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

format on save formats stdlib code #250

Closed
DetachHead opened this issue Jun 15, 2023 · 8 comments · Fixed by #273
Closed

format on save formats stdlib code #250

DetachHead opened this issue Jun 15, 2023 · 8 comments · Fixed by #273
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug needs PR

Comments

@DetachHead
Copy link

sometimes i accidentally make changes to stdlib files (eg. [python install directory]/lib/typing.py) and typeshed files (eg. %userprofile%/.vscode/extensions/ms-python.vscode-pylance-2023.6.10/dist/typeshed-fallback/stdlib), and it's annoying when they get formatted by this extension

@github-actions github-actions bot added the triage-needed Issue is not triaged. label Jun 15, 2023
@karthiknadig
Copy link
Member

@DetachHead Can you try with the pre-release version? I recently updated the stdlib check, and this is in pre-release

@karthiknadig karthiknadig self-assigned this Jun 15, 2023
@karthiknadig karthiknadig added the info-needed Issue requires more information from poster label Jun 15, 2023
@DetachHead
Copy link
Author

it now correctly ignores stdlib files but still formats typeshed files (located in %userprofile%/.vscode/extensions/ms-python.vscode-pylance-2023.6.10/dist/typeshed-fallback/stdlib)

@pkgw
Copy link

pkgw commented Jul 12, 2023

I believe that the fix for this issue is causing a different problem. For me, this extension is now failing to format many of my files because I have installed them in development mode with pip install -e. This appears to put them in the extension's idea of what the system path is:

2023-07-11 23:14:13.878 [info] sys.path used to run Server:
   /home/peter/.vscode/extensions/ms-python.black-formatter-2023.4.1/bundled/libs
   /home/peter/.vscode/extensions/ms-python.black-formatter-2023.4.1/bundled/tool
   /a/lib/python39.zip  # <-- my default Python environment
   /a/lib/python3.9
   /a/lib/python3.9/lib-dynload
   /a/lib/python3.9/site-packages
   [...]
   /a/wwt/sw/toasty   # <-- a Git development checkout 
   /a/dasch/sw/daschdata  # <-- ditto

Which then means that the files simply don't get formatted:

2023-07-11 23:14:40.610 [info] [Warn  - 11:14:40 PM] Skipping standard library file: /a/dasch/sw/daschdata/daschdata/treecli.py

This is a severe problem for me since, by definition, the trees affected by this are the ones that I'm editing in VS Code!

@karthiknadig
Copy link
Member

karthiknadig commented Jul 12, 2023

@pkgw Can you give me the output of this for your environment?

import sysconfig 
print(sysconfig.get_paths())

@pkgw
Copy link

pkgw commented Jul 12, 2023

For my default interpreter, it's:

{
  'stdlib': '/a/lib/python3.9', 
  'platstdlib': '/a/lib/python3.9', 
  'purelib': '/a/lib/python3.9/site-packages', 
  'platlib': '/a/lib/python3.9/site-packages', 
  'include': '/a/include/python3.9', 
  'platinclude': '/a/include/python3.9', 
  'scripts': '/a/bin', 
  'data': '/a'
}

I should also mention that this problem has actually been affecting me for the past few releases; the changes introduced for this specific issue don't seem to be specifically relevant to what I'm seeing. I can file a separate issue if that would be better.

@karthiknadig
Copy link
Member

@pkgw There is a specific issue for this now: #272

@DetachHead would you be a to provide the same info for your case?

import sysconfig 
print(sysconfig.get_paths())

Basically, there are two options:

  1. [Option 1] : If there is a clear way to separate editable installs from other paths then we can use that to safely categorize stdlib vs user files. Downside, if someone really wants to format stdlib files this still blocks them. It is also possible that our guess can be wrong.
  2. [Option 2] : A (boolean) Setting to override stdlib filter entirely.

@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug needs PR and removed triage-needed Issue is not triaged. info-needed Issue requires more information from poster labels Jul 12, 2023
@karthiknadig
Copy link
Member

Can you try 2023.5.11941908 version to see if it helps?

@itsbjoern
Copy link

That did fix it for me, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug needs PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants