Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Skip if unsupported environment
if not in_script() and not in_notebook() and not is_cli:
log('Failed to detect Jupyter notebook or Python script. Skipping..', error=True)
return
# Attempt to save Jupyter notebook
if in_notebook():
save_notebook()
log('Attempting to save notebook..')
sleep(1)
# Extract notebook/script filename
filename = _parse_filename(filename)
if filename is None:
log(FILENAME_MSG, error=True)
return
# Commit from Kaggle (After many bug reports of empty notebook)
if filename == '__notebook_source__.ipynb':
log("Detected Kaggle notebook...")
if not project:
log("Please provide the project argument e.g. jovian.commit(project='my-project')", error=True)
return
perform_kaggle_commit(message,
files,
outputs,
environment,
privacy,
project,
new_project)
# Deprecated argument (artifacts)
if 'artifacts' in kwargs:
outputs = kwargs['artifacts']
log('"artifacts" is deprecated. Use "outputs" instead', error=True)
is_cli = kwargs.get('is_cli', False)
# Skip if unsupported environment
if not in_script() and not in_notebook() and not is_cli:
log('Failed to detect Jupyter notebook or Python script. Skipping..', error=True)
return
# Attempt to save Jupyter notebook
if in_notebook():
save_notebook()
log('Attempting to save notebook..')
sleep(1)
# Extract notebook/script filename
filename = _parse_filename(filename)
if filename is None:
log(FILENAME_MSG, error=True)
return
# Commit from Kaggle (After many bug reports of empty notebook)
if filename == '__notebook_source__.ipynb':
log("Detected Kaggle notebook...")
if not project:
log("Please provide the project argument e.g. jovian.commit(project='my-project')", error=True)
return
perform_kaggle_commit(message,
if num_files >= 50:
log("Can't upload more than 50 files at once")
return
if num_files == 1:
log('Uploading 1 notebook: {}'.format(files[0]))
else:
log('Uploading {} notebooks:'.format(num_files))
log('\n'.join(files), pre=False)
if click.confirm('\n[jovian] Do you want to continue?', default=True):
for filename in files:
reset_notebook_slug()
commit(filename=filename, **kwargs)
log("", pre=False)
sleep(1)
'"public", "private", "secret", "auto")', error=True)
# Deprecated argument (nb_filename)
if filename is None and 'nb_filename' in kwargs:
filename = kwargs['nb_filename']
log('"nb_filename" is deprecated. Use "filename" instead', error=True)
# Deprecated argument (env_type)
if 'env_type' in kwargs:
environment = kwargs['env_type']
log('"env_type" is deprecated. Use "environment" instead', error=True)
# Deprecated argument (capture_env)
if 'capture_env' in kwargs and not kwargs['capture_env']:
environment = None
log('"catpure_env" is deprecated. Use "environment=None" instead', error=True)
# Deprecated argument (notebook_id)
if 'notebook_id' in kwargs:
project = kwargs['notebook_id']
log('"notebook_id" is deprecated. Use "project" instead.', error=True)
# Deprecated argument (create_new)
if 'create_new' in kwargs:
new_project = kwargs['create_new']
log('"create_new" is deprecated. Use "new_project" instead.', error=True)
# Deprecated argument (artifacts)
if 'artifacts' in kwargs:
outputs = kwargs['artifacts']
log('"artifacts" is deprecated. Use "outputs" instead', error=True)
f
for f in glob.glob('**/*', recursive=True)
if get_file_extension(f) in whitelist
]
if exclude_files:
if not isinstance(exclude_files, list):
exclude_files = [exclude_files]
for filename in exclude_files:
try:
paths.remove(filename)
except ValueError:
pass
log('Uploading additional ' + ('outputs' if output else 'files') + '...')
# Convert single path to list
if type(paths) == str:
paths = [paths]
for path in paths:
if os.path.isdir(path):
files = [
f
for f in glob.glob(os.path.join(path, '**/*'), recursive=True)
if get_file_extension(f) in whitelist
]
for file in files:
_attach_file(file, gist_slug, version, output)
elif os.path.exists(path):
_attach_file(path, gist_slug, version, output)
data = "Hello from the Integration!"
jovian.notify(data)
.. important::
This feature requires for your Jovian account to be connected to a Slack workspace, visit `Jovian Integrations`_ to integrate them and to control the type of notifications.
.. _Slack: https://slack.com
.. _Jovian: https://jovian.ml?utm_source=docs
.. _Jovian Integrations: https://jovian.ml/settings/integrations?utm_source=docs
"""
res = post_slack_message(data=data, safe=safe)
if verbose:
if not res.get('errors'):
log('message_sent:' + str(res.get('data').get('messageSent')))
else:
log(str(res.get('errors')[0].get('message')), error=True)
import jovian
data = "Hello from the Integration!"
jovian.notify(data)
.. important::
This feature requires for your Jovian account to be connected to a Slack workspace, visit `Jovian Integrations`_ to integrate them and to control the type of notifications.
.. _Slack: https://slack.com
.. _Jovian: https://jovian.ml?utm_source=docs
.. _Jovian Integrations: https://jovian.ml/settings/integrations?utm_source=docs
"""
res = post_slack_message(data=data, safe=safe)
if verbose:
if not res.get('errors'):
log('message_sent:' + str(res.get('data').get('messageSent')))
else:
log(str(res.get('errors')[0].get('message')), error=True)
"""Install packages for a cloned gist"""
# Check for conda and get the binary path
conda_bin = get_conda_bin()
# Identify the right environment file, and exit if absent
env_fname = identify_env_file(env_fname=env_fname)
if env_fname is None:
log('Failed to detect a conda environment YML file. Skipping..', error=True)
return
else:
log('Detected conda environment file: ' + env_fname + "\n")
# Get the environment name from user input
env_name = request_env_name(env_name=env_name, env_fname=env_fname)
if env_name is None:
log('Environment name not provided/detected. Skipping..')
return
# Construct the command
command = conda_bin + ' env update --file "' + \
env_fname + '" --name "' + env_name + '"'
packages = extract_env_packages(env_fname=env_fname)
if len(packages) > 0:
success = run_command(command=command, env_fname=env_fname, packages=packages, run=1)
if not success:
log('Some pip packages failed to install.')
print_conda_message(env_name=env_name)
except:
log(CONDA_NOT_FOUND, error=True)
return False
# Identify the right environment file, and exit if absent
env_fname = identify_env_file(env_fname=env_fname)
if env_fname is None:
log('Failed to detect a conda environment YML file. Skipping..', error=True)
return False
else:
log('Detected conda environment file: ' + env_fname + "\n")
# Get the environment name from user input
env_name = extract_env_name(env_fname=env_fname)
if env_name is None:
log('Environment name not provided/detected. Skipping..')
return False
# Activate the environment
command = conda_bin + " activate " + env_name
log('Copy and execute the following command (try "source activate" if "conda activate doesn\'t work" )')
print(" " + command + " \n")
def post_clone_msg(title):
log("Cloned successfully to '{}'".format(title), color='green')
log(click.style('\nNext steps:', fg='yellow', underline=True) +
click.style("""
$ cd {}
$ jovian install
$ conda activate
$ jupyter notebook
""".format(title), bold=True), pre=False)
log("""
Replace with the name of your environment (without the '<' & '>')
Jovian uses Anaconda ( https://conda.io/ ) under the hood,
so please make sure you have it installed and added to path.
* If you face issues with `jovian install`, try `conda env update`.
* If you face issues with `conda activate`, try `source activate `
or `activate ` to activate the virtual environment.
""", pre=False)