-
Notifications
You must be signed in to change notification settings - Fork 74
enh: update dependency page to support pep 735 and uv #584
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
Conversation
| To ensure this works as you want it to, activate your package's development | ||
| environment prior to installing anything using `pip`. | ||
| :::{todo} | ||
| We shouldn't show UV pip install, so how do you add optional feature deps with UV?? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zanieb I wondered if you could help us here by reviewing this and helping me understand how astral expects users to use uv to install things like feature dependencies etc. Adding deps is super easy and clear to me but i'd love your input on this pr if you have bandwidth.
| **Install optional dependencies:** | ||
| ```bash | ||
| # FIXME | ||
| uv pip install -e ".[docs]" # Single group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will uv sync sync everything or do you have to tell it to sync specific groups? uv pip install could install into the wrong environment i think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i did figure out that you can uv sync --group so it won't install group items by default but you can ask it to and it will.
The different tho is if we use hatch - it's a different model entirely. where you tell Hatch what features or groups to install into individual, unique environments, whereas UV just plops things into a single project-based envt. 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also the --active flag that will choose whatever environment that is currently active
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@all-contributors please add @yeelauren for docs, review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lauren i've turned this into an issue to address in the pr for this same page (that i'll reopen next week) post workshop!!
| `python -m pip install ".[tests]"` | ||
| You can use uv sync to sync dependency groups too | ||
| ```bash | ||
| # TEST ME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all works perfectly
| You can use uv sync to sync dependency groups too | ||
| ```bash | ||
| # TEST ME | ||
| uv sync --group docs # Single group |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to test groups like this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also works well.
|
We might want to add hatch environment examples with task runner features... in a small breakout ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change makes the diagram a bit misleading now. Dependency Groups do not have to include your package, nor any subset of your package's required dependencies. They certainly can, by including your package just as any other dependency, but they can also be entirely disjointed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - I can take another stab at this tomorrow - maybe dependency groups are to the side in a small bubble?
so we have optional and your package which overlap as optional is for features. (and sometimes tests? if people include them)
And the dependency groups are development focused - not ever user facing.
Does this sound reasonable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's kind of awkward because there certainly will be some dependency groups that will be off in their own bubble (formatter environments) but others that will be supersets, like in the old graphic (test environments, generally)
|
|
||
| ```toml | ||
| dependencies = [ | ||
| "pandas", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a wild toml format 😶
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh gosh - i'll look at this again tomorrow - i was jumping between the template - i have done a fairly big cleanup and this page. 😆
|
|
||
| Optional dependencies dependencies can be optionally installed by users | ||
| depending upon their needs. There are two broad groups of optional dependencies: | ||
| Optional (or feature) dependencies can be installed by users as needed. They add specific features to your package that not all users might need. For example, if your package has an optional interactive plotting feature that uses Bokeh, you would list Bokeh as a feature dependency so users who don't need plotting don't have to install it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc seems to now be missing a section, ### Group Dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's at the bottom - i am doing a big reorg now. I'm going to push what I have and will pick up again tomorrow so that this is all clearer. i hear you that it's not well organized.
| ### Understanding optional vs. required dependencies | ||
| You can think about dependencies as being either optional or required. If they are required, they will be listed in the `dependencies` key in the `project` table of your `pyproject.toml` file. If they are optional, they will be listed in the `[optional.dependencies]` table of your `pyproject.toml`. | ||
| Specifying dependencies in your `pyproject.toml` file ensures that your package works correctly. | ||
| Users automatically get the packages your code needs to run. For instance, if your package requires Pandas to run properly, Pandas will be installed into the users' environment when they install your package using uv, pip or conda, if you specify it as a dependency in your pyproject.toml file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you removed all the <code> embellishing in this paragraph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh can you help me understand that comment Jeremiah? I added a paragraph (essentially, there was a todo from Jonny on adding a paragraph about the why). So this is a new paragraph that introduces why we need / care about dependencies and then we can talk more about the different kinds. as i'm writing this - i am realizing it's also confusing here because there are 3 kinds and only 1 is really necessary for a user to ensure the package works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, nothing so significant. I just mean that the pyproject.toml and other TOML fields had their backticks removed.
| `python -m pip install plotMe` | ||
|
|
||
| This means that in order for plotMe to work in a user's `environment` when installed, you also need to ensure that they have both of those required `dependencies` installed in their environment too. | ||
| or if plotMe is in the pyproject.toml: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs expaned. "if plotMe is in the pyproject.toml's project.dependencies"? Or do you mean plotMe is the package, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh no that's a blatant typo.
|
|
||
| 1. Add a `[project.optional-dependencies]` table to your **pyproject.toml** file. | ||
| 2. Create named groups of dependencies using the syntax: | ||
| You can also add feature dependencies to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see what this example specifically adds to the Dependency Group section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed this (I think). I wanted to touch on the fact that some people might include tests in the optional dependency group, as some people like to ship tests with their package (like the core scientific packages). I think it's just as confusing as I wrote it. For some reason, the packaging template really fries my brain when I work on it. it requires a lot of focus.
| Below we've created three sets of optional development dependencies named: tests, docs and lint. We've also added a set of feature dependencies. | ||
| Will add this to your pyproject.toml | ||
| ```toml | ||
| feature = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This toml break-out needs to have the section header. This looks like a top-level field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added throughout. i also reorganized to make this more clear.
| :::{figure-md} python-package-dependencies | ||
|
|
||
| <img src="../images/python-package-dependencies.png" alt="Diagram showing a Venn diagram with three sections representing the dependency groups listed above - docs feature and tests. In the center it says your-package and lists the core dependencies of that package seaborn and numpy. To the right are two arrows. The first shows the command python - m pip install your-package. It them shows how installing your package that way installs only the package and the two core dependencies into a users environment. Below is a second arrow with python -m pip install youPackage[tests]. This leads to an environment with both the package dependencies - your-package, seaborn and numpy and also the tests dependencies including pytest and pytest-cov "> | ||
| <img src="../images/python-package-dependencies.png" alt="Diagram showing a Venn diagram with three sections representing dependency groups - docs, feature, and tests. In the center it shows your-package with core dependencies seaborn and numpy. Two arrows on the right demonstrate: first, python -m pip install your-package installs only the package and core dependencies. Second, python -m pip install your-package[tests] installs the package, core dependencies, and test dependencies including pytest and pytest-cov."> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the diagram does show any pip commands, unless I am missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the image that i pasted into the pr body that this caption references- i haven't touched it yet because all of the UV stuff is new here. I'm trying to figure out ways to update our graphics and explain these 3 types of deps clearly.
My goal with this graphic was to show a user that the different types of dependencies may or may not install into their environments depending on how they call things when they use pip.
But the reason I haven't touched this graphic is that UV has a different model of doing things than pip does. And i also think i'm getting stuck on - thinking about how a user might install vs how a developer might install.
I think my brain was a bit fried from working on the packaging template, but I also welcome all of this feedback, and I'll make a point to work on this page FIRST in the morning tomorrow. But also, I'm not sure if we need a different structure here. The old structure isn't right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also relates to my question below - where uv pip install can be a bit dangerous (as we learned!!), and it might be better to avoid it. but there are users still using pip. and uv is newer.
i'm not sure how to manage messaging around this and am open to suggestions.
|
Cool! I'll add this to my todo list (I'm at an onsite through the end of the week though so it'll be next week) |
ok fantastic. I will create a shiny new pr with all of this content for review next week (I'm going to merge later today for a workshop tomorrow), but then we can do a proper review next week! Thank you so so much! My biggest question now relates to using uv pip install. |
|
Ok fantastic. i've made signfiicant improvements to this page. the plan:
|
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Jeremiah Paige <ucodery@gmail.com>
Co-authored-by: Jeremiah Paige <ucodery@gmail.com>

No description provided.