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

Add a way to set a fixed Python version for a project #621

Closed
1 task done
sdispater opened this issue Nov 13, 2018 · 10 comments
Closed
1 task done

Add a way to set a fixed Python version for a project #621

sdispater opened this issue Nov 13, 2018 · 10 comments
Assignees
Labels
area/cli Related to the command line area/init Related to 'poetry init'/project creation kind/feature Feature requests/implementations
Milestone

Comments

@sdispater
Copy link
Member

  • I have searched the issues of this repo and believe that this is not a duplicate.

Issue

Since this is an issue that has arisen before (see #522) and there is some confusion around which Python version Poetry uses, introducing a more explicit way to tell which Python version to use seems reasonable.

Before we go into more details of what it would look like, it's important to note that the default behavior (using the currently activated Python) will remain. This new feature will only make it more convenient for people to choose explicitly what they want to use.

So, with that being said, here is what a possible implementation could look like.

This requires the introduction of a new command which would accept a python executable as an argument. The argument must be a full path to a Python executable or a python command that is in the path:

poetry project use --python python
poetry project use --python python3
poetry project use --python /full/path/to/python

What this command would do is create a virtualenv like the ones currently created in the form {project_name}-py3.6, and write the association of the virtualenv and the project to a file so that Poetry knows what to use.

If the virtualenv already exists and it is not currently associated with the project, it will be associated. This makes switching between virtualenvs easier.

This will likely be implemented for the release of the first stable 1.0.0 release.

@sdispater sdispater added area/init Related to 'poetry init'/project creation area/cli Related to the command line kind/feature Feature requests/implementations labels Nov 13, 2018
@sdispater sdispater added this to the 1.0 milestone Nov 13, 2018
@sdispater sdispater self-assigned this Nov 13, 2018
@jgirardet
Copy link
Contributor

Hi,
Happy to see some evolution about it.

About adding a new command:

Poetry has already many commands so adding new ones should be considered to not make the things to complicated. Why add a new command since we already have install, run config...

Since you propose to create the virtualenv with the project use command why not use the install command which already exists ?
poetry install --python python3.6 would do the job creating and linking or just linking to an existing venv and set a flag as default venv for the project.
Same thing for the run command : poetry run --python3.6 my_command : create/link the venv, then install and run the command.

About the way of switching between env I understand the idea of a project use command but at the end, it's nothing more than : install a new venv, link it to project and make it default venv for current project : poetry install --python other_python.

About the name of the new command

If we go anyway with a new command, I think one word should be better :
not project use but only use or set ?
The project word is not consistant with rest of the api. why would we have a projet use and not project add ?

About the virtualenv name :

Should we handle the micro version ?
Should we take care of project with same name ? maybe add a hash (path of project, author of project) in the name ?

About the per-project .venv

if the python version specified is different from current, we should manage to make poetry erase the current .venv and reinstall an new one.

About the multiplication of virtualenv in cache with this new option :

maybe we should add a command 🤣
poetry clear remove the current flagged venv of the project
poetry clear --all remove all the virtualenv associated with current project

It was a bit long sorry, thanks for taking time to question our views, its cool

@sdispater
Copy link
Member Author

Since you propose to create the virtualenv with the project use command why not use the install command which already exists ?

No, because this is not the purpose of install which is only to install the dependencies.

Having a separate command makes the association of the current project with a specific Python version explicit.

About the name of the new command

Regarding the name of the command, it is not set yet and is just here to show the intended use case.

Should we handle the micro version ?

No, I don't think so. To me the minor version is the important one, not the patch version.

Should we take care of project with same name ? maybe add a hash (path of project, author of project) in the name ?

I wondered too but the cases where you have two Python projects with the same name are rare and do not warrant changing the current implementation.

About the multiplication of virtualenv in cache with this new option

This can be handled by the future env command. And now that I think about it, I think we can make the env command handle this feature (like a env use command).

@jgirardet
Copy link
Contributor

jgirardet commented Nov 13, 2018

So if I understand your mind, poetry workflow will have two entry points:
poetry install : install using current python version
poetry env use whatever-version: install using custom version

I deduce :
poetry env use /path/to/python3.6 : check if venv exists, create if needed, flag this venv in a config file for this project, then install poetry.
then
poetry env use python3.5 : does same thing for python3.5 if python3.5 is in path or fail
then
poetry env use python3.6 or shorter poetry env use 36 : switch flag to 3.6
poetry env use 37 : fail if no python3.7 env installed
poetry env use python3.4: fail if python3.4 env not installed but succeds if python3.4 is in path.

We could add poetry env list or/and poetry env use {autocompletion showsavailable venv version}

@digitalresistor
Copy link
Contributor

I wondered too but the cases where you have two Python projects with the same name are rare and do not warrant changing the current implementation.

I run into this fairly often, and have started using the venv in dir setting to mitigate this issue. It's fairly often the case when I am trying to reproduce a poetry bug with a minimal example, or even when I am working on projects for myself and for my company where the two may have the same names.

@jgirardet
Copy link
Contributor

I think this use case is not unusual :
you clone a repo : do somethings
you decide to fork it and then clone your fork
you got two project with same name.

@ryanhiebert
Copy link

I also have with some regularity wanted two different local envs of the same project. For example, if I'm playing around with different sets of dependencies for different work. I think taking the path into account somehow would be wise, probably via a hash or something. I know pipenv does something like that, though I'm not sure exactly what their algorithm is.

@ri-gilfanov
Copy link

ri-gilfanov commented Dec 6, 2018

Why not use multiple names for the launch of Poetry to specify the desired version of Python?

For example:

poetry
poetry3
poetry3.7

This is familiar to Debian, Ubuntu, and Linux Mint users. Since they are already using:

python
python3
pip
pip3

And today in last versions of Ubuntu, we can install Python 3.7 and use with command:
python3.7

Thanks.

@sdispater
Copy link
Member Author

PR #731 is ready for review :-)

@gitonthescene
Copy link

gitonthescene commented Jun 10, 2021

I seem to not be able to get it to build the write binary version of the wheel even after using poetry env use...

Notice that it's csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl. My project uses Cython.

Should I open a new issue for this?

$ poetry env info  

Virtualenv
Python:         3.7.10
Implementation: CPython
Path:           /Users/XXXX/Library/Caches/pypoetry/virtualenvs/csv-reconcile-GBl6xnkr-py3.7
Valid:          True

System
Platform: darwin
OS:       posix
Python:   /opt/local/Library/Frameworks/Python.framework/Versions/3.7
$ poetry run python --version
Python 3.7.10
$ poetry build
Building csv-reconcile (0.2.5)
  - Building sdist
  - Built csv-reconcile-0.2.5.tar.gz
  - Building wheel
running build
running build_py
running build_ext
  - Built csv_reconcile-0.2.5-cp38-cp38-macosx_11_0_x86_64.whl
$

I've installed poetry with pipx.

$ poetry --version
Poetry version 1.1.6
$ which poetry
/Users/XXXX/.local/bin/poetry
$

[EDIT:] I tracked by issue down to this line in wheel.py which seems not to exist anymore. I.e. it seems to be picking a more or less arbitrary tag for the binary name. I'm not yet sure where to find the new build files. Hopefully it tries to choose more sensibly.

    def tag(self):  # type: () -> str
        ...
        tag = next(sys_tags())
        tag = (tag.interpreter, tag.abi, tag.platform)

CC: @sdispater

Copy link

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line area/init Related to 'poetry init'/project creation kind/feature Feature requests/implementations
Projects
None yet
Development

No branches or pull requests

6 participants