Prepare the project for publication on PyPI
This diff and the following steps will resolve #18.
You will need to install tox if you don't already have it.
I recommend using the same steps outlined in Option 1 in the README.
- Review and merge this PR.
- Create an account on PyPI: https://pypi.org/account/register/
- We need an API token to enable automatic publication, but we cannot create one until the project is created and associated with your account. So, the first time (only) we must publish manually:
git fetch mhagger git checkout mhagger/master tox -e publish -- upload # This will ask for your PyPI creds.- Note: This will publish a developmental release (because the version is generated from the nearest tag, and we haven't created a new tag since merging):
$ tox -e publish # Creates distributions for publication, but does NOT upload them. ... $ .tox/.package/bin/python setup.py --version 1.2.1.dev6+gc97f5a6- That version is a PEP 440-compliant variant of
git describegenerated bysetuptools-scm:$ git describe v1.2.0-6-gc97f5a6 pip installwill ignore developmental releases unless the--devoption is passed (or the exact version is given).
- That version is a PEP 440-compliant variant of
- Note: This will publish a developmental release (because the version is generated from the nearest tag, and we haven't created a new tag since merging):
- The project should now exist on PyPI: https://pypi.org/project/git-when-merged/
That means we can now create an API token for it.
- Go to https://pypi.org/manage/account/ and scroll down to the "API tokens" section.
- Click "Add API token".
- Under "Token name" put something like "GitHub Actions" since that what we're going to use it for.
- Under "Scope" select "Project: git-when-merged".
- Click "Add token".
- PyPI may ask you to confirm your password.
- Click "Copy token".
- Now we need to set the API token as a Repository secret for this repository.
- Go to https://github.com/mhagger/git-when-merged/settings/secrets/actions/new
- Under "Name", type
PYPI_PASSWORD(as that is what the Publication workflow in this PR expects). - Under "Value", paste the token we copied in step 4.vii.
- Click "Add secret".
- Repeat steps 5.i through 5.iv to set
PYPI_USERNAMEto__token__.
That's it for one-time setup! Now, new distributions will automatically be published whenever a Release is created on GitHub: https://github.com/mhagger/git-when-merged/releases/new
New distributions can also be published manually at any time using tox -e publish -- upload. The version that is published will depend on what is checked out when the command is run.
Thanks!
I think that I'll skip the Actions automation; i.e., I'll end up merging the first three of your patches but not the fourth.
What is your rationale for requiring a minimum python version of 3.7? I believe that the code should work with Python all the way back to 2.6. I see that 3.7 is the latest supported version of Python; is that the reason?
Your instructions seem to work, except for checking the version with
$ .tox/.package/bin/python setup.py --version 1.2.1.dev6+gc97f5a6
First of all, the path .tox/.package doesn't even exist after running tox -e publish. The only python that exists is .tox/publish/bin/python. But running the command using that python version seems to consistently give version 0.0.0, regardless of whether there was a tag pointing at the checked-out version when I ran tox -e publish:
$ .tox/publish/bin/python setup.py --version
0.0.0
The files under .tox/dist/ do seem to have the expected version number in their filenames, though, so maybe this isn't a problem?
Thanks again for your help!
I think that I'll skip the Actions automation; i.e., I'll end up merging the first three of your patches but not the fourth.
👌 np. I'll remove that commit.
What is your rationale for requiring a minimum python version of 3.7? I believe that the code should work with Python all the way back to 2.6. I see that 3.7 is the latest supported version of Python; is that the reason?
The build tools require 3.7 (except wheel):
https://github.com/mhagger/git-when-merged/blob/c97f5a6a76554737740633fd0054d81cd9302973/pyproject.toml#L2
Using older versions to get 3.5 or 3.6 support probably wouldn't be too hard, but getting them for 2.6 would be. Even supporting 2.7 usually requires some special handling...
First of all, the path
.tox/.packagedoesn't even exist after runningtox -e publish.
Woops, that's my fault... I forgot to update the instructions after adding this optimization: https://github.com/mhagger/git-when-merged/blob/c97f5a6a76554737740633fd0054d81cd9302973/tox.ini#L17
Usually, tox builds the project and installs it into the testenv before running the testenv's commands. Since the purpose of the publish testenv is to build the project, we don't need tox to also build it 😅 You should be able to create .tox/.package by running any of the other testenvs (e.g. tox -e static):
https://github.com/mhagger/git-when-merged/blob/c97f5a6a76554737740633fd0054d81cd9302973/tox.ini#L5-L9
The only
pythonthat exists is.tox/publish/bin/python. But running the command using that python version seems to consistently give version0.0.0, regardless of whether there was a tag pointing at the checked-out version when I rantox -e publish:
The reason that happens is because publish (and indeed any other testenv) doesn't have the build tools installed by default. The build happens in an isolated virtualenv (.tox/.package if tox is doing the building) as described in PEP 517. The build tools are installed, and they are used to build one or more wheels. That wheel, along with any dependencies specified in install_requires, is what gets installed in the testenv. The isolated build env with the build tools installed in usually gets destroyed, although tox leaves .tox/.package in place.
The files under
.tox/dist/do seem to have the expected version number in their filenames, though, so maybe this isn't a problem?
Yes, that is because build used the PEP 517 build process I mentioned above:
https://github.com/mhagger/git-when-merged/blob/c97f5a6a76554737740633fd0054d81cd9302973/tox.ini#L19
So the build tools were in place when those dists were created.
@tucked: thanks for all the help! :sparkles:
That kindof took me forever, but I have finally merged your PR along with a couple of minor tweaks and created and uploaded a release to PyPI. If you see any problems, please let me know.