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

option in the vscode extension to specify the location of pyproject.toml/pyrightconfig.json #941

Open
laguill opened this issue Dec 9, 2024 · 13 comments
Labels
config issues relating to config (pyproject.toml, pyrightconfig.json, LSP config or vscode extension) language server vscode the extension for vscode/vscodium

Comments

@laguill
Copy link

laguill commented Dec 9, 2024

Hello,

I am using basedpyright in vscode and basedpyright is installed in my pixi environmment.
I would like to configure basedpyright to not check for Any type.

It seams there is something wrong with my config because basepyright is still returning error Type Any is not allowed

[tool.pyright]
typeCheckingMode = "recommended"
reportAny = "none"
reportExplicitAny = "none"
@DetachHead
Copy link
Owner

that should work. could you provide some more info please:

  • which editor are you using? or are you using the CLI?
  • which version of basedpyright are you using?
  • how did you install basedpyright?

@DetachHead DetachHead added config issues relating to config (pyproject.toml, pyrightconfig.json, LSP config or vscode extension) awaiting response waiting for more info from the author - will eventually close if they don't respond labels Dec 9, 2024
@laguill
Copy link
Author

laguill commented Dec 9, 2024

Yes sorry

  • editor: vscode
  • os : xubuntu
  • basedpyright: 1.22.1
  • installed from conda-forge: pixi add basedpyright
  • I have the basedpyright extension installed

Here is the code with errors

from pathlib import Path
from typing import Any

import pandas as pd


dataset_folder: Path = Path("data/Dataset_Edstats_csv/")
csv_files: list[Path] = list(dataset_folder.glob("*.csv"))
print(f"Fichiers CSV trouvés : {[file.name for file in csv_files]}")

dfs: dict[str, pd.DataFrame] = {file.stem: pd.read_csv(file) for file in csv_files}

# Liste pour stocker les informations de chaque dataframe
summary_data: list[dict[str, Any]] = []
for name, df in dfs.items():
    summary_data.append({
        "Fichier": name,
        "Dimensions": df.shape,
        "Noms colonnes": df.columns.tolist(),
        "Types de données": df.dtypes,
    })

@laguill
Copy link
Author

laguill commented Dec 9, 2024

Everything is fine when using basedpyright myfile.py but not is vscode

@DetachHead
Copy link
Owner

can you send the log from basedpyright in the vscode output tab please:

image

there should be an entry that says something like "Loading pyproject.toml file at path/to/pyproject.toml"

@laguill
Copy link
Author

laguill commented Dec 9, 2024

Here is the output
The pyproject.toml file is in P2*/pyproject.toml
But vscode working folder is P2*/quarto_project

[Info  - 14:18:27] basedpyright language server 1.1.390 starting
[Info  - 14:18:27] Server root directory: file:///home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/.pixi/envs/default/lib/python3.13/site-packages/basedpyright/dist
[Info  - 14:18:27] Starting service instance "quarto_project"
Received pythonPath from Python extension: /home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/.pixi/envs/default/bin/python
[Info  - 14:18:29] Setting pythonPath for service "quarto_project": "/home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/.pixi/envs/default/bin/python"
[Info  - 14:18:29] No include entries specified; assuming /home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/quarto_project
[Info  - 14:18:29] Auto-excluding **/node_modules
[Info  - 14:18:29] Auto-excluding **/__pycache__
[Info  - 14:18:29] Auto-excluding **/.*
[Info  - 14:18:29] Assuming Python version 3.13.1.final.0
[Info  - 14:18:29] Found 1 source file
[Info  - 14:18:29] Background analysis(1) root directory: file:///home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/.pixi/envs/default/lib/python3.13/site-packages/basedpyright/dist
[Info  - 14:18:29] Background analysis(1) started
[Info  - 14:18:34] [BG(1)] Long operation: checking: file:///home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/quarto_project/test.py (4257ms)
[Info  - 14:18:34] [BG(1)] Long operation: analyzing: file:///home/laguill/Documents/01-Etudes/OpenClassrooms/P2_Analysez-donnees-systemes-educatifs/quarto_project/test.py (5894ms)

@DetachHead
Copy link
Owner

the pyproject.toml file will only be read if it's in the root of your project. are you trying to re-use settings across multiple projects? if so, perhaps configuring basedpyright using the language server settings may be better for your use case

