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

documentation request: how to follow imports within a virtualenv #117

Open
SKalt opened this issue Oct 28, 2018 · 4 comments
Open

documentation request: how to follow imports within a virtualenv #117

SKalt opened this issue Oct 28, 2018 · 4 comments

Comments

@SKalt
Copy link
Contributor

SKalt commented Oct 28, 2018

Issue Scope

  1. provide an example in the guided tour on following imports in a virtualenv
  2. clarify CLI argument documentation to show how to pass multiple directories to --search-path

The Story

I wanted to write an example of checking pip-installed imports using pyre. After reading through the documentation, I found that vanilla source activate my-venv; pyre --source-directory to/check check was not detecting packages I had pip installed in my virtualenv. Reading #64, I tried passing in a unix-style path, separated by :s. This failed with a semi-informative error message, pyre_check.exceptions.EnvironmentException: colon/separated:list/of:paths/to/search is not a valid directory. I found passing in multiple --search-paths worked:

get_path_to_check() { 
  python <<eof
import sys
from os.path import isdir
result = ' '.join(
    f'--search-path {i}' for i in sys.path
    if isdir(i) and 'site-packages' in i
)
print(result)
eof
}
pyre $(get_search_path) --source-directory to/validate check

This solution isn't 100% intuitive. The guided tour should include an example like this of working in a virtualenv to make pyre easier to adopt. Updating the --search-path SEARCH_PATH documentation from

Additional directories with modules and stubs to include in type environment

to something like

Adds an additional directory with modules and stubs to include in type
environment each time it is passed

would also clarify pyre usage.

@dark
Copy link
Contributor

dark commented Nov 5, 2018

Thanks for the report, would you like to provide pull requests to clarify the usage of --search-path and how that can be used in a virtualenv?

SKalt added a commit to SKalt/pyre-check that referenced this issue Nov 9, 2018
This change relates to facebook#117. I am to make it more explicit that `--search-path` is passed multiple times, rather than a single time with a delimited list of directories (e.g. `path/to:your/pyton:modules/and/stubs`)
@SKalt
Copy link
Contributor Author

SKalt commented Nov 9, 2018

Sure thing! Full disclosure: I'm only familiar with pipenv and conda envs. I'll see if I can set up minimal gists for pipenv and virtualenv; I've got one for conda.

Aside: looking through the code, I noticed at ./client/configuration.py#Configuration.__init__ it looks like you could ingest the sys.path that pyre is running in. Do you think that would make working with python envs simpler or introduce gotchas?

@dark
Copy link
Contributor

dark commented Nov 20, 2018

Sorry for the late reply, but this dropped from my radar somehow. I am looking at the PR, I have minor comments on that one.

As for the second point you mentioned, we might as well extend the pre-existing flag (--preserve-pythonpath) to cover sys.path as well. I'd rather not add another config flag to prevent creating a configuration hell. If you could write a PR for it, it would be great, thanks!

facebook-github-bot pushed a commit that referenced this issue Nov 22, 2018
Summary:
This change relates to #117. I am to make it more explicit that `--search-path` is passed multiple times, rather than a single time with a delimited list of directories (e.g. `path/to:your/pyton:modules/and/stubs`)
Pull Request resolved: #120

Differential Revision: D13165526

Pulled By: dark

fbshipit-source-id: 50f2201ded12788c3e98fd71f724966a483c550f
facebook-github-bot pushed a commit that referenced this issue Dec 11, 2018
Summary:
dark this is re: the comment you made in #117 about extending `--preserve-pythonpath`. When it's used, I include `sys.path` in the paths searched.  Please check the test output of  to verify the paths are as expected. With `PYTHONPATH=additional/:directories/`, it sets
```python
>>> configuration.search_path
[
  'additional/',
  'directories/',
  # vvv the contents of sys.path that are directories
  '',
   '/your/env/anaconda3/lib/python3.6',
   '/your/env/anaconda3/lib/python3.6/lib-dynload',
   '/your/env/anaconda3/lib/python3.6/site-packages',
   # ^^^
   'command/',
   'line/',
   'json/',
   'file/',
]
```

Assuming my understanding is correct and python searches `$PYTHONPATH` and then `sys.path` for packages, then this should fix #121 as well.
Pull Request resolved: #123

Differential Revision: D13413376

Pulled By: dark

fbshipit-source-id: 41de2eecb9175378e1e0d17649d60eaef5cabfcc
@omry
Copy link

omry commented Dec 25, 2019

I am having issues running inside a conda environment as well.
pyre does not find installed packages.

tests/examples/test_dataclass_example.py:3:0 Undefined import [21]: Could not find a module corresponding to import `pytest`.

Are virtual environments supported?

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

No branches or pull requests

3 participants