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

Automate publishing Python package on PyPI #1580

Merged
merged 2 commits into from
Jun 28, 2024
Merged

Automate publishing Python package on PyPI #1580

merged 2 commits into from
Jun 28, 2024

Conversation

bittner
Copy link
Contributor

@bittner bittner commented Mar 5, 2024

Adds two Tox environments that help with publishing the Python package on PyPI.

  • tox -e package can be used for linting to help detect packaging issues.
  • tox -e package -- upload allows to publish the package on PyPI.
  • tox -e ensure_version_matches $GIT_TAG verifies that the package version matches the semantic Git tag on the current commit. This is used by the GHA configuration to prevent a mismatch of tags and the version of the published package.

To make publishing work, you need to add the 2 secrets PYPI_USERNAME and PYPI_PASSWORD to Settings ➜ Secrets ➜ Actions with the PyPI access token for the project, as described in the Python packaging user guide.

Related

Copy link
Collaborator

@lengau lengau left a comment

Choose a reason for hiding this comment

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

Thanks for this!

I think snapcraft 8 lets us get rid of the setup.py file, but we'll find out when I run the CI

.github/workflows/publish-pypi.yaml Outdated Show resolved Hide resolved
@bittner
Copy link
Contributor Author

bittner commented Mar 6, 2024

I think snapcraft 8 lets us get rid of the setup.py file, but we'll find out when I run the CI

The snap-build job fails, because the charmcraft snap configuration takes for granted that setup.py is around:

:: ++ python3 setup.py --version
:: python3: can't open file '/root/parts/charmcraft/src/setup.py': [Errno 2] No such file or directory

From a Python (packaging) point of view the use of setup.py is legacy and every modern Python package should switch over to using (just) pyproject.toml. I guess it's okay if I try to fix the snap configuration with an additional commit to make the pipeline pass.

@bittner
Copy link
Contributor Author

bittner commented Mar 15, 2024

The snap-build job fails as it can't find the craft_cli module.

ModuleNotFoundError: No module named 'craft_cli'

I can't see that the craft-cli Python package is installed in the job, I can only see it as a dependency in requirements.txt.

Can anyone see what is the problem?

@bittner
Copy link
Contributor Author

bittner commented Mar 15, 2024

Can anyone see what is the problem?

Okay, looks like there is a problem with the sed command before that:

sed: -e expression #1, char 14: unterminated `s' command

The problem is that that with the new setup the returned version string also contains the package name. I'll try to find a solution. Suggestions welcome!

EDIT: Stupid me! A closing / was missing. 🤪

@bittner
Copy link
Contributor Author

bittner commented Mar 16, 2024

The CI jobs all pass now (on my personal fork). I rebased the branch, and I made separate commits to document the specific changes that were necessary to work around a few build issues. 📜

Hope that looks good enough now for the PR to be merged. 🤞

@lengau lengau self-requested a review March 18, 2024 17:13
@bittner
Copy link
Contributor Author

bittner commented Mar 18, 2024

I have signed the CLA now. I use a different email address on Launchpad than on GitHub, that's why the check probably didn't find my Launchpad account.

@bittner
Copy link
Contributor Author

bittner commented Mar 18, 2024

The cla-check still fails. I checked my Launchpad account again; looks like there was another account with the email address I use on GitHub. I merged the accounts on Launchpad now.

@bittner
Copy link
Contributor Author

bittner commented Mar 19, 2024

I received an email notification this morning saying, I was added as a member of Canonical Contributor Agreement.

I assume, the cla-check job would now succeed.

pyproject.toml Outdated Show resolved Hide resolved
snap/snapcraft.yaml Outdated Show resolved Hide resolved
@bittner
Copy link
Contributor Author

bittner commented Mar 19, 2024

@lengau Let me know what needs to be changed, if anything, so that I can help getting this merged. Thank you! 👍

@bittner
Copy link
Contributor Author

bittner commented Mar 22, 2024

I rebased the branch of this PR again to keep it up-to-date with the main branch.

If the changes look okay, I'd be happy to see this merged. Otherwise, please let me know what needs to be changed.

@bittner
Copy link
Contributor Author

bittner commented Apr 1, 2024

Is there a reason why this PR isn't considered for merging? Any arguments against the changes? Anything that needs to be updated?

It would be very helpful if the recent release(s) of charmcraft were published also on PyPI. For example, I'm currently blocked by the No keyring found error that was fixed in version 2.3.0 by allowing anonymous downloads of charm library modules. As explained in #1579 (comment) a pure-Python installation is needed for the CI use case.

@lengau lengau requested review from syu-w and lengau April 10, 2024 20:43
Copy link
Collaborator

@lengau lengau left a comment

Choose a reason for hiding this comment

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

Please re-add setup.py, and then I'm happy with this :-)

I've created #1635 for seeing if we can remove setup.py at a later date so we don't block this PR with it

requirements.txt Outdated Show resolved Hide resolved
@bittner bittner requested a review from lengau June 16, 2024 23:10
@bittner
Copy link
Contributor Author

bittner commented Jun 18, 2024

ping 🔔

@lengau Alex, I think this PR is now ready for merging. Can you (or some other maintainer) take a look?

@lengau lengau requested review from tigarmo and a team June 25, 2024 15:01
@lengau lengau enabled auto-merge June 28, 2024 17:21
Copy link
Contributor

@mattculler mattculler left a comment

Choose a reason for hiding this comment

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

👍

tox.ini Show resolved Hide resolved
auto-merge was automatically disabled June 28, 2024 18:58

Pull Request is not mergeable

@lengau lengau enabled auto-merge June 28, 2024 20:16
@lengau lengau added this pull request to the merge queue Jun 28, 2024
Merged via the queue into canonical:main with commit e216376 Jun 28, 2024
16 checks passed
@bittner bittner deleted the feature/automate-publish-pypi branch June 29, 2024 09:46
@bittner
Copy link
Contributor Author

bittner commented Jun 29, 2024

Thanks for merging! 💯

Now don't forget to add the secrets to the project settings to make automatic publishing succeed! 🤖

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.

4 participants