Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 7cb596b

Browse files
kossakdandruszak
authored andcommitted
support for --ignoreFiles and --workspace none brought back
1 parent 3958495 commit 7cb596b

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

paperspace/cli/experiments.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def common_experiments_create_options(f):
5858
"workspaceUrl",
5959
help="Project git repository url",
6060
),
61+
click.option(
62+
"--ignoreFiles",
63+
"ignore_files",
64+
help="Ignore certain files from uploading"
65+
),
6166
click.option(
6267
"--workingDirectory",
6368
"workingDirectory",

paperspace/cli/jobs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def list_jobs(api_key, **filters):
7575
@click.option("--workspace", "workspace", required=False, help="Path to workspace directory")
7676
@click.option("--workspaceArchive", "workspaceArchive", required=False, help="Path to workspace archive")
7777
@click.option("--workspaceUrl", "workspaceUrl", required=False, help="Project git repository url")
78-
@click.option("--workingDirectory", "workingDirectory", help="Working directory for the experiment", )
78+
@click.option("--workingDirectory", "workingDirectory", help="Working directory for the experiment")
79+
@click.option("--ignoreFiles", "ignore_files", help="Ignore certain files from uploading")
7980
@click.option("--experimentId", "experimentId", help="Experiment Id")
8081
@click.option("--jobEnv", "envVars", type=json_string, help="Environmental variables ")
8182
@click.option("--useDockerfile", "useDockerfile", help="Flag: using Dockerfile")

paperspace/workspace.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import progressbar
77
import requests
88
from requests_toolbelt.multipart import encoder
9-
from paperspace import logger as default_logger
109

10+
from paperspace import logger as default_logger
1111
from paperspace.exceptions import S3UploadFailedError, PresignedUrlUnreachableError, \
1212
PresignedUrlAccessDeniedError, PresignedUrlConnectionError, ProjectAccessDeniedError, \
1313
PresignedUrlMalformedResponseError, PresignedUrlError
@@ -24,10 +24,11 @@ def __init__(self, experiments_api, logger=None):
2424
self.logger = logger or default_logger
2525

2626
@staticmethod
27-
def _retrieve_file_paths(dir_name):
27+
def _retrieve_file_paths(dir_name, ignored_files=''):
2828
# setup file paths variable
2929
file_paths = {}
30-
exclude = ['.git', '.idea', '.pytest_cache']
30+
ignored_files = ignored_files.split(',')
31+
exclude = ['.git', '.idea', '.pytest_cache'] + ignored_files
3132
# Read all directory, subdirectories and file lists
3233
for root, dirs, files in os.walk(dir_name, topdown=True):
3334
dirs[:] = [d for d in dirs if d not in exclude]
@@ -38,11 +39,12 @@ def _retrieve_file_paths(dir_name):
3839
file_path = filename
3940
else:
4041
file_path = os.path.join(os.path.relpath(root, dir_name), filename)
41-
file_paths[file_path] = os.path.join(root, filename)
42+
if file_path not in ignored_files:
43+
file_paths[file_path] = os.path.join(root, filename)
4244

4345
return file_paths
4446

45-
def _zip_workspace(self, workspace_path):
47+
def _zip_workspace(self, workspace_path, ignore_files):
4648
if not workspace_path:
4749
workspace_path = '.'
4850
zip_file_name = os.path.basename(os.getcwd()) + '.zip'
@@ -54,8 +56,7 @@ def _zip_workspace(self, workspace_path):
5456
if os.path.exists(zip_file_path):
5557
self.logger.log('Removing existing archive')
5658
os.remove(zip_file_path)
57-
58-
file_paths = self._retrieve_file_paths(workspace_path)
59+
file_paths = self._retrieve_file_paths(workspace_path, ignore_files)
5960

6061
self.logger.log('Creating zip archive: %s' % zip_file_name)
6162
zip_file = zipfile.ZipFile(zip_file_path, 'w')
@@ -86,6 +87,8 @@ def upload_workspace(self, input_data):
8687
workspace_url = input_data.get('workspaceUrl')
8788
workspace_path = input_data.get('workspace')
8889
workspace_archive = input_data.get('workspaceArchive')
90+
ignore_files = input_data.get('ignore_files')
91+
8992
if (workspace_archive and workspace_path) or (workspace_archive and workspace_url) or (
9093
workspace_path and workspace_url):
9194
raise click.UsageError("Use either:\n\t--workspaceUrl to point repository URL"
@@ -96,10 +99,13 @@ def upload_workspace(self, input_data):
9699
if workspace_url:
97100
return # nothing to do
98101

102+
# That's nasty amf. Should be removed as soon it won't be necessary by PS_API (meaning ASAP)
103+
if workspace_path == 'none':
104+
return 'none'
99105
if workspace_archive:
100106
archive_path = os.path.abspath(workspace_archive)
101107
else:
102-
archive_path = self._zip_workspace(workspace_path)
108+
archive_path = self._zip_workspace(workspace_path, ignore_files)
103109

104110
file_name = os.path.basename(archive_path)
105111
project_handle = input_data['projectHandle']

tests/unit/test_workspace.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
MOCK_BUCKET_NAME = 'bucket_name'
1111
MOCK_OBJECT_KEY = 'object_key'
1212
mock_upload_data = {
13-
"bucket_name": MOCK_BUCKET_NAME,
14-
"fields": {
15-
"key": MOCK_OBJECT_KEY
16-
}
13+
"bucket_name": MOCK_BUCKET_NAME,
14+
"fields": {
15+
"key": MOCK_OBJECT_KEY
1716
}
18-
17+
}
1918

2019
mock_upload_response = {
2120
"message": "success",

0 commit comments

Comments
 (0)