66import progressbar
77import requests
88from requests_toolbelt .multipart import encoder
9- from paperspace import logger as default_logger
109
10+ from paperspace import logger as default_logger
1111from 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' ]
0 commit comments