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

Inherit python.pythonPath from ST's project file? #380

Open
Gabriel-p opened this issue Jan 9, 2025 · 8 comments
Open

Inherit python.pythonPath from ST's project file? #380

Gabriel-p opened this issue Jan 9, 2025 · 8 comments

Comments

@Gabriel-p
Copy link

I set my python path per project using, e.g.:

    "settings":
    {
        "python_interpreter": "/home/gabriel/miniconda3/envs/ucc/bin/python",
    },

Is there a way to have LSP-Pyright inherit this path? I just spent half a day debugging an issue only to discover that I had a different path set in LSP-Pyright's settings ("python.pythonPath")

Leaving it empty for automatic resolution does not work.

@jfcherng
Copy link
Collaborator

jfcherng commented Jan 10, 2025

Fwiw, that setting (python_interpreter) comes from the Anaconda plugin rather than ST itself.

We can add a new venv finder in https://github.com/sublimelsp/LSP-pyright/blob/master/plugin/virtual_env/venv_finder.py (to find from ST project settings' python_interpreter) if we want to support that.

My current suggestion would be https://github.com/sublimelsp/LSP-pyright#virtual-environments per project.

@Gabriel-p
Copy link
Author

Yes sorry, that was leftover from a previous project (I don't use Anaconda anymore) I'm sorry, I don't follow how I should use the instructions in the link you sent to solve this issue. I use conda environments, this is what my project file looks like:

{
	"build_systems":
	[
		{
			"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
			"name": "Conda Python Builder",
			"selector": "source.python",
			"cmd": ["/home/gabriel/miniconda3/envs/asteca/bin/python",  "-u", "$file"],
		}
	],
	"folders":
	[
		{
			"path": ".",
		},
	],
}

The ideal scenario would be a way to tell this package to access the path defined in cmd above, this way both my REPL and LSP-pyright would be using the same python version and installed packages

@jfcherng
Copy link
Collaborator

The ideal scenario would be a way to tell this package to access the path defined in cmd above, this way both my REPL and LSP-pyright would be using the same python version and installed packages

That seems to go too far imho. I will still say sublimelsp/LSP-pyright#virtual-environments

@Gabriel-p
Copy link
Author

Could you give me a small example of what I should do to use sublimelsp/LSP-pyright#virtual-environments to set up my conda environment as the default python.pythonPath?

@jfcherng
Copy link
Collaborator

jfcherng commented Jan 11, 2025

Could you give me a small example of what I should do to use sublimelsp/LSP-pyright#virtual-environments to set up my conda environment as the default python.pythonPath?

Create pyrightconfig.json on project root and pyright will auto use it. Unrelated to ST.

{
    "venvPath": "/home/gabriel/miniconda3/envs",
    "venv": "asteca"
}

@Gabriel-p
Copy link
Author

But that still requires me setting the environment in two separate places: ST's project and this JSON file. The goal was to avoid having to do this and have pyright lift the path from the project's file

@jfcherng
Copy link
Collaborator

jfcherng commented Jan 11, 2025

We can add a new venv finder in master/plugin/virtual_env/venv_finder.py

I am free to accept elegant PR(s).

@jfcherng
Copy link
Collaborator

jfcherng commented Jan 11, 2025

Imho, it makes more sense to implement a custom "build" (https://www.sublimetext.com/docs/build_systems.html#advanced-example) which auto honors .python-version, pyrightconfig.json or something else.

Though I personally hardly use ST's build system. I just invoke a terminal and do what I want with a script (usually a Makefile).

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

No branches or pull requests

2 participants