python-poetry/poetry

Add ability to configure ephemeral environment location

riptusk331 opened this issue · 6 comments

Issue Kind

Change in current behaviour

Description

It's my understanding that poetry will create temporary/ephemeral environments in order to build certain packages from source. These ephemeral environments are created here in a function that creates a temporary directory (based on the user's system). As far as I can see, that temporary directory is not configurable and ends up in the %TEMP% directory. I'm proposing that it can be.

I would be happy to work on implementing this, assuming of course I am not missing a way to already do this, or I am just misusing/misunderstanding poetry and this design choice. Thanks.

Impact

I stumbled upon this because I use poetry in a corporate environment which restricts running applications outside of a dedicated C:/Dev folder. When the ephemeral environment tries to run python, it would lock up on my machine as it was an "unauthorized" application running outside of C:/Dev.

Workarounds

The issue can be worked around by overriding the %TEMP% environment variable prior to invoking poetry, i.e. $env:TEMP="C:\Dev\Temp"; poetry install

I set the various POETRY_HOME, POETRY_VIRTUALENVS_PATH, POETRY_CACHE_DIR and a few other environment variable settings with no success.

setting the TEMP environment variable (or TMP or TMPDIR) is how to configure the directory used for temporary files. By setting that, you configure this and hence solve your problem for all programs - not only for poetry.

Does poetry really need its own separate configuration for this?

Thank you, David. I agree that setting TEMP resolves my immediate issue.

Does poetry really need its own separate configuration for this?

Poetry gives users the ability to configure various directories it uses for its operations (cache, config, home, virtualenv, etc...), so I did not think it was that big an ask. Sure, I can override TEMP each time I invoke poetry or create an alias and it works, but it would be nice if I didn't have to. If you don't think it deserves a separate configuration, then I would suggest documenting this behavior better (I'm happy to help) so that future users with similar usage context as me understand their options.

The reason for my post is that it's not immediately obvious that poetry is creating temporary environments in TEMP when it's building/installing packages -- it's certainly not documented, and I had to pore through the code to figure out what it was doing.

I definitely think that it does not make sense for individual programs to reimplement standard OS facilities, each no doubt in slightly different ways.

By way of comparison, here is pip rejecting something similar some years ago, and for much the same reason pypa/pip#4462 (there are other similar issues in that repository)

However it will take someone with more power - or you - to close this issue, I cannot do it.

If you want to contribute documentation then that is generally welcome though in this case I think a little tricky. This behaviour does not really belong to poetry - it is more like "poetry respects standard environment variables so you can use them if you want to".

Of course it does not help you much if you do not know about them, but it is not really on poetry to be the one to document standard things.

Your feedback is fair, David, and I will close the issue.

Before I do, since we are having a discussion, I have a question regarding documenting - I'm quite aware of what TEMP is and that it's a standard OS facility that any application can use. I'm less familiar with what you mean by "this behavior does not really belong to poetry"? Poetry's code is choosing to build ephemeral environments in TEMP for package installations. Isn't that a design choice that users should be aware of? I was less saying "document that poetry uses TEMP" and more saying "document that it uses TEMP to perform X, Y, and Z."

I am genuinely asking -- I do not work on build systems for a living or in my spare time, so if you are saying very resolutely "yes, it's normal to build temp environments there and everyone knows that", I will go away. I wanted to ask the question though, if at the very least for my own education and folks that might Google this. Thanks.

what you mean by "this behavior does not really belong to poetry"?

I mean only that respecting environment variables such as TMPDIR is not poetry-specific behaviour.

eg poetry does this not through any explicit implementation but simply because python tempfile does the expected thing.

But it is not python-specific behaviour either eg I expect that mktemp respects TMPDIR, and similar in other programming languages and applications

I assume that whatever error you saw - you never said - would have been something along the lines of not having permission in /tmp (or whatever the windows equivalent is). Recognising that what is obvious to one may not be so to another, but I would think at that point it should be reasonably clear that poetry was trying to use a temporary directory.