def test_whitelisted_lines(self, mock_open, _): configs = [ ('foo.c', '*.c'), ('.c', '*.c'), ('foo/foo.c', '*.c'), ('foo/foo.c', 'foo.c'), ('foo.c', '/*.c'), ('foo.c', '/foo.c'), ('foo.c', 'foo.c'), ('foo.c', 'foo.[ch]'), ('foo/bar/bla.c', 'foo/**'), ('foo/bar/bla/blie.c', 'foo/**/blie.c'), ('foo/bar/bla.c', '**/bla.c'), ('bla.c', '**/bla.c'), ('foo/bar', 'foo/**/bar'), ('foo/bla/bar', 'foo/**/bar'), ('foo/bar/', 'bar/'), ('foo/bar/', 'bar'), ('foo/bar/something', 'foo/bar/*'), ] for (path, pattern) in configs: mock_open.return_value.__iter__.return_value = [pattern] patterns = IgnoreManager.get_config() self.assertEqual( (self.get_ignored(patterns), self.get_whitelisted(patterns)), ([pattern], [])) assert len(list(IgnoreManager.find_matching(path, patterns))) == 1
def init(project, run, model): """Initialize a new polyaxonfile specification.""" user, project_name = get_project_or_local(project) try: project_config = PolyaxonClients().project.get_project(user, project_name) except (PolyaxonHTTPError, PolyaxonShouldExitError) as e: Printer.print_error('Make sure you have a project with this name `{}`'.format(project)) Printer.print_error('You can a new project with this command: ' 'polyaxon project create --name={} --description=...'.format(project)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) if not any([model, run]) and not all([model, run]): Printer.print_error("You must specify which an init option, " "possible values: `--model` or `--run`.") sys.exit(1) result = False if model: result = create_init_file(constants.INIT_FILE_MODEL) elif run: result = create_init_file(constants.INIT_FILE_RUN) if result: ProjectManager.set_config(project_config, init=True) IgnoreManager.init_config() Printer.print_success( "Project `{}` was initialized and Polyaxonfile was created successfully `{}`".format( project, constants.INIT_FILE)) sys.exit(1) # if we are here the file was not created if not os.path.isfile(constants.INIT_FILE): Printer.print_error( "Something went wrong, init command did not create a file.\n" "Possible reasons: you don't have the write to create the file.") sys.exit(1) # file was already there, let's check if the project passed correspond to this file try: PolyaxonFile(constants.INIT_FILE).specification except (PolyaxonfileError, ValidationError) as e: Printer.print_error( "Something went wrong, init command did not create a file.\n" "Another file already exist with.") Printer.print_error('Error message: `{}`.'.format(e)) sys.exit(1) # At this point we check if we need to re init configurations ProjectManager.set_config(project_config, init=True) IgnoreManager.init_config() Printer.print_success( "Project `{}` was initialized and Polyaxonfile was created successfully `{}`".format( project, constants.INIT_FILE))
def init(project, polyaxonfile): """Initialize a new polyaxonfile specification.""" user, project_name = get_project_or_local(project) try: project_config = PolyaxonClient().project.get_project( user, project_name) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Make sure you have a project with this name `{}`'.format(project)) Printer.print_error( 'You can a create new project with this command: ' 'polyaxon project create ' '--name={} [--description=...] [--tags=...]'.format(project_name)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) init_project = False if ProjectManager.is_initialized(): local_project = ProjectManager.get_config() click.echo( 'Warning! This project is already initialized with the following project:' ) with clint.textui.indent(4): clint.textui.puts('User: {}'.format(local_project.user)) clint.textui.puts('Project: {}'.format(local_project.name)) if click.confirm('Would you like to override this current config?', default=False): init_project = True else: init_project = True if init_project: ProjectManager.purge() ProjectManager.set_config(project_config, init=True) Printer.print_success('Project was initialized') else: Printer.print_header('Project config was not changed.') init_ignore = False if IgnoreManager.is_initialized(): click.echo('Warning! Found a .polyaxonignore file.') if click.confirm('Would you like to override it?', default=False): init_ignore = True else: init_ignore = True if init_ignore: IgnoreManager.init_config() Printer.print_success('New .polyaxonignore file was created.') else: Printer.print_header('.polyaxonignore file was not changed.') if polyaxonfile: create_polyaxonfile()
def test_ignored_lines(self, mock_open, _): configs = [('foo.c', 'foo.[dh]'), ('foo/foo.c', '/foo.c'), ('foo/foo.c', '/*.c'), ('foo/bar/', '/bar/'), ('foo/bar/', 'foo/bar/*'), ('foo/bar', 'foo?bar')] for (path, pattern) in configs: mock_open.return_value.__iter__.return_value = [pattern] patterns = IgnoreManager.get_config() self.assertEqual( (self.get_ignored(patterns), self.get_whitelisted(patterns)), ([pattern], [])) assert list(IgnoreManager.find_matching(path, patterns)) == []
def upload(): # pylint:disable=assign-to-new-keyword """Upload code of the current directory while respecting the .polyaxonignore file.""" project = ProjectManager.get_config_or_raise() files = IgnoreManager.get_unignored_file_paths() with create_tarfile(files, project.name) as file_path: with get_files_in_current_directory('repo', [file_path]) as (files, files_size): try: PolyaxonClient().project.upload_repo(project.user, project.name, files, files_size) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Could not upload code for project `{}`.'.format( project.name)) Printer.print_error('Error message `{}`.'.format(e)) Printer.print_error( 'Check if you have access rights for this project and ' 'that you are not uploading large files.' 'If you are running a notebook, ' 'you should stop it before uploading.') sys.exit(1) Printer.print_success('Files uploaded.')
def test_escaping_of_globs_that_start_with_reserved_chars( self, mock_open, _): file_data = ['', '# comment', '\#file1', '\!file2'] mock_open.return_value.__iter__.return_value = file_data result = IgnoreManager.get_config() self.assertEqual(result, (['#file1', '!file2'], []))
def upload(sync=True): # pylint:disable=assign-to-new-keyword """Upload code of the current directory while respecting the .polyaxonignore file.""" project = ProjectManager.get_config_or_raise() files = IgnoreManager.get_unignored_file_paths() try: with create_tarfile(files, project.name) as file_path: with get_files_in_current_directory('repo', [file_path]) as (files, files_size): try: PolyaxonClient().project.upload_repo(project.user, project.name, files, files_size, sync=sync) except (PolyaxonHTTPError, PolyaxonShouldExitError, PolyaxonClientException) as e: Printer.print_error( 'Could not upload code for project `{}`.'.format(project.name)) Printer.print_error('Error message `{}`.'.format(e)) Printer.print_error( 'Check the project exists, ' 'and that you have access rights, ' 'this could happen as well when uploading large files. ' 'Please also make sure that you have enough space to upload the data.') sys.exit(1) Printer.print_success('Files uploaded.') except Exception as e: Printer.print_error("Could not upload the file.") Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1)
def test_properly_interprets_whitelisted_globs(self, mock_open, _): file_data = ['', '# comment', '*.py', '!file1.py'] mock_open.return_value.__iter__.return_value = file_data patterns = IgnoreManager.get_config() self.assertEqual( (self.get_ignored(patterns), self.get_whitelisted(patterns)), (['*.py'], ['file1.py']))
def test_trims_slash_prefix_from_abs_paths(self, mock_open, _): file_data = ['/test', '!/ignore'] mock_open.return_value.__iter__.return_value = file_data patterns = IgnoreManager.get_config() self.assertEqual( (self.get_ignored(patterns), self.get_whitelisted(patterns)), (['/test'], ['/ignore']))
def test_ignores_commented_lines(self, mock_open, _): file_data = ['', '# comment', '', '*.py'] mock_open.return_value.__iter__.return_value = file_data patterns = IgnoreManager.get_config() self.assertEqual( (self.get_ignored(patterns), self.get_whitelisted(patterns)), (['*.py'], []))
def upload(): """Upload code of the current directory while respecting the .polyaxonignore file.""" project = get_current_project_or_exit() files = IgnoreManager.get_unignored_file_paths() filepath = create_tarfile(files, project.name) files, files_size = get_files_in_current_directory('repo', [filepath]) try: PolyaxonClients().project.upload_repo(project.user, project.name, files, files_size) except (PolyaxonHTTPError, PolyaxonShouldExitError) as e: Printer.print_error('Could not upload code for project `{}`.'.format(project)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success('Files upload.')
def upload(async): # pylint:disable=assign-to-new-keyword """Upload code of the current directory while respecting the .polyaxonignore file.""" project = ProjectManager.get_config_or_raise() files = IgnoreManager.get_unignored_file_paths() with create_tarfile(files, project.name) as file_path: with get_files_in_current_directory('repo', [file_path]) as (files, files_size): try: PolyaxonClients().project.upload_repo(project.user, project.name, files, files_size, async) except (PolyaxonHTTPError, PolyaxonShouldExitError) as e: Printer.print_error( 'Could not upload code for project `{}`.'.format( project.name)) Printer.print_error('Error message `{}`.'.format(e)) sys.exit(1) Printer.print_success('Files uploaded.')
def test_returns_two_empty_lists_if_file_is_not_present(self, _): patterns = IgnoreManager.get_config() self.assertEqual(patterns, [])
def test_returns_two_empty_lists_if_file_is_not_present(self, _): result = IgnoreManager.get_config() self.assertEqual(result, ([], []))
def test_trims_slash_prefix_from_abs_paths(self, mock_open, _): file_data = ['/test', '!/ignore'] mock_open.return_value.__iter__.return_value = file_data result = IgnoreManager.get_config() self.assertEqual(result, (['test'], ['ignore']))
def test_ignores_commented_lines(self, mock_open, _): file_data = ['', '# comment', '', '*.py'] mock_open.return_value.__iter__.return_value = file_data result = IgnoreManager.get_config() self.assertEqual(result, (['*.py'], []))