@laguill
Copy link
Author

laguill commented Dec 9, 2024

No no
Here is my project structure

My project dependencies are defined also in pyproject.toml
The jupyter extension do not have issue to detect the environment
Is it possible that basedpyright extension is not searching in the root directory for my pyproject.toml ?

tree
.
├── .gitattributes
├── .gitignore
├── .mypy_cache
│   ├── 3.13
│   ├── CACHEDIR.TAG
│   └── .gitignore
├── .pixi
│   ├── envs
│   └── .gitignore
├── pixi.lock
├── pyproject.toml
├── quarto_project
│   ├── data
│   ├── Décrivez+et+nettoyez+votre+jeu+de+données
│   ├── edProfile.html
│   ├── index.qmd
│   ├── .mypy_cache
│   ├── Numpy.qmd
│   ├── _output
│   ├── Pandas.qmd
│   ├── .quarto
│   ├── _quarto.yml
│   ├── style.css
│   ├── test.py
│   └── .vscode
├── .ruff_cache
│   ├── 0.8.1
│   ├── CACHEDIR.TAG
│   └── .gitignore
└── src
    └── p2_analysez_donnees_systemes_educatifs

@DetachHead DetachHead added needs investigation awaiting verification by a maintainer that the issue is valid and removed awaiting response waiting for more info from the author - will eventually close if they don't respond labels Dec 9, 2024
@DetachHead
Copy link
Owner

thanks for the info, will investigate this further

@DetachHead DetachHead changed the title Configure basedpyright vscode extension ignores pyproject.toml workspace is a subfolder of the project root Dec 9, 2024
@DetachHead
Copy link
Owner

this functionality appears to be intentional:

// In a project-based IDE like VS Code, we should assume that the
// project root directory contains the config file.
configFilePath = findConfigFile(this.fs, projectRoot);
// If pyright is being executed from the command line, the working
// directory may be deep within a project, and we need to walk up the
// directory hierarchy to find the project root.
if (!configFilePath && !commandLineOptions.fromLanguageServer) {
configFilePath = findConfigFileHereOrUp(this.fs, projectRoot);
}

we can probably add an option to the language server to specify the path to the config file, like the --project cli option

@DetachHead DetachHead added language server vscode the extension for vscode/vscodium and removed needs investigation awaiting verification by a maintainer that the issue is valid labels Dec 10, 2024
@DetachHead DetachHead changed the title vscode extension ignores pyproject.toml workspace is a subfolder of the project root vscode extension ignores pyproject.toml when workspace is a subfolder of the project root Dec 25, 2024
@Tragio
Copy link

Tragio commented Jan 5, 2025

Hi @DetachHead 👋

Thank you very much for your work. 🚀

I have my project root folder, where I have several folders, and inside the app/ is where I have the pyproject.toml and all the Django stuff, in result is: app/pyproject.toml.

When I cd app/ and run basedpyright . it works just fine, but in VSCode I see that nothing I do in my pyproject.toml has any effect on IDE. 🤔

@DetachHead DetachHead changed the title vscode extension ignores pyproject.toml when workspace is a subfolder of the project root option in the vscode extension to specify the location of pyproject.toml/pyrightconfig.json Jan 7, 2025
@DetachHead
Copy link
Owner

@laguill would you mind elaborating on your use case for only opening a subfolder of your project in vscode instead of the whole repo? @Tragio's situation where pyproject.toml is located in a subfolder of the project sounds like it would be more common, for example in a monorepo (#384 is sorta related)

i will probably just add an option in the extension settings where you can specify the path to pyproject.toml/pyrightconfig.json but i'm just curious about the use cases

@laguill
Copy link
Author

laguill commented Jan 8, 2025

I usually open vscode from the terminal in a subfolder of my project after activating my environment.

@DetachHead
Copy link
Owner

personally i always open the project in vscode because i have vscode configured to automatically activate the environment for me:

// .vscode/settings.json
{
    "python.terminal.activateEnvInCurrentTerminal": true
}

it also makes it easier for me to browse other parts of my project because everything's available from within vscode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config issues relating to config (pyproject.toml, pyrightconfig.json, LSP config or vscode extension) language server vscode the extension for vscode/vscodium
Projects
None yet
Development

No branches or pull requests

3 participants