コード例 #1
0
 def test_whitelisted_lines(self, mock_file, _):
     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_file.return_value.__enter__.return_value = [pattern]
         patterns = IgnoreConfigManager.get_config()
         self.assertEqual(
             (self.get_ignored(patterns), self.get_whitelisted(patterns)),
             ([pattern], []),
         )
         assert len(list(IgnoreConfigManager.find_matching(path,
                                                           patterns))) == 1
コード例 #2
0
 def test_returns_two_empty_lists_if_file_is_not_present(self, _):
     patterns = IgnoreConfigManager.get_config()
     self.assertEqual(
         patterns,
         IgnoreConfigManager.get_patterns(
             io.StringIO(cli_constants.DEFAULT_IGNORE_LIST)),
     )
コード例 #3
0
def purge(cache_only):
    """Purge the global config values."""
    if not cache_only:
        ClientConfigManager.purge()
        CliConfigManager.purge()
        AuthConfigManager.purge()
    ProjectConfigManager.purge()
    RunConfigManager.purge()
    IgnoreConfigManager.purge()
    GitConfigManager.purge()
    Printer.print_success("Configs was removed.")
コード例 #4
0
ファイル: operations.py プロジェクト: opentechfn/polyaxon
def upload(ctx, project, uid, path_from, path_to, is_file, sync_failure):
    """Upload runs' artifacts.

    Uses /docs/core/cli/#caching

    Examples:

    \b
    $ polyaxon ops upload -uid=8aac02e3a62a4f0aaa257c59da5eab80

    \b
    $ polyaxon ops upload -uid=8aac02e3a62a4f0aaa257c59da5eab80 path_from="path/to/upload"

    \b
    $ polyaxon ops upload -uid=8aac02e3a62a4f0aaa257c59da5eab80 path_to="path/to/upload/to"
    """
    owner, project_name, run_uuid = get_project_run_or_local(
        project or ctx.obj.get("project"),
        uid or ctx.obj.get("run_uuid"),
        is_cli=True,
    )
    try:
        client = RunClient(owner=owner,
                           project=project_name,
                           run_uuid=run_uuid)
        if is_file:
            response = client.upload_artifact(filepath=path_from,
                                              path=path_to or "",
                                              overwrite=True)
        else:
            files = IgnoreConfigManager.get_unignored_filepaths(path_from)
            response = client.upload_artifacts(files=files,
                                               path=path_to or "",
                                               overwrite=True,
                                               relative_to=path_from)
    except (
            ApiException,
            HTTPError,
            PolyaxonHTTPError,
            PolyaxonShouldExitError,
            PolyaxonClientException,
    ) as e:
        handle_cli_error(
            e,
            message="Could not upload artifacts for run `{}`.".format(
                run_uuid))
        sys.exit(1)

    if response.status_code == 200:
        Printer.print_success("Artifacts uploaded.")
    else:
        if sync_failure:
            client.log_failed(message="Operation failed uploading artifacts.")
        Printer.print_error(
            "Error uploading artifacts. "
            "Status: {}. Error: {}.".format(response.status_code,
                                            response.content),
            sys_exit=True,
        )
コード例 #5
0
    def test_ignores_commented_lines(self, mock_file, _):
        file_data = ["", "# comment", "", "*.py"]
        mock_file.return_value.__enter__.return_value = file_data

        patterns = IgnoreConfigManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (["*.py"], []))
コード例 #6
0
    def test_properly_interprets_whitelisted_globs(self, mock_file, _):
        file_data = ["", "# comment", "*.py", "!file1.py"]
        mock_file.return_value.__enter__.return_value = file_data

        patterns = IgnoreConfigManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (["*.py"], ["file1.py"]),
        )
コード例 #7
0
    def test_trims_slash_prefix_from_abs_paths(self, mock_file, _):
        file_data = ["/test", "!/ignore"]
        mock_file.return_value.__enter__.return_value = file_data

        patterns = IgnoreConfigManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (["/test"], ["/ignore"]),
        )
コード例 #8
0
    def test_escaping_of_globs_that_start_with_reserved_chars(self, mock_file, _):
        file_data = ["", r"# comment", r"\#file1", r"\!file2"]  # noqa
        mock_file.return_value.__enter__.return_value = file_data

        patterns = IgnoreConfigManager.get_config()
        self.assertEqual(
            (self.get_ignored(patterns), self.get_whitelisted(patterns)),
            (["#file1", "!file2"], []),
        )
コード例 #9
0
 def test_ignored_lines(self, mock_file, _):
     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_file.return_value.__enter__.return_value = [pattern]
         patterns = IgnoreConfigManager.get_config()
         self.assertEqual(
             (self.get_ignored(patterns), self.get_allowed(patterns)),
             ([pattern], []),
         )
         assert list(IgnoreConfigManager.find_matching(path,
                                                       patterns)) == []
