-
Notifications
You must be signed in to change notification settings - Fork 56
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
Ruff doesn't work with virtual environment #351
Comments
That's strange! What do you see as the output of: import site
print(site.getsitepackages())
print(site.getusersitepackages()) |
@charliermarsh hi Charlie, This is the input from
This is the input from
Thank you |
You should not place any project code in the virtual environment directory. |
@CrystalWindSnake hi Crystal, I used virtualenv, so the virtual environment directory is inside the project code, not the the other way around. At least that's how I interpret venv should be - different environments for different projects. Thank you. |
@CrystalWindSnake Sometimes it is unavoidable. I have just installed this extension, and have had the same problem (with Anaconda). This hack resolves the problem, but please add it as a check-box in the configuration settings. # file on my hdd: C:\Users\xxx\.vscode\extensions\charliermarsh.ruff-2024.2.0-win32-x64\bundled\libs\ruff_lsp\server.py
# Hack 1:
# Comment out:
if document.is_stdlib_file():
log_warning(f"Skipping standard library file: {document.path}")
return None
# updated code should look like:
async def _run_format_on_document(document: Document) -> ExecutableResult | None:
"""Runs the Ruff `format` subcommand on the given document source."""
# if document.is_stdlib_file():
# log_warning(f"Skipping standard library file: {document.path}")
# return None
async def _run_check_on_document(
document: Document,
*,
extra_args: Sequence[str] = [],
only: Sequence[str] | None = None,
) -> ExecutableResult | None:
"""Runs the Ruff `check` subcommand on the given document source."""
# if document.is_stdlib_file():
# log_warning(f"Skipping standard library file: {document.path}")
# return None
# Hack 2 (not tested):
def is_stdlib_file(self) -> bool:
"""Return True if the document belongs to standard library."""
return False # add this line
return utils.is_stdlib_file(self.path) # ignored now (could be deleted) |
@karthiknadig -- Have you seen this with any of the other extensions? |
@charliermarsh I can confirm that ms-pylint has the same issue with virtual environment. This was the reason I looked into ruff. |
I'm moving from PyCharm to VsCode, and this was the first linter that worked in my Anaconda envs (with the hack though). By the way: It seems like doing a great job. Thank you for the great work! |
How is the project structured. This is what we expect:
can you share your project structure? |
Thank you so much :) Right now I'm leaning towards adding a setting to allow folks to opt-out of this behavior. |
@hansalemaos I tried your workaround (hack 1), and I am getting some crashes.
Not sure what I did wrong. Tried restarting VSCode/ruff a few times and the same result. |
@karthiknadig I guess that you are asking @Vinci08, right? I am using anaconda. |
I am using 1+2 combined now, and it is working. But it seems like, there will be a patch soon according to: @charliermarsh This is the first and only code so far that I have used to test it import pandas as pd
import numpy as np # working here
from PrettyColorPrinter import add_printer
def bsbsbs(x=4, y=22):
return x**x**y **zz # working here
kj;j # working here
add_printer(1)
df = pd.read_csv("C:\Users\xxx\Downloads\titanic.txt") # working here Some things that I should add:
|
@karthiknadig I usually create new project folder (let's call it project_dir), then run
I put Lib and Script folder .gitignore, so the only thing makes it to source control is requirements.txt. |
That structure is not recommended. Please follow the one I posted. Soon You can also use |
Drinking beer is also not recommended, but a lot of people drink. :) Don't you think there is a way to add a little checkbox in the settings to disable this behaviour. I would help those outlaws out there :) |
I am somewhat tempted to remove this check altogether and put the onus on Ruff and the user's Ruff configuration to filter out these kinds of things. |
Awesome!!! |
## Summary Users can now specify `"ruff.ignoreStandardLIbrary": false` to turn off the standard library detection. Closes #351.
Setting (to opt-out) will go out in the next release (tomorrow, I gotta sleep and would prefer not to release and leave in case there are issues). |
Hello, I am having trouble get ruff to lint files inside a python virtual environment. The issue here is I kept getting warnings like this
Skipping standard library file: c:\Users\Leo\Desktop\someproject\api\_views\reports.py
here is my settings.json for ruff
Please give me some guidance on how to fix this issue. Thank you
The text was updated successfully, but these errors were encountered: