Skip to main content

flit_pytest_circleci_template is a sample project to show how to use flit, pytest, and circleci to automatically build, test and publish Python packages.

Project description

flit_pytest_circleci_template is a sample project to show how to use:

  • flit to build a python package, configured in pyproject.toml
  • pytest to test a python package, configured in pyproject.toml
  • circleci for to build the python package, test it, and publish to pypi automatically.

If you prefer to use github actions, here is a sample using flit in a github action to build a package and publish to testpypi. A later version of that file will no doubt publish to pypi instead of testpypi.

Getting Ready

To proceed with your own package and publishing to pypi:

  • copy the .circleci folder to your project and add to your git repo. Currently it has only one file config.yml that configures the build pipeline for a python project. Here is the .circleci/config.yml and pyproject.toml for this project.
  • Create the pyproject.toml as normally required to build your package with flit. Include in test dependencies pytest and any other python packages that need to be installed for testing:
[project.optional-dependencies]
test = [
    "pytest >=7.1.2",
]
  • Add testpaths to [tool.pytest.ini_options] identifying where your tests are located. Specifying minversion and addopts is also recommended:
[tool.pytest.ini_options]
minversion = "7.1.2"
addopts = "--capture=tee-sys "

testpaths= [
    "test",
]

When you are satisifed with your tests, review the config.yml and see if there are any obvious changes you require. You may not need any but you might elect to update to the latest python orb or specific python image you would like to use to build and test your python package.

The publish step will normally fail if there is already a package in pypi with the same version number. Which is desired behavior. When you are ready to publish, increase the version number (in pyproject.toml or init.py depending on how the project is set up.).

** You can elect to publish to testpypi by tweaking the twine command in config.yml **

Configure circleci

Create a circleci account if you don't have one and add your github repository as a project. Get the build at least running.

Using Project Settings, add Environment variables TWINE_USERNAME and TWINE_PASSWORD. These are the credentials you use to publish to pypi or testpypi. Until you set those variables, the publish stop obviously will fail, but the package build and test steps should work.

License

You can do whatever you want with the code in this repository and apply whatever license you want to copies or modifications in your own project. This project is mean to be a helpful starting point for people who want to get circleci to build and publish python packages.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flit_pytest_circleci_template-0.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page