crflynn / pypistats.org

PyPI downloads analytics dashboard
https://pypistats.org/
140 stars 10 forks source link

optional dependencies are incorrect #62

Open maartenbreddels opened 1 year ago

maartenbreddels commented 1 year ago

Hi,

thanks for this project. I noticed on https://pypistats.org/packages/solara that it listed dask as a dependency, while it is only an optional dependency. Looking at: https://github.com/crflynn/pypistats.org/blob/70a10f994173b4b9e8905fb3494dd5d0d5bd1bbb/pypistats/views/general.py#L118 is too I see this check will not detect something like "dask[dataframe]; python_version < '3.7' and extra == 'dev'",

where the extra is not directly after the ;

Regards,

Maarten

domdfcoding commented 1 year ago

It might be better to use the packaging library (specifically packaging.requirements.Requirement for the parsing.

For example

from packaging.requirements import Requirement
r = Requirement("dask[dataframe]; python_version < '3.7' and extra=='dev'")
package_name = r.name
is_optional = ("extra == " in str(r.marker))  # the requirement gets normalised so there will always be spaces around the ==
print(package_name, is_optional)
# dask True
mauvilsa commented 7 months ago

Clearly the listing of required vs. optional packages is wrong. Since it seems to be an easy fix, @maartenbreddels @domdfcoding, why not create a pull request?

@crflynn there hasn't been a commit here in two years. Would a fix for this be merged?