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

Demo of versioned dependency install #424

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nickjalbert
Copy link
Contributor

@nickjalbert nickjalbert commented Aug 19, 2022

Draft PR to show a little demo I've put together per our "rapid prototype" discussion on discord (in case you have a few minutes during baby care).

The demo file contains imports as follows:

import infer
import arrow  # ==1.1.1
import numpy  # ==1.22.4
import regex

If you run demo.py on a clean environment, the import of the infer package will automatically install the specified versions of arrow and numpy (note these are not the default latest versions) and the latest version of regex.

Here's an example running through the demo script:

cd documentation/demos/dependency_inference/
virtualenv -p /usr/bin/python3.9 demo_env
source demo_env/bin/activate
python demo.py  # Installs missing packages numpy and arrow
pip install numpy -U  # Installs incorrect version of numpy into the virtualenv
python demo.py  # re-installs the correct version on numpy

Some things I've been thinking about as I've been playing with this:

  • I have a hypothesis that users care more about some imports than others. I think they care about imports in the files they've written and less so about internal imports (e.g. when numpy/__init__.py initializes and imports all its internal packages). Right now this demo uses (fragile) heuristics to determine whether or not the import is important. For unimportant imports (i.e. numpy internal imports) we turn off the import intercept machinery.
  • In fact, it appears numpy uses ModuleNotFoundErrors to handle some optional internal extensions. This presents a problem for a naive "install every not-found package automatically" strategy.
  • Next steps I want to work on (all have a fairly clear path, I think):
    • If the wrong version of a requirement is installed, uninstall and then reinstall
    • Rewrite a file with version annotation comments (e.g. pin unversioned imports after it is run)
    • Expand this to multi-file demos (e.g. demo.py imports other user-written code)

@nickjalbert nickjalbert requested a review from andyk August 19, 2022 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant