mmshivesh / Python-Nova.novaextension

Python Extension for Panic's Nova editor for macOS
https://extensions.panic.com/extensions/works.creativecode/works.creativecode.python-nova/
22 stars 6 forks source link

Usage with a virtual environment #5

Closed FlippAre closed 3 years ago

FlippAre commented 4 years ago

I prefer to use a local venv in my project folder. What would be the recommended way to configure the extension to use the local venv for autocompletes?

I have noticed some extensions have project unique settings like:

Screenshot 2020-10-29 at 21 53 37

Might adding support for something like that be a viable way to use a local venv, or is there a simple solution already in place that I might be missing? I have looked a little bit on the Jedi configuration, but haven't been able to find anything useful so far.

Thank you for a very nice extension!

FlippAre commented 4 years ago

Setting an absolute path as the Jedi Environment seems to solve my problem, albeit being quite impractical if you are working with many project ;)

mwidjaja1 commented 4 years ago

I'd like to also request this too. I use Conda Environments and being able to set the interpreter for each workspace would be ideal.

mwidjaja1 commented 4 years ago

I didn't try this but looking at the Extension Docs, I think one way this could be implemented is in extension.json, adding this to the file:

"configWorkspace": [
        {   
            "title": "Workspace Options",
            "description": "PyLS configuration options for this workspace",
            "type": "section",
            "key": "works.creativecode.pyls.optionsSec",
            "children": [
                {
                    "key":"pyls.executable",
                    "title": "Workspace Executable Path",
                    "type": "path",
                    "placeholder": "/usr/local/bin/pyls",
                    "description": "Language server executable for the given workspace (Will use the system settings otherwise)"
                }
             ]
        }
]

And then in line 47 of main.js, add an if statement to use the workspace path first if available. I'm not a Javascript expert so I'm not sure what that portion would look like.

Of course, this'll also let each environment/workspace has its own pyls executable but it seems like a meaningful step forward. Can't immediately imagine why one would want different pylint/pyflakes version across workspaces.. famous last words.

Hope this helps!

mmshivesh commented 4 years ago

Great, that seems like a solid lead. Thanks 👍

FlippAre commented 4 years ago

Looks good, albeit it isn't the path to pyls executable that at least I would like to set as a project setting. I have installed pyls globally and that works just fine. What I think should be a project setting is be able to set your Python executable, so Jedi et. al finds my local dependencies and give me autocomplete. Setting a Jedi Environment seems to solve this

mmshivesh commented 4 years ago

Since Jedi seems to already work with virtual environments out of the box, an override for the Jedi environment seems like a much better option.

Do you have a screenshot of what configuration works with Jedi Environments?

mmshivesh commented 4 years ago

I pushed v1.0.3 (303681d) that should add support for overriding Jedi environment at the workspace level. If this fixes the issue, kindly let me know and i'll close this issue.

mwidjaja1 commented 4 years ago

So I'm a Jedi noob so this may be a stupid question, but I don't see how Jedi supports virtual environments -- I don't see it in Jedi's documentation (jedi.readthedocs.io). How would I set that up (might be a @FlippAre question)?

FlippAre commented 4 years ago

@mwidjaja1 I simply pointed Jedi Environment to the Python bin in my local venv, like:

Screenshot 2020-11-02 at 22 18 21

This above is given i have my project pylip and in it a virtual environment named .venv

@mmshivesh I think I might be seeing some issues with the override feature. Please see this log:

Python[22:14:07.773000] pyls.executable: /Users/filip/.local/bin/pyls

Python[22:14:07.773000] pyls.enableLogging: null is null. Returning false

Python[22:14:08.063000] pyls.configurationSources: pycodestyle

Python[22:14:08.063000] pyls.rope.extensionModules: null is null. Returning undefined

Python[22:14:08.063000] pyls.rope.ropeFolder: null is null. Returning undefined

Python[22:14:08.063000] pyls.plugins.jedi.enabled: true

Python[22:14:08.063000] pyls.plugins.jedi.extra_paths: null is null. Returning undefined

Python[22:14:08.064000] pyls.plugins.jedi.env_vars: null is null. Returning undefined

Python[22:14:08.064000] pyls.plugins.jedi.workspace.environment: null is null. Returning undefined

Python[22:14:08.064000] Workspace Jedi environment undefined. Using global value

Python[22:14:08.064000] pyls.plugins.jedi.environment: /Volumes/Macintosh HD/Users/filip/Source/Lime/Misc/pylip/.venv/bin/python

Python[22:14:08.064000] pyls.plugins.jedi_completion.enabled: true

This with a locally set project override as:

image
mmshivesh commented 4 years ago

Python[22:14:08.064000] Workspace Jedi environment undefined. Using global value

It seems like the workspace preference is not being picked up. I'll take a quick look at this.

mmshivesh commented 4 years ago

