コード例 #1
0
    def upload_enabled() -> bool:
        """
        Check if artifact repository upload is enabled

        :returns True if upload is enabled, False otherwise.
        """
        return config.get("upload_to_repository") and config.get(
            "upload_to_pypi")
コード例 #2
0
    def _handle_glob_patterns(self, dist_path: Path) -> None:
        """
        Load glob patterns that select the distribution files to publish.

        :param dist_path: Path to folder with package files
        """
        glob_patterns = config.get("dist_glob_patterns") or config.get(
            "upload_to_pypi_glob_patterns")
        glob_patterns = (glob_patterns or "*").split(",")

        self.dists = [
            str(dist_path.joinpath(pattern)) for pattern in glob_patterns
        ]
コード例 #3
0
    def _handle_repository_config(self) -> None:
        """
        Initialize repository settings from config.

        *repository_url* overrides *repository*, Twine handles this the same way.

        Defaults to repository_name `pypi` when both are not set.
        """
        repository_url = config.get("repository_url")
        repository_name = config.get("repository")

        if repository_url:
            self.repository_url = repository_url
        elif repository_name:
            self.repository_name = repository_name
コード例 #4
0
def get_env_var(name: str) -> Optional[str]:
    """
    Resolve variable name from config and return matching environment variable

    :param name: Variable name to retrieve from environment

    :returns Value of environment variable or None if not set.
    """
    return os.environ.get(config.get(name))
コード例 #5
0
def upload_to_pypi(
    path: str = "dist", skip_existing: bool = False, glob_patterns: List[str] = None
):
    """Upload wheels to PyPI with Twine.

    Wheels must already be created and stored at the given path.

    Credentials are taken from either the environment variable
    ``PYPI_TOKEN``, or from ``PYPI_USERNAME`` and ``PYPI_PASSWORD``.

    :param path: Path to dist folder containing the files to upload.
    :param skip_existing: Continue uploading files if one already exists.
        (Only valid when uploading to PyPI. Other implementations may not support this.)
    :param glob_patterns: List of glob patterns to include in the upload (["*"] by default).
    """
    if not glob_patterns:
        glob_patterns = ["*"]

    # Attempt to get an API token from environment
    token = os.environ.get("PYPI_TOKEN")
    username = None
    password = None
    if not token:
        # Look for a username and password instead
        username = os.environ.get("PYPI_USERNAME")
        password = os.environ.get("PYPI_PASSWORD")
        home_dir = os.environ.get("HOME", "")
        if not (username or password) and (
            not home_dir or not os.path.isfile(os.path.join(home_dir, ".pypirc"))
        ):
            raise ImproperConfigurationError(
                "Missing credentials for uploading to PyPI"
            )
    elif not token.startswith("pypi-"):
        raise ImproperConfigurationError('PyPI token should begin with "pypi-"')
    else:
        username = "******"
        password = token

    repository = config.get("repository", None)
    repository_arg = f" -r '{repository}'" if repository else ""

    username_password = (
        f"-u '{username}' -p '{password}'" if username and password else ""
    )

    dist = " ".join(
        ['"{}/{}"'.format(path, glob_pattern.strip()) for glob_pattern in glob_patterns]
    )

    skip_existing_param = " --skip-existing" if skip_existing else ""

    run(f"twine upload {username_password}{repository_arg}{skip_existing_param} {dist}")
コード例 #6
0
def parse_commit_message(message):
    """
    Parses a commit message according to the 1.0 version of python-semantic-release. It expects
    a tag of some sort in the commit message and will use the rest of the first line as changelog
    content.
    :param message: A string of a commit message.
    :raises semantic_release.UnknownCommitMessageStyle: If it does not recognise the commit style
    :return: A tuple of (level to bump, type of change, scope of change, a tuple with descriptions)
    """
    if config.get('minor_tag') in message:
        level = 'feature'
        level_bump = 2
        subject = message.replace(config.get('minor_tag'), '')

    elif config.get('fix_tag') in message:
        level = 'fix'
        level_bump = 1
        subject = message.replace(config.get('fix_tag'), '')

    elif config.get('major_tag') in message:
        level = 'breaking'
        level_bump = 3
        subject = message.replace(config.get('major_tag'), '')

    else:
        raise UnknownCommitMessageStyleError(
            'Unable to parse the given commit message: {0}'.format(message))

    body = message
    footer = message

    return ParsedCommit(level_bump, level, None,
                        (subject.strip(), body.strip(), footer.strip()), None)