help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use project.el


From: Dmitry Gutov
Subject: Re: How to use project.el
Date: Wed, 25 Nov 2020 03:54:17 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 24.11.2020 05:54, excalamus--- via Users list for the GNU Emacs text editor wrote:

23 nov. 2020 à 17:19 de dgutov@yandex.ru:

On 23.11.2020 18:22, excalamus--- via Users list for the GNU Emacs text editor 
wrote:


21 nov. 2020 à 21:55 de dgutov@yandex.ru:

  For instance, if you are working on a Python project, shouldn't there be some 
file in the project root directory which will indicate which virtualenv to use?

Maybe? I've never heard of such a file being used with the venv module or conda 
environments.


OK, I'm not well-versed in Python ecosystem

I sadly am (it's my day job). "Should" is a dangerous assumption for Python. As far as 
I'm aware there's no unit of project nor standard way to indicate which environment to use or what 
packages are in that environment. Some people put a bajillion packages into a giant catch all 
environment to "reduce duplication", others have a 1:1 project to virtual environment 
relationship.
In practice, a project and virtual environment are separate, although each are 
determined by a directory (maybe the virtual environment is a subdirectory of 
the project directory; maybe virtual environments are all co-located in a 
separate envs/ directory). The user has to remember which virtual environment 
to activate and where that environment is located.

pyenv seems to be one such standard. Though of course it might not be adopted by the projects you use (especially if they are collaborative, and you don't make that decision).

The virtual environment is activated by running some script which sets 
environment variables for the current shell instance.
I think the general idea could be implemented in Emacs Lisp: you call 
(project-root (project-current)) and see if there is a file with a 
predetermined name inside that root. That file could point to a specific 
virtualenv which you would then switch to.

I could create my own project indicator file, I suppose.  I'm not sure how that 
would help.  But I'm getting (myself) lost. I may be stuck in my own pattern of 
solving things. What problem are we trying to solve here?

My project workflow is:
1. Create a shell2. Activate a virtual environment
3. Assign some commonly used commands based on the project (e.g. run this entry 
point, build according to this spec, etc.)
The trouble is managing several of these simultaneously (e.g. "Hey can you quickly 
fix this thing in this other project?") while maintaining the state of each.

You asked how to maintain a number of "profiles" corresponding to projects, each containing a venv, entry point, and so on.

My response is that in my preferred paradigm most or all of that information is inferred from the files that reside in the project's root directory. So to get some of that info you first find the project root, and then read that info from disk. You can subsequently cache it, of course.

But if there is no existing standard for most of those things in your projects, you might as well write some registry in Lisp, in your init script, that would map, say, project roots to such profiles.

The benefit of having those auto-determined is that you could always have them up-to-date and correspond to the current file you have opened in Emacs (the current buffer). And when you switch to another project, with project-switch-project or even the plain find-file, your profile-finding logic would use the correct profile automatically, without you having to recall which profile corresponds to which project.

But that's how I prefer to approach this kind of problem. You might choose to do it differently.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]