Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poetry Build System #49

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

darthtrevino
Copy link
Contributor

@darthtrevino darthtrevino commented May 3, 2024

Hey Raul,
I wanted to make some contributions around the issues I've been posting. As a first step I thought I'd offer up a build-system update.

This PR updates semversioner with the Poetry build system, which is a PEP517-based package management tool.

The tasks in the makefile have been replaced with poethepoet tasks. These can be invoked via:

poetry run poe lint
poetry run poe test
poetry run poe clean
# this will run semversioner release, generate a changelog, and update pyproject.toml
poetry run poe release 

# additional parameters can be passed in as well, e.g.
poetry run poe test --junitxml=tests.xml

The release flow is also a little different. The publish script assumes that you're got a PyPi Trusted Publisher configured, which means you don't need $TWINE_USERNAME and $TWINE_PASSWORD. It also expects that developers have run poetry run poe release in a release branch.

If you'd like to use this, I'd be glad to help with any configuration issues you run into.

Thanks!
Chris

@darthtrevino darthtrevino changed the title Use Poetry Build System Use Poetry Build System; Update check command May 4, 2024
@darthtrevino darthtrevino changed the title Use Poetry Build System; Update check command poetry Build System May 6, 2024
@raulgomis
Copy link
Owner

Hi @darthtrevino ,

Thanks for your contribution. I like the idea of moving to Poetry as well as setting up PyPi Trusted Publisher. Let's work on the details to make this merged.

Cheers!
Raul

@@ -0,0 +1,60 @@
[tool.poetry]
name = "semversioner"
version = "2.0.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to automatically bump versions, this should not be hardcoded or manually updated. It should be read from __version__.py.

Copy link
Contributor Author

@darthtrevino darthtrevino Jun 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that may be an incompatible goal with how Poetry works

Copy link
Contributor Author

@darthtrevino darthtrevino Jun 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that there should be a single source of truth here, but I kind of think it should go the other way.
 
We could model this as a build step that reads from pyproject.toml and injects that version into init.py.

Another route we could go is use the poetry-dynamic-versioning plugin to hydrate the version in pyproject.toml and in version.py the closest git tag, which is what I used recently in this project (https://github.com/graspologic-org/graspologic).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense. We could update both places during the build process: https://github.com/raulgomis/semversioner/blob/master/.github/workflows/build-and-publish.yml#L60 and have an additional check to verify both versions are the same before publishing to avoid any mismatch.

This is an interesting thread with similar (and additional) ideas: python-poetry/poetry#144 (comment) .

Thoughts?

.github/workflows/publish.yml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
.github/workflows/publish.yml Show resolved Hide resolved
Copy link
Owner

@raulgomis raulgomis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darthtrevino I'll find some time this week to run this in local and test this branch for additional feedback. Thanks for your contribution.

run: poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to use poetry publish here instead of relying on the github action?


- name: Build Distributable
shell: bash
run: poetry build
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on Github Actions as I normally use other CI/CD tools, but I'd like to find a way that we build only once, and deploy exactly the same artifact we run the tests against. From what I understand from this workflow is that we are building it again, pulling dependencies, etc. The poetry.lock file helps reducing the risk to introducting non tested behaviour, but overall I'd like to have a CI/CD workflow that enforces:

After merging to master:

  • We run tests
  • We package only once
  • We publish the package we run the tests against

Does it make sense? I'll read a bit more about how to achieve that in actions.

@@ -0,0 +1,60 @@
[tool.poetry]
name = "semversioner"
version = "2.0.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense. We could update both places during the build process: https://github.com/raulgomis/semversioner/blob/master/.github/workflows/build-and-publish.yml#L60 and have an additional check to verify both versions are the same before publishing to avoid any mismatch.

This is an interesting thread with similar (and additional) ideas: python-poetry/poetry#144 (comment) .

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants