Package: setuptools-github
setuptools-githubIntroductionsetuptools-github helps to setup a simple project life cycle
where the target is delivering packages intoPyPIfrom a hosted project atGithub.The idea is rather simple (and detailed inhere):commits on a master branch will trigger code checks (static checks, tests etc.)commits on abeta/N.M.Obranch will do all the previous checks + publishing a beta package N.M.ObXXX(XXXis an increasing number) onPyPItagging on abeta/N.M.Obranch will publish an official package onPyPIfor N.M.OSeeherefor what the life cycle implementation looks like.IndexSetup the projectinstall the packagesetup theinit.py filefix the setup.py fileSetup the workflow filesadd the filessetup the secretsWorking with branchescommit on the master branchcommit on a beta/N.M.O branchreleasing on tagsSetup the projectThe project should conform to this layout style:project-name/
  ├── setup.py
  ├── pyproject.toml
  ├── .github
  │   └── workflows           <- workflow files for
  │       ├── beta.yml             * beta/N.M.O branches
  │       ├── master.yml           * master branch
  │       └── tags.yml             * release/N.M.O tags
  ├── src
  │   └── project_name        <- project name
  │       └── __init__.py     <- version_file
  └── tests                   <- tests (pytest)
      ├── conftest.py
      └── requirements.txt    <- requirement file for testsNOTEfor a pyproject.toml / hatch enabled version of this, please usehatch-ci plugininstall the packagepipinstallsetuptools-githubor
condainstall-cconda-forgesetuptools-githubsetup up the initial version_fileCreate a new version_filesrc/project_name/__init__.pyfile to store the package information:__version__ = "N.M.O"  # replace N, M and O with numerical values (eg. 0.0.0)
__hash__ = ""  # leave this emptyFix the setup.py fileInclude in thesetup.pyfile:from setuptools_github import tools

setup(
  name="project-name",
  version=tools.process(version_file, os.getenv("GITHUB_DUMP"))["version"],
  ...NOTE: there's an annotatedtools.processexample insetup.pywith support for keyword substitution on text files.Setup the workflow filesThese are the steps to automate the build process on github.add workflow filesAdd these workflows file to your project:github/workflows/master.ymlgithub/workflows/beta.ymlgithub/workflows/tags.ymlThese will trigger a build on:a master branch commitseea beta/N.M.O commitseea release on tag release/N.M.OseeNOTE: Most likely you might need to change:thetests/requirements.txtfilethe envs variables at the beging ofmaster.ymlandbeta.ymlSetup github secretsIn order to publish to codecov the coveragen info and to PyPI the wheels,
you need to set the github secrets under:https://github.com/username/project-name/settings/secrets/actionsThese are the needed secrets for the PyPI index and codecov services:TWINE_PASSWORDTWINE_USERNAMECODECOV_TOKENTHAT IS ALL! Now when commit to the master branch, this will trigger the
github action to run tests and quality checks on the codeWorking with branchescommit on the master branchEvery time there's a commit on themasterbranch, this will trigger
the workflow under ./github/workflows/master.yml:Runs mypy on src/Runs ruff on src/Run all tests under tests/On completion static and dynamic tests are supported.commit on a beta/N.M.O branchIn order to prepare for a release a newbeta/N.M.Obranch should be created:python-msetuptools_github.scriptmake-betasrc/project_name/__init__.pyorsetuptools-githubmake-betasrc/project_name/__init__.pyEvery commit onbeta/N.M.Obranch ifSecretshave been set
properly:Runs mypy on src/Runs ruff on src/Run all tests under tests/Run coverage on tests/Send the coverage result intocoverageCreate a new wheel package under dist/(on success) Send the new wheelspackage-N.M.O.bXtoPyPINOTE: the nameproject-N.M.O.bXcontains the X: this is an
incrementing counter set during build.
This meansproject-N.M.O.bX<project-N.M.Oallowing
the correct package ordering.releasing on tagsTo release an official package forproject-N.M.Ofrom
thebeta/N.M.Obranch:python-msetuptools_github.scriptmicrosrc/project_name/__init__.pyorsetuptools-githubmake-betamicrosrc/project_name/__init__.pyThis will tag the HEAD onbeta/N.M.Obranch
with therelease/N.M.Otag and increment theversion_filewith the
next version N.M.O+1 (using micro).Once done, you'll need to push it the tag.gitpushrelease/N.M.OThis will:trigger a CI build that will create the project-name-N.M.OCreate a new wheel package under dist/(on success) Send the new wheelsproject-N.M.OtoPyPI