Skip to content
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

Technical debt with deps specifications #3074

Closed
neutrinoceros opened this issue Feb 11, 2021 · 5 comments
Closed

Technical debt with deps specifications #3074

neutrinoceros opened this issue Feb 11, 2021 · 5 comments
Labels

Comments

@neutrinoceros
Copy link
Member

neutrinoceros commented Feb 11, 2021

Bug report

Bug summary

Currently, there are several files specifying constraints for our deps. I'll try to list them all here with short descriptions

  • setup.py: defines mandatory runtime dependencies (update: migrated to setup.cfg in Migrate metadata from setup.py to setup.cfg #3078)
  • pyproject.toml: defines only Cython and numpy as compile-time deps
  • tests/test_prerequirements.txt: again, constrains for Cython and numpy, but this time it's needed because Cartopy (an optional dep to us) doesn't define its own compile time deps correctly (?)
  • tests/test_requirements.txt: contains all optional deps of yt and (mostly) up-to-date versions of mandatory deps
  • tests/ci_install.sh: contains "minimal" requirements for Cython and numpy (for Cartopy again)
  • tests/test_minimal_requirements.txt: defines minimal mandatory runtime deps

Evidently this is getting pretty hard to maintain, especially in PRs like #2917 (ok maybe the plural isn't appropriate)... and quite confusing for everyone.

It seems to me that, for the most part (i.e. ignoring the Cartopy Problem™️), the problem can be addressed by using _only_™️ setup.cfg (or setup.py) to specify minimal runtime deps

# this illustrates the syntax, content is irrelevant
[options]
install_requires =
    setuptools>=19.6
    matplotlib>=1.5.3; python_version < 3.0
    sympy>=1.2
    numpy>=1.10.4
    IPython>=1.0
    unyt>=2.7.2
    more_itertools>=8.4
    tqdm>=3.4.0
    toml>=0.10.2

and a "full" env could be specified as

[options.extras_require]
# again, content is irrelevant
full =
    requests>=2.20.0
    netCDF4>=1.5.3
    ...

though I admit it is not clear to me if this would still work with the most recent versions of pip.
Note that the identifier "full" is purely arbitrary.

The Cartopy Problem ™️

It seems a lot of the technical debt described above is due to the fact Cartopy isn't trivial to install for non-conda environments. However our own tests are run with conda so the setup could still be simplified (I think).

Moreover, we have this helpful comment

Getting cartopy installed requires getting cython and numpy installed
first; this is potentially going to be fixed with the inclusion of
pyproject.toml in cartopy.

and I'm glad to announce that this commit SciTools/cartopy@f6aadf8 (⚠️ not released yet) apparently solved the issue upstream, so there's room for experimentation and simplification on our side !

Issue with PEP 517 (pyproject.toml)

Our own pyproject.toml is causing some undesirable side effects lately because it specifies compile-time dependencies that are installed in isolation, so they actually ignore the runtime environment. This is problematic because compiling yt with e.g. numpy 1.20.0 while 1.19.0 is installed will create a faulty install where import yt raises an error.

I honestly don't know how to resolve this properly, the only workaround I know atm is to advise users to upgrade numpy before compiling yt (which is done here #3073).

Useful References

@neutrinoceros neutrinoceros changed the title A unique deps specification file ? Technical debt with deps specifications Feb 11, 2021
@cphyc
Copy link
Member

cphyc commented Feb 15, 2021

Thanks so much for this! I do agree we have too many ways to define our dependencies and I cannot see one that you would have missed. I'd be happy to see everything be moved to one single file (e.g. setup.cfg or setup.py). In particular, this would allow to install the dependencies using the syntax pip install yt[full], which I find quite clean.

One thing I am wondering about is how to handle compile-time dependencies? Should this stay in pyproject.toml?

@neutrinoceros
Copy link
Member Author

One thing I am wondering about is how to handle compile-time dependencies? Should this stay in pyproject.toml?

atm I don't think we can avoid this yeah, but at least the separation is quite clean and documenting this state would already reduce the amount of headache it's currently generating, I think.

@neutrinoceros
Copy link
Member Author

Another note is that I've been experimenting with this pre-commit hook (https://github.com/asottile/setup-cfg-fmt) on small projects and it is a very nice helper to maintain consistency in setup.cfg (in particular, it can auto-discover and update [options] python_requires). This provides some incentive to migrate the metadata from setup.py to setup.cfg.
The hook however is extremely long to run (several seconds on very small projects), so I'll need to further experiment with it to know if scales to the size of yt.

@neutrinoceros
Copy link
Member Author

neutrinoceros commented Feb 15, 2021

and as pointed out by @cphyc , there's a tool to automate the migration from setup.py to setup.cfg https://github.com/asottile/setup-py-upgrade

edit: it seems this can't be done because some functionalities described in our setup.py can not be translated to setup.cfg. Namely distclass, ext_modules and cmdclass. Maybe there's a way to keep them in setup.py while still migrating most of the data to setup.cfg but this looks doubtful at best.

edit again: doable after all #3078

@neutrinoceros
Copy link
Member Author

This is mostly solved with #3236 merged. There is still room for improvement but nothing really obvious atm.

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

No branches or pull requests

2 participants