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

autopep8 incorrectly skips sources as standard library files #125

Closed
nputikhin opened this issue Jul 13, 2023 · 2 comments · Fixed by #126
Closed

autopep8 incorrectly skips sources as standard library files #125

nputikhin opened this issue Jul 13, 2023 · 2 comments · Fixed by #126
Assignees

Comments

@nputikhin
Copy link

Symptoms: Trying to format a source with autopep8 v2023.6.0 doesn't do anything. The code is on a Debian-based system.

Output>autopep8:

2023-07-13 12:20:40.266 [info] [Trace - 12:20:40 PM] Sending request 'textDocument/formatting - (3)'.
2023-07-13 12:20:40.268 [info] [Trace - 12:20:40 PM] Received notification 'window/logMessage'.
2023-07-13 12:20:40.268 [info] [Warn  - 12:20:40 PM] Skipping standard library file: /usr/local/home/username/code/foo.py
2023-07-13 12:20:40.269 [info] [Trace - 12:20:40 PM] Received response 'textDocument/formatting - (3)' in 2ms.

Likely culprit is #103 - _site_paths were changed to include paths from sysconfig

_site_paths = set(
str(pathlib.Path(p).resolve())
for p in (
as_list(site.getsitepackages())
+ as_list(site.getusersitepackages())
+ list(sysconfig.get_paths().values())
)
)

These paths are then used as prefixes to detect standard library files.

def is_stdlib_file(file_path: str) -> bool:
"""Return True if the file belongs to the standard library."""
normalized_path = str(pathlib.Path(file_path).resolve())
return any(normalized_path.startswith(path) for path in _site_paths)

These files are skipped here:

if utils.is_stdlib_file(document.path):
log_warning(f"Skipping standard library file: {document.path}")
return None

Output from python:

Python 3.11.4 (main, Jun  7 2023, 10:13:09) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_default_scheme()
'posix_local'
>>> sysconfig.get_paths()
{'stdlib': '/usr/lib/python3.11', 'platstdlib': '/usr/lib/python3.11', 'purelib': '/usr/local/lib/python3.11/dist-packages', 'platlib': 
'/usr/local/lib/python3.11/dist-packages', 'include': '/usr/include/python3.11', 'platinclude': '/usr/include/python3.11', 'scripts': 
'/usr/local/bin', 'data': '/usr/local'} 

'data' : '/usr/local' is a directory for data files (doc), but here it is also a base folder for the user's home folder. So the source file, which in our example is /usr/local/home/username/code/foo.py, gets skipped. I believe data shouldn't be added to _site_paths.

@karthiknadig
Copy link
Member

Can you try build 2023.7.11941910 and let me know if it works?

image

@nputikhin
Copy link
Author

Just checked, can confirm that it works now. Thanks for fixing it so quickly!

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

Successfully merging a pull request may close this issue.

2 participants