Skip to content

Add no_site_packages setting#8524

Merged
emmatyping merged 13 commits into
python:masterfrom
davidzwa:no-site-packages-flag
Apr 8, 2020
Merged

Add no_site_packages setting#8524
emmatyping merged 13 commits into
python:masterfrom
davidzwa:no-site-packages-flag

Conversation

@davidzwa

@davidzwa davidzwa commented Mar 11, 2020

Copy link
Copy Markdown
Contributor

Fixes #7768
Adds main.py logic for the no_site_packages flag. Tested as being subjective to CLI argument (override).

  • Add field to Options constructor
  • Add Bool key to config_parser.py
  • Adjust 2 places in main.py when checking for python executable.
  • Add test(s) in PEP 561 test file
  • Rebase onto master
  • Remove tests in testpep561.py
  • Merged new args and mypy.ini parse options for pep561.test
  • Add test to pep561.test file
  • Run test and add proper messages

Note: run test with the following command

python -m pytest -k testTypedPkg_nositepackages ./mypy

Comment thread mypy/config_parser.py Outdated
akerami added 3 commits March 12, 2020 12:20
Implementation of parts of python#6544 , namely of printing the path of the source files given to be processed by mypy. Tested using the command line as well as a configuration file.
For failing tests of python#8536
akerami added 2 commits March 18, 2020 15:34
For failing tests of python#8536.
For the last push I didn't take into account the result of the runtest file which is why 1 test case (for Travis )was failing.
Lint error fix where blank lines were missing / too many.
Comment thread mypy/test/testpep561.py Outdated
Comment thread mypy/test/testpep561.py Outdated
@emmatyping

Copy link
Copy Markdown
Member

Any idea why it's failing on importing typedpkg?

That is the point of no-site-packages, it disables mypy from searching the site-packages directory for installed packages, failing to import typedpkg is the expected result. I think you should change the expected output to be the failure to find typedpkg warning.

akerami added 2 commits March 20, 2020 13:43
For python#8536 feedback of core team leader is applied to code.
This way the source paths are ordered alphabetically which can be useful if there are many files.
@davidzwa

Copy link
Copy Markdown
Contributor Author

Not to happy with the ':4' and ':2' messages in the testpep561.py file. Thinking about formatting the message with a line number in the expected_out list. Sound good?

Comment thread mypy/test/testpep561.py Outdated
@davidzwa davidzwa force-pushed the no-site-packages-flag branch from 5f983a3 to 1fb5baa Compare April 6, 2020 12:31
@davidzwa davidzwa force-pushed the no-site-packages-flag branch from 1fb5baa to 6d012af Compare April 6, 2020 12:58
@davidzwa

davidzwa commented Apr 6, 2020

Copy link
Copy Markdown
Contributor Author

@ethanhs I added a test, but I think this is not working correctly. I tried the following variants:

  • # flags: no-site-packages
  • # mypy: no-site-packages
  • # mypy: no-site-packages=true
  • # cmd: mypy --no-site-packages

But all give the "testTypedPkg_nositepackages.py:6: note: Revealed type is 'builtins.tuple[builtins.str]'" note instead of an import error. I hope you can take over to find the solution.

[Edit]: I also tried to add [file mypy.ini] and [mypy] followed by no_site_packages=True. This broke the whole test data parsing process.

@emmatyping

emmatyping commented Apr 7, 2020

Copy link
Copy Markdown
Member

@davidzwa hm, yeah it looks like the test harness doesn't support flags like that. You can probably create a function to parse arguments and call it here and have it parse testcase.input[1] (Since the first line already handles packages). Let me know if that doesn't make sense, or I can do it myself if you wish.

EDIT: oh and the harness will also need to understand mypy.ini files. I'll fix this myself.

@emmatyping

emmatyping commented Apr 7, 2020

Copy link
Copy Markdown
Member

@davidzwa you should be able to pull my changes from the no-sp-fix branch in my repository.

You can pull the changes with something like:

$ git remote add ethanhs https://github.com/ethanhs/mypy.git
$ git fetch ethanhs
$ git merge ethanhs/no-sp-fix

Let me know if you have any problems.

@davidzwa

davidzwa commented Apr 7, 2020

Copy link
Copy Markdown
Contributor Author

Merged, tomorrow I will look at how to adapt test.
[Note]:

[file mypy.ini]
[mypy]
no_site_packages=True

This will not work. Any other way to build up the file? I just need to insert some escaped string, nothing fancy xD

@emmatyping

Copy link
Copy Markdown
Member

@davidzwa if you look at the test I added, you have to escape the [

So:

\[mypy]
no_site_packages = True

should work. Let me know if it doesn't.

@davidzwa

davidzwa commented Apr 7, 2020

Copy link
Copy Markdown
Contributor Author

I think I should learn to read more carefully, sorry for the miss. You'll find the the two tests sufficient, I'm sure of it!

@emmatyping emmatyping left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for working through this.

@emmatyping emmatyping merged commit 0bf31ca into python:master Apr 8, 2020
@davidzwa

davidzwa commented Apr 9, 2020

Copy link
Copy Markdown
Contributor Author

If you can point me to a related issue including this test-framework, that'd be awesome

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.

Expose --no-site-packages to configuration file.

3 participants