コード例 #10
0
def upload():
    """N.B. This is not available in all distributions.

    Upload code of the current directory while respecting the .polyaxonignore file.
    """
    import sys

    from polyaxon.cli.errors import handle_cli_error
    from polyaxon.client import PolyaxonClient
    from polyaxon.exceptions import (
        PolyaxonClientException,
        PolyaxonHTTPError,
        PolyaxonShouldExitError,
    )
    from polyaxon.managers.ignore import IgnoreConfigManager
    from polyaxon.managers.project import ProjectConfigManager
    from polyaxon.utils.formatting import Printer
    from polyaxon.utils.path_utils import create_project_tarfile, get_files_by_paths

    project = ProjectConfigManager.get_config_or_raise()
    files = IgnoreConfigManager.get_unignored_filepaths()
    try:
        with create_project_tarfile(files, project.name) as filepath:
            with get_files_by_paths("repo", [filepath]) as (files, files_size):
                try:
                    PolyaxonClient().project.upload_repo(
                        project.user, project.name, files, files_size)
                except (
                        PolyaxonHTTPError,
                        PolyaxonShouldExitError,
                        PolyaxonClientException,
                ) as e:
                    handle_cli_error(
                        e,
                        message="Could not upload code for project `{}`.".
                        format(project.name),
                    )
                    Printer.print_error(
                        "Check that 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:
        handle_cli_error(e, message="Could not upload the file.")
        sys.exit(1)
コード例 #11
0
ファイル: init.py プロジェクト: rimon-safesitehq/polyaxon
def init(project, git_connection, git_url, polyaxonfile, polyaxonignore):
    """Initialize a new local project and cache directory.

    Note: Make sure to add the local cache `.polyaxon`
    to your `.gitignore` and `.dockerignore` files.
    """
    if not any(
        [project, git_connection, git_url, polyaxonfile, polyaxonignore]):
        Printer.print_warning(
            "`polyaxon init` did not receive any valid option.",
            command_help="polyaxon init",
        )
    if project:
        owner, project_name = get_project_or_local(project, is_cli=True)
        try:
            polyaxon_client = ProjectClient(owner=owner, project=project_name)
            polyaxon_client.refresh_data()
        except (ApiException, HTTPError) as e:
            Printer.print_error(
                "Make sure you have a project with this name `{}`".format(
                    project))
            handle_cli_error(
                e,
                message="You can a create new project with this command: "
                "polyaxon project create "
                "--name={} [--description=...] [--tags=...]".format(
                    project_name),
            )
            sys.exit(1)
        init_project = False
        if ProjectConfigManager.is_initialized():
            local_project = get_local_project()
            click.echo(
                "Warning! This project is already initialized with the following project:"
            )
            with indentation.indent(4):
                indentation.puts("Owner: {}".format(local_project.owner))
                indentation.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:
            ProjectConfigManager.purge(
                visibility=ProjectConfigManager.VISIBILITY_LOCAL)
            config = polyaxon_client.client.sanitize_for_serialization(
                polyaxon_client.project_data)
            ProjectConfigManager.set_config(
                config,
                init=True,
                visibility=ProjectConfigManager.VISIBILITY_LOCAL)
            Printer.print_success("Project was initialized")
            Printer.print_header(
                "Make sure to add the local cache `.polyaxon` "
                "to your `.gitignore` and `.dockerignore` files.")
        else:
            Printer.print_header("Project config was not changed.")

    if git_connection or git_url:
        init_git = False
        if GitConfigManager.is_initialized():
            click.echo("Warning! A {} file was found.".format(
                GitConfigManager.CONFIG_FILE_NAME))
            if click.confirm("Would you like to override it?", default=False):
                init_git = True
        else:
            init_git = True

        if init_git:
            GitConfigManager.purge(
                visibility=GitConfigManager.VISIBILITY_LOCAL)
            config = GitConfigManager.CONFIG(
                connection=git_connection,
                git=V1GitType(url=git_url) if git_url else None,
            )
            GitConfigManager.set_config(config=config, init=True)
            Printer.print_success("New {} file was created.".format(
                GitConfigManager.CONFIG_FILE_NAME))
        else:
            Printer.print_header("{} file was not changed.".format(
                GitConfigManager.CONFIG_FILE_NAME))

    if polyaxonfile:
        create_polyaxonfile()

    if polyaxonignore:
        init_ignore = False
        if IgnoreConfigManager.is_initialized():
            click.echo("Warning! A {} file was found.".format(
                IgnoreConfigManager.CONFIG_FILE_NAME))
            if click.confirm("Would you like to override it?", default=False):
                init_ignore = True
        else:
            init_ignore = True

        if init_ignore:
            IgnoreConfigManager.init_config()
            Printer.print_success("New {} file was created.".format(
                IgnoreConfigManager.CONFIG_FILE_NAME))
        else:
            Printer.print_header("{} file was not changed.".format(
                IgnoreConfigManager.CONFIG_FILE_NAME))
コード例 #12
0
 def test_default_props(self):
     assert IgnoreConfigManager.is_global() is False
     assert IgnoreConfigManager.is_local() is True
     assert IgnoreConfigManager.IS_POLYAXON_DIR is False
     assert IgnoreConfigManager.CONFIG_FILE_NAME == ".polyaxonignore"
     assert IgnoreConfigManager.CONFIG is None
コード例 #13
0
 def test_returns_two_empty_lists_if_file_is_not_present(self, _):
     patterns = IgnoreConfigManager.get_config()
     self.assertEqual(patterns, [])