Skip to content

ENH: Publish your python package to PyPI #164

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

Merged
merged 9 commits into from
Jan 22, 2024

Conversation

lwasser
Copy link
Member

@lwasser lwasser commented Jan 12, 2024

There are two versions of this lesson in this PR - i'm thinking the hatch version is the way to go because the environment complexities without hatch are significant. the lesson is shorted and simpler using hatch than it would be with build and twine for numerous reasons. With that said, i did leave the original twine lesson in the pr too in case people want to look at it and think about the difference between the two. we will ultimately remove one of these - likely the twine lesson.


```bash
# This will create a default envt with your package installed in editable mode
hatch env create
Copy link
Member Author

Choose a reason for hiding this comment

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

➜ hatch -e dev pytest
Usage: hatch [OPTIONS] COMMAND [ARGS]...
Try 'hatch -h' for help.

Error: No such command 'pytest'.

pyosPackage (☊ main) [✎ ×1 ] is 📦 v0.1.0 🐍 v3.12.1 
❯ hatch -e dev pytest


If you don't already have a pyos-package development environment, create one now.

::::{tab-set}
Copy link
Member Author

Choose a reason for hiding this comment

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

All of this could go away potentially with hatch.

@@ -0,0 +1,588 @@
# Publish your Python package to PyPI - without hatch
Copy link
Member Author

Choose a reason for hiding this comment

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

All: this is the older lesson that used twine. it's a lot more complex to teach because you have to either guess what envt manager someone is using or provide instructions across conda, venv windows / linux+maxos

so this lesson is much more complex. im leaning towards deleting it and just leaning in 100% to hatch.

@@ -0,0 +1,416 @@
# Publish your Python package to PyPI
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the hatch lesson! i left a few TODO's at the top - the biggest one is

should we teach pipx to install hatch? (it seems that would make sense) except pipx is a bit weird to install on windows potentially.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am +1 on pipx. Even though the installation is not the easiest on Windows, I found it far easier to introduce tooling to beginners. With pipx, they do not mess with their global install, and they do not have any issue with tools being installed in virtual environment (and forgetting to activate said envs).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I just found out that pipx is available on scoop: https://scoop.sh/#/apps?q=pipx.
Then it is just as easy to install on Windows as on Linux/MacOS

Copy link
Member Author

Choose a reason for hiding this comment

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

ok scoop is easy? i just wasn't sure. i installed with homebrew @Batalex and it was really easy but you have to have homebrew setup of course. i also read that you can install pipx with pip but that hurts my brain a bit. i'm not sure where it would get installed if you did that.

@lwasser lwasser changed the title [DRAFT] Fix: first push of pypi lesson [BUG BASH] ENH: Publish your python package to PyPI Jan 12, 2024
Copy link
Collaborator

@ucodery ucodery left a comment

Choose a reason for hiding this comment

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

I just looked at the hatch lesson since that seems to be the chosen one. The publish workflow looks so nice with this tool.

I am wondering if too much focus is being placed on distribution types, especially for a beginner lesson. I don't think we should ignore the distribution files or not note there are two types. But maybe once in the whole lesson. Hatch, like most of the rest of the modern build front ends will always produce an sdist and wheels when it builds. And it will publish all dist files without the user really having to think about it. I think new users won't care that there are different distribution types, or why both are needed, just as long as it will work; which it will (including for conda-forge) out of the box.

* Should we install hatch with pipx?

```bash
pipx install hatch
Copy link
Collaborator

Choose a reason for hiding this comment

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

I could be convinced, but I don't see the point of telling new users about a python venv management tool to manage their environment management tool. How do they get pipx without polluting a top-level environment? pipx-in-pipx? (mostly serious, this is a good tool, but now we have three environment tools to teach in one lesson).

Copy link
Member Author

Choose a reason for hiding this comment

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

i hear you. it sounds like we have mixed opinions about using pipx vs pip. it is very true that the pipx install will add cognitive load to this lesson. it's not the simplest altho you can pip install pipx but i could see that also confusing users as it kind of confuses me to think about it!

maybe we can talk more in slack. i know some really like pipx and i do understand why. but on the other hand, most beginners won't likely be dealing with a ton of different package environments as they are just learning so keeping it simpler for now could be good. we could have a tiny breakout about pipx so they know it exists if they want to use it.

Copy link
Contributor

@kierisi kierisi left a comment

Choose a reason for hiding this comment

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

left a few suggestions! otherwise things look good to me.

lwasser and others added 5 commits January 19, 2024 14:03
Co-authored-by: Jeremy Paige <ucodery@gmail.com>
Co-authored-by: Jeremy Paige <ucodery@gmail.com>
Co-authored-by: Alex Batisse <alexandre.batisse@hey.com>
Co-authored-by: Jeremy Paige <ucodery@gmail.com>
@lwasser lwasser changed the title [BUG BASH] ENH: Publish your python package to PyPI ENH: Publish your python package to PyPI Jan 22, 2024
@lwasser
Copy link
Member Author

lwasser commented Jan 22, 2024

ok everyone! i am going to move forward with merging this as all of the feedback has been integrated and none of the changes were significant. As such i don't think we need a second review!

If we discover issues in the lesson in future reviews we can always make changes then.

@@ -37,7 +37,7 @@ Licenses are legally binding, as such you should avoid trying to create your own

### Use open permissive licenses when possible

Copy link
Member Author

Choose a reason for hiding this comment

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

this is causing issues in CI so i fixed the link.

Fix: bad link

Fix: add 429 http code
@lwasser lwasser merged commit dd9c93b into pyOpenSci:main Jan 22, 2024
@lwasser lwasser deleted the bb-pypi-jan24 branch January 22, 2024 19:25
@lwasser
Copy link
Member Author

lwasser commented Jan 22, 2024

@all-contributors please add @ofek for tutorials

Copy link
Contributor

@lwasser

I've put up a pull request to add @ofek! 🎉

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

Successfully merging this pull request may close these issues.

5 participants