Ejemplo n.º 1
0
    def publish(self, repository_name, username, password):
        if repository_name:
            self._io.writeln(
                'Publishing <info>{}</info> (<comment>{}</comment>) '
                'to <fg=cyan>{}</>'.format(self._package.pretty_name,
                                           self._package.pretty_version,
                                           repository_name))
        else:
            self._io.writeln(
                'Publishing <info>{}</info> (<comment>{}</comment>) '
                'to <fg=cyan>PyPI</>'.format(self._package.pretty_name,
                                             self._package.pretty_version))

        if not repository_name:
            url = 'https://upload.pypi.org/legacy/'
            repository_name = 'pypi'
        else:
            # Retrieving config information
            config_file = Path(CONFIG_DIR) / 'config.toml'

            if not config_file.exists():
                raise RuntimeError('Config file does not exist. '
                                   'Unable to get repository information')

            with config_file.open() as f:
                config = toml.loads(f.read())

            if ('repositories' not in config
                    or repository_name not in config['repositories']):
                raise RuntimeError(
                    'Repository {} is not defined'.format(repository_name))

            url = config['repositories'][repository_name]['url']

        if not (username and password):
            auth_file = Path(CONFIG_DIR) / 'auth.toml'
            if auth_file.exists():
                with auth_file.open() as f:
                    auth_config = toml.loads(f.read())

                if 'http-basic' in auth_config and repository_name in auth_config[
                        'http-basic']:
                    config = auth_config['http-basic'][repository_name]

                    username = config.get('username')
                    password = config.get('password')

        # Requesting missing credentials
        if not username:
            username = self._io.ask('Username:'******'Password:')

        # TODO: handle certificates

        self._uploader.auth(username, password)

        return self._uploader.upload(url)
Ejemplo n.º 2
0
    def get_supported_tags(self):  # type: () -> List[Tag]
        file_path = Path(packaging.tags.__file__)
        if file_path.suffix == ".pyc":
            # Python 2
            file_path = file_path.with_suffix(".py")

        with file_path.open(encoding="utf-8") as f:
            script = decode(f.read())

        script = script.replace(
            "from ._typing import TYPE_CHECKING, cast",
            "TYPE_CHECKING = False\ncast = lambda type_, value: value",
        )
        script = script.replace(
            "from ._typing import MYPY_CHECK_RUNNING, cast",
            "MYPY_CHECK_RUNNING = False\ncast = lambda type_, value: value",
        )

        script += textwrap.dedent(
            """
            import json

            print(json.dumps([(t.interpreter, t.abi, t.platform) for t in sys_tags()]))
            """
        )

        output = self.run("python", "-", input_=script)

        return [Tag(*t) for t in json.loads(output)]
Ejemplo n.º 3
0
    def callback(request, uri, headers):
        fixture = Path(__file__).parent.parent.joinpath(
            "fixtures/distributions/demo-0.1.0-py2.py3-none-any.whl"
        )

        with fixture.open("rb") as f:
            return [200, headers, f.read()]
Ejemplo n.º 4
0
def load_toml_versions(toml_file: Path) -> Tuple[_TOMLDocument, _TOMLDocument]:
    """Load a pair of TOML documents from a TOML file with merge conflicts.

    Args:
        toml_file: Path to the lock file.

    Returns:
        A pair of TOML documents, corresponding to *our* version and *their*
        version.
    """
    def load(lines: Sequence[str]) -> _TOMLDocument:  # noqa
        return tomlkit.loads("".join(lines))

    with toml_file.open() as fp:
        ours, theirs = parser.parse(fp)
        return load(ours), load(theirs)
Ejemplo n.º 5
0
def fixture(name):
    file = Path(__file__).parent / "fixtures" / "{}.test".format(name)

    with file.open() as f:
        return toml.loads(f.read())
Ejemplo n.º 6
0
    def publish(self, repository_name, username, password):
        if repository_name:
            self._io.writeln(
                "Publishing <info>{}</info> (<comment>{}</comment>) "
                "to <fg=cyan>{}</>".format(
                    self._package.pretty_name,
                    self._package.pretty_version,
                    repository_name,
                ))
        else:
            self._io.writeln(
                "Publishing <info>{}</info> (<comment>{}</comment>) "
                "to <fg=cyan>PyPI</>".format(self._package.pretty_name,
                                             self._package.pretty_version))

        if not repository_name:
            url = "https://upload.pypi.org/legacy/"
            repository_name = "pypi"
        else:
            # Retrieving config information
            config_file = Path(CONFIG_DIR) / "config.toml"

            if not config_file.exists():
                raise RuntimeError("Config file does not exist. "
                                   "Unable to get repository information")

            with config_file.open() as f:
                config = toml.loads(f.read())

            if ("repositories" not in config
                    or repository_name not in config["repositories"]):
                raise RuntimeError(
                    "Repository {} is not defined".format(repository_name))

            url = config["repositories"][repository_name]["url"]

        if not (username and password):
            auth_file = Path(CONFIG_DIR) / "auth.toml"
            if auth_file.exists():
                with auth_file.open() as f:
                    auth_config = toml.loads(f.read())

                if ("http-basic" in auth_config
                        and repository_name in auth_config["http-basic"]):
                    config = auth_config["http-basic"][repository_name]

                    username = config.get("username")
                    password = config.get("password")

        # Requesting missing credentials
        if not username:
            username = self._io.ask("Username:"******"Password:")

        # TODO: handle certificates

        self._uploader.auth(username, password)

        return self._uploader.upload(url)