@FlippAre I have pushed a commit which should fix the override. Workspace specific settings are read from nova.workspace.config instead of nova.config. I had missed this previously.

If you could try the latest commit (081efe5) and let me know, i'll close this issue and push this build to the extension library. This should also add automatic reload when you change preferences.

FlippAre commented 4 years ago

@mmshivesh Amazing! Will give it a try! I haven't looked into running extensions from source yet, but will do and get back to you.

mmshivesh commented 4 years ago

Installation is straightforward, Nova automatically recognizes .novaextension folder and offers to install the extension when you double click. (Nova treats folders with .novaextension just like how macOS treats .bundle folders).

FlippAre commented 4 years ago

Super convenient! I did clone the repo and activated the extension via Novas Extension developer menu and then opened a new window with my project in. I notised a somewhat related, yet unrelated issue though. Nova gave me errors about the Language server already connected.

I guess this is related to: https://github.com/mmshivesh/Python-Nova.novaextension/blob/081efe52b9e31f00dd701d31db711863da1adabd/Scripts/main.js#L307

As you always create a client named PyLS. I would suggest adding the projects name or maybe path, so a unique client is created

mmshivesh commented 4 years ago

Oh wait, i think the manual installation is conflicting with the version from the extension store. You can disable it for now (just uncheck the box. There's no need to uninstall the version from the store).

FlippAre commented 4 years ago

Still seeing a issue, albeit a different one ;)

Python[11:43:30.208000] pyls.plugins.jedi.workspace.environment: /Volumes/Macintosh HD/Users/filip/Source/Lime/Misc/pylip/.venv/bin/python

Python[11:43:30.208000] Jedi environment overriden at Workspace. Using workspace value instead.

Python[11:43:30.209000] pyls.plugins.jedi.workspace.environment: null is null. Returning undefined
mmshivesh commented 4 years ago

Yeah, I overlooked a simple line in the preference parsing:

https://github.com/mmshivesh/Python-Nova.novaextension/blob/081efe52b9e31f00dd701d31db711863da1adabd/Scripts/main.js#L86

when it should have been:

https://github.com/mmshivesh/Python-Nova.novaextension/blob/3ac217deb439e47e21eff956038b1febc5f19760/Scripts/main.js#L86

(this reads from the workspace preferences)

I've pushed a commit with the fix. Hopefully this fixes this issue 😄

johnsturgeon commented 3 years ago

I just grabbed this version (1.1.0) of the extension, and set the Workspace Jedi Environment Path in the project settings to my virtual env's python: /Users/john/Code/venvs/myvenv/bin/python but when I load Nova I get the message:

Python[17:54:27.690000] pyls.executable: null is null. Returning /usr/local/bin/pyls
Python[17:54:27.691000] pyls.enableLogging: true
Python[17:54:27.691000] pyls.logPath: null is null. Returning /tmp/pyls.log
mmshivesh commented 3 years ago

Yeah those are fine. It's just debug messages that are being logged:

The following line reads the default executable path: Python[17:54:27.690000] pyls.executable: null is null. Returning /usr/local/bin/pyls

and this reads the default log path: Python[17:54:27.691000] pyls.logPath: null is null. Returning /tmp/pyls.log

@johnsturgeon Could you attach what the logs say for pyls.plugins.jedi.workspace.environment? That should determine if the workspace paths are being loaded

johnsturgeon commented 3 years ago

OK, the workspace seems to be correct. Thx

mmshivesh commented 3 years ago

Great! I'm closing this issue. Feel free to reopen it.

tommasongr commented 3 years ago

Hi there! I little follow up. First of all thanks for this amazing extension!

I'm looking at Python and Django for the first time and I was trying to set up the dev environment. I installed python 3.9 with pyenv and then installed django through pipenv.

I configured pyls for using the the correct python version but I'm not able to get django completions working...

I tried to specify the pipenv environment but I'm not totally sure if I was supposed to do so or not.

Schermata 2021-02-06 alle 23 41 43

Can somebody help me?

Sorry for the beginner question ahah Thanks a lot

thirdjal commented 3 years ago

I'm not sure how to configure the workspace override.

I've have the workspace path configured in my project, like so:

Screen Shot 2021-03-01 at 4 12 05 PM

But the configuration doesn't appear to be taking. I get the following error in the log: pyls.plugins.jedi.workspace.environment: null is null. Returning undefined

dbux commented 3 years ago

I'm also unclear on how to get autocomplete working for virtual environments. I'm using the current version of the extension from this repo, I've entered my venv path in the workspace environment path options, the jedi package is installed, but nothing I do will persuade Nova to autocomplete commands from packages installed in the venv. Am I missing something obvious?

image

The workspace paths appear to be loaded properly: pyls.plugins.jedi.workspace.environment: /Users/dbux/Documents/test_venv