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

Support for PEP 582 (Python local packages directory) #1697

Closed
ntninja opened this issue Mar 24, 2021 · 4 comments
Closed

Support for PEP 582 (Python local packages directory) #1697

ntninja opened this issue Mar 24, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@ntninja
Copy link

ntninja commented Mar 24, 2021

When using flake8 for projects managed with PDM, which implements PEP 582 (Python local packages directory), I find a large amount of errors reported for files under the local packages directory like this:

ERROR: /home/alexander/src/flake8-tabs/__pypackages__/3.9/bin/isort-3.9 Imports are incorrectly sorted and/or formatted.
--- /home/alexander/src/flake8-tabs/__pypackages__/3.9/bin/isort-3.9:before   2021-03-24 20:41:20.224279
+++ /home/alexander/src/flake8-tabs/__pypackages__/3.9/bin/isort-3.9:after 2021-03-24 21:15:49.689383
@@ -2,7 +2,10 @@
 # -*- coding: utf-8 -*-
 import re
 import sys
+
 from isort.main import main
+
+
 if __name__ == '__main__':
     sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
     sys.exit(main())

While the __pypackages__ directory is specified by the recent PEP-582, that PEP is currently draft status, so the name (and the entire feature) is guaranteed to stick around. Although PDM and PyFlow already use this convention and provide PEP-582 shims, they'd probably change if the PEP proves unworkable for some reason.

FYI, flake8 decided to close a similar request at GL/pycqa/flake8#681 noting that “we'll maybe reconsider this if [PEP-582] is accepted”.

@ntninja
Copy link
Author

ntninja commented Mar 24, 2021

For anybody finding this, workaround is to put the following into your config:

skip_glob = [
	"__pypackages__/**",
]

@timothycrosley timothycrosley added the enhancement New feature or request label Mar 24, 2021
@timothycrosley
Copy link
Member

timothycrosley commented Mar 24, 2021

I'd be very surprised if any significant number of projects legitimately want Python imports inside of a __pypackages__ directory sorted, and would be inconvenienced by a change to include it by default. I'd be happy to add this exclude by default to isort, I might suggest filing an issue with black as well as the 2 tools are often utilized together: https://github.com/psf/black/issues?q=is%3Aissue+PEP+582+is%3Aopen

@timothycrosley
Copy link
Member

This is implemented in develop and will be pushed to PyPI in the 5.9.0 release of isort

@ntninja
Copy link
Author

ntninja commented Mar 25, 2021

Thank you!

I won't submit this to black through since I don't use and dislike for “your not ready to embrace back” reasons. Somebody else will have to do that.

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

No branches or pull requests

2 participants