jvllmr/poetry-types

Does poetry-types handle dependencies?

Closed this issue · 5 comments

Pandas is required by my projects via a dependency, so it is not directly in my pyproject.toml. However, it is in my poetry.lock file.

If I add pandas types with poetry types add pandas then pandas-stubs gets added to my types group. However when I run poetry types update it removes pandas-stubs.

If I add pandas directly to my poetry dependencies in pyproject.toml then pandas-stubs is not removed with poetry types update

It seems that pandas is detected, if I run poetry types update -vvv then I get this at the end of the output:

   0: Complete version solving took 1.253 seconds with 3 overrides
   0: Resolved with overrides: ({Package('pandas', '2.2.2'): {'numpy': <Dependency numpy (>=1.22.4)>}}), ({Package('pandas', '2.2.2'): {'numpy': <Dependency numpy (>=1.23.2)>}}), ({Package('pandas', '2.2.2'): {'numpy': <Dependency numpy (>=1.26.0)>}})

Finding the necessary packages for the current system

Package operations: 0 installs, 0 updates, 2 removals

  - Removing pandas-stubs (2.2.1.240316): Pending...
  - Removing pandas-stubs (2.2.1.240316): Removing...
  - Removing pandas-stubs (2.2.1.240316)
  - Removing types-pytz (2024.1.0.20240417): Pending...
  - Removing types-pytz (2024.1.0.20240417): Removing...
  - Removing types-pytz (2024.1.0.20240417)

Writing lock file

So it seems to know I have pandas installed but it still removes pandas-stubs

poetry-types collects your dependencies from pyproject.toml and syncs your types group based on that information. It should work for most usecases.

But it seems that in your case reading from poetry.lock would be the better solution.
How and why is pandas not in your pyproject.toml, but in your poetry.lock? I want to understand your usecase.

Pandas is not my pyproject.toml because I do not want to pin the version in my library - if a downstream user wants to use a different version of pandas that is there call. However, it is a requirement of one of my library's dependencies

at 18:00:42 ❯ poetry show pandas                          
 name         : pandas                                                                  
 version      : 2.2.2                                                                   
 description  : Powerful data structures for data analysis, time series, and statistics 

dependencies
 - numpy >=1.22.4
 - numpy >=1.23.2
 - numpy >=1.26.0
 - python-dateutil >=2.8.2
 - pytz >=2020.1
 - tzdata >=2022.7

required by
 - databricks-connect >=1.0.5

From my point of view there are multiple solutions to this:
- Add pandas with a wildcard contraint pandas = "*"
- Add pandas with an constraints that allows every future version pandas = ">=2.0.0" (I think allowing 1.0 is a bad idea as an older major release will most likely break something; this would be my preferred solution)
- Add pandas to your dev group so it won't be included inside your packages metadata (poetry install --group dev pandas)

I assume I could help you of some sort.