pyodide / micropip

A lightweight Python package installer for Pyodide
https://micropip.pyodide.org
Mozilla Public License 2.0
85 stars 23 forks source link

pre-relseases installed when mentioned directly, not when dependencies. #162

Open Carreau opened 5 days ago

Carreau commented 5 days ago

found when working on #159, in particular https://github.com/pyodide/micropip/pull/159#issuecomment-2493771874

Tracked down to:

In [5]: from packaging.requirements import Requirement
   ...: from packaging.version import Version
   ...: req_numpy_with_ver = Requirement('numpy<3,>=1.23')
   ...: req_numpy_no_ver = Requirement('numpy')
   ...:
   ...: print(list(req_numpy_with_ver.specifier.filter([Version('2.2.0.dev')])))
   ...: print(list(req_numpy_with_ver.specifier.filter([Version('2.2.0.dev')], prereleases=True)))
   ...:
   ...: print(list(req_numpy_no_ver.specifier.filter([Version('2.2.0.dev')])))
   ...: print(list(req_numpy_no_ver.specifier.filter([Version('2.2.0.dev')], prereleases=True)))
   ...:
   ...:
[]                          # if a dependency: 
[<Version('2.2.0.dev0')>]
[<Version('2.2.0.dev0')>]   # trigger this is install direct
[<Version('2.2.0.dev0')>]

In [7]: packaging.__version__
Out[7]: '24.1'

This also lead to weird things:

>>> await micropip.install('numpy<3', index_urls=['https://cors.carreau.workers.dev/scientific-python-nightly-wheels/simple'])
# ValueError: Can't find a pure Python 3 wheel for 'numpy<3'.

but (note the lack of <3)

>>> await micropip.install('numpy', index_urls=['https://cors.carreau.workers.dev/scientific-python-nightly-wheels/simple'])
# Successfully installed numpy-2.3.0.dev0

I don't know if it's a packaging bug, or an incorrect usage of packaging; so I'm opening the issue here.

Carreau commented 4 days ago

Ok, this is because the filter operation of packaging is not distributive:

In [29]: list(SpecifierSet('').filter(['1.0','2.2.0.dev']))
Out[29]: ['1.0']

In [30]: list(SpecifierSet('').filter(['2.2.0.dev']))
Out[30]: ['2.2.0.dev']