Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _attach_file(path, gist_slug, version, output=False):
"""Helper function to attach a single file to a commit"""
try:
with open(path, 'rb') as f:
file_obj = os.path.basename(path), f
folder = os.path.dirname(path)
api.upload_file(gist_slug, file_obj, folder, version, output)
except Exception as e:
log(str(e) + " (" + path + ")", error=True)
def upload_pip_env(gist_slug, version=None):
"""Read and upload the current virtual environment to server"""
return upload_file(gist_slug=gist_slug, file=('requirements.txt', read_pip_env()), version=version)
def upload_conda_env(gist_slug, version=None):
"""Read and save the current Anaconda environment to server"""
# Export environment to YML string
env_str = read_conda_env(get_conda_env_name())
# Upload environment.yml
upload_file(gist_slug=gist_slug, file=('environment.yml', env_str), version=version)
# Check and include existing os-specific files
platform = get_platform()
for p in PLATFORMS:
pfname = 'environment-' + p + '.yml'
if p == platform:
# Use the new environment for current platform
upload_file(gist_slug=gist_slug, file=(pfname, env_str), version=version)
elif os.path.exists(pfname):
# Reuse old environments for other platforms
with open(pfname, 'rb') as f:
file = (pfname, f)
upload_file(gist_slug=gist_slug, file=file, version=version)
def try_upload_file(gist_slug, version, current_file, artifact=False):
"""Safely upload a file"""
try:
with open(current_file, 'rb') as f:
folder = os.path.dirname(current_file)
file = (os.path.basename(current_file), f)
upload_file(gist_slug=gist_slug, file=file, folder=folder, version=version, artifact=artifact)
except Exception as e:
log(str(e), error=True)
def upload_pip_env(gist_slug, version=None):
"""Read and upload the current virtual environment to server"""
return upload_file(gist_slug, ('requirements.txt', read_pip_env(), version))