Skip to content

A semantic-release plugin for PyPi.org that supports both regular and Poetry projects

License

Notifications You must be signed in to change notification settings

ProfessorManhattan/semantic-release-python

Repository files navigation

Semantic Release Python (with Poetry Support)

A plugin created by Megabyte Labs



A semantic-release plugin for PyPi.org that supports both regular and Poetry projects


Table of Contents

Overview

Semantic Release Python is a semantic-release plugin that brings support for managing the publication of PyPi packages. It supports traditional Python projects with a setup.cfg file and also supports Poetry projects.

This plugin requires both Python 3 and a recent version of Node.js to be present. After installing the plugin, a few supporting Python packages will automatically be installed into a virtualenv located at .venv. Using a virtualenv helps to prevent incompatibilities with your current installed software. Before you run any configuration that contains, you must source the virtualenv by running . venv/bin/activate or install the dependencies in this project's requirements.txt through other means prior to utilizing the plugin.

Requirements

If you are simply including this library in your project, all you need is a recent version of Node.js. Node.js >14.18.0 is sometimes required and is the only version range we actively support. Albeit, it is highly probable that lower versions will work as well depending on the requirements that this project imports.

Developer Requirements

The following versions of Node.js and Python are required for development:

Other versions may work, but only the above versions are supported. Most development dependencies are installed automatically by our Taskfile.yml set-up (even Node.js and Python). Run bash start.sh to install Bodega (an improved fork of go-task) and run the initialization sequence. The taskfiles will automatically install dependencies as they are needed, based on what development tasks you are running. For more information, check out the CONTRIBUTING.md or simply run:

npm run help

npm run help will ensure Bodega is installed and then open an interactive dialog where you can explore and learn about various developer commands.

Lifecycle Hooks

Step Description
verifyConditions
  • Verify the environment variable PYPI_TOKEN
  • Verify PYPI_TOKEN is authorized to publish on the specified repository
  • If the project is not a Poetry project (i.e. it has a setup.cfg), then verify that version is not set inside setup.py (version will be set in setup.cfg)
  • If it is not Poetry project, check if the packages setuptools, wheel and twine are installed
  • If it is a Poetry project (i.e. contains pyproject.toml instead of setup.cfg), ensure Poetry is installed
prepare Update the version in setup.cfg and create the distribution packages if it is not a Poetry project. But, if it is a Poetry project, then just update the version.
publish Build the project if it is a Poetry project and then publish the Python package to the PYPI_REPO_URL

Environment Variables

Variable Description Required Default
PYPI_TOKEN API token for PyPi (or password if PYPI_USERNAME is specified) true
PYPI_USERNAME PyPi username (only required if you are using a password instead of an API token) false __token__
PYPI_REPO_URL URL of remote Python package repository false https://upload.pypi.org/legacy/

Options

Option Type Default Description
setupPy string ./setup.py Location of setup.py (or any file in the root of the project for a Poetry project)
distDir string dist Directory to put the source distribution archive(s) in, relative to the directory of setup.py (this variable is not used in Poetry projects)
repoUrl string https://upload.pypi.org/legacy/ The repository to upload the package to
pypiPublish boolean true Whether to publish the Python package to the PyPi registry. If false, the package version will still be updated.
gpgSign boolean false Whether to sign the package using GPG. A valid PGP key must already be installed and configured on the host. Our implementation for Poetry projects currently do not support this feature.
gpgIdentity string null When gpgSign is true, set the GPG identify to use when signing files. Leave empty to use the default identity. Our implementation for Poetry projects currently do not support this feature.

Examples

This plugin can be configured in the semantic-release configuration file. For a full example of a configuration used for multiple project types, check out the shareable configuration we use for all our of projects.

Basic Example Using setup.cfg

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "semantic-release-python"
  ]
}

Example Using Poetry

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "semantic-release-python",
      {
        "setupPy": "./pyproject.toml"
      }
    ]
  ]
}

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page. If you would like to contribute, please take a look at the contributing guide.

Sponsorship

Dear Awesome Person,

I create open source projects out of love. Although I have a job, shelter, and as much fast food as I can handle, it would still be pretty cool to be appreciated by the community for something I have spent a lot of time and money on. Please consider sponsoring me! Who knows? Maybe I will be able to quit my job and publish open source full time.

Sincerely,

Brian Zalewski

Open Collective sponsors GitHub sponsors Patreon

License

Copyright © 2020-2021 Megabyte LLC. This project is MIT licensed.