Poetry and CI builds -- best practices, knowledge share (travisci), and discussion
See original GitHub issue- I have searched the issues of this repo and believe that this is not a duplicate.
- I have searched the documentation and believe that my question is not covered.
Question
Hi! I’ve been working with poetry
recently and am happy that I can publish packages to pypi or my own hosted package repository with it. I would like to share my current setup with TravisCI in hopes that it could help others. I would also like to learn from those who have more experience with poetry
to get tips on how I might make this setup better, or see how it works with other continuous integration platforms, or other more in depth CI/CD requirements.
My requirements for travis-ci are fairly common.
- Use
poetry
to install my project dependencies and dev dependencies. - Run lint and unit tests for my project.
- When the project is git tagged, to build and publish my project to my companies internal pypi registry.
.travis.yml
language: python
python:
- 3.6
env:
global:
- secure: "<encrypted MYPYPI_USER=username>"
- secure: "<encrypted MYPYPI_PASS=p@ssword>"
before_install:
- pip install poetry
install:
- poetry install
script:
- poetry run flake8 my_package test
- poetry run coverage run --source=my_package -m unittest discover -b
before_deploy:
- poetry config repositories.mypypi http://mypypi.example.com/simple
- poetry config http-basic.mypypi $MYPYPI_USER $MYPYPI_PASS
- poetry build -f sdist
deploy:
provider: script
script: poetry publish -r mypypi
skip_cleanup: true
on:
tags: true
I have in the past used the built in travis pypi deployment, but it requires a setup.py
( which I don’t have anymore! 🙌). So instead I’m running my poetry publish as a script deployment when I tag my repo.
So when master is at a spot where I want to deploy a new version of the package. I do something like.
poetry version minor
git commit -am 'bumped the version'
git tag <version>
# SIDE NOTE: it would be nice to be able to do `git tag $(poetry version --show)`
# or possibly have the bump command output the NEW_VERSION=poetry version minor --output
git push --tags
In order to configure poetry with the credentials to push to our repository I have set $MYPYPI_USER
and $MYPYPI_PASS
encrypted environment variables in travis.
That’s what I have. Cheers 🍺
Issue Analytics
- State:
- Created 5 years ago
- Reactions:45
- Comments:28 (6 by maintainers)
Top GitHub Comments
Can I continue the sharing 🙂 ?
Here is my typical
.gitlab-ci.yml
:Poetry tips for GitHub Actions workflows
Use caching to speed up workflows
Use actions/cache with a variation on their
pip
cache example to cache Poetry dependencies for faster installation.Use the custom installer
Installing Poetry via
pip
can lead to dependency conflicts, so the custom installer is recommended. The command listed in the docs exits in GitHub Actions with127
(not on$PATH
).There are some additional modifications needed for GitHub Actions:
-y
to avoid prompts.$GITHUB_PATH
(note that the::set-env
syntax has been deprecated).poetry install
to separate step to ensure Poetry is on$GITHUB_PATH
.Use environment variables for config
Poetry allows config from the
poetry config
command, or by environment variables. Environment variables are a more dependable way to configure Poetry in CI.Build and publish in one step
${{ secrets.PYPI_TOKEN }}
(secret name isPYPI_TOKEN
in this example, and username for PyPI tokens is__token__
).poetry publish --build
to build and publish in one step.That’s why they call it Poetry. Beautiful.
Example workflow
Expand this details element for an example workflow from br3ndonland/inboard that uses these tips.
Bonus: automated dependency updates with Dependabot
Dependabot now offers automated version updates, with (preliminary) support for Poetry 🎉. If you have access to the Dependabot beta, set up .github/dependabot.yml as described in the docs:
Dependabot will now send you PRs when dependency updates are available. Although
package-ecosystem
must be set topip
, it will pick up the pyproject.toml and poetry.lock. Check the status of the repo at Insights -> Dependency graph -> Dependabot.