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

Create virtual env hash based on lock file instead of parent directory #2927

Closed
2 tasks done
matzhaugen opened this issue Sep 17, 2020 · 5 comments
Closed
2 tasks done
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged

Comments

@matzhaugen
Copy link

matzhaugen commented Sep 17, 2020

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

Feature Request

When building the same poetry package with the same lock file on a different machine, e.g. On different VMs in a jenkins PR build cluster, the virtual environment will hash to something different if the VM is not the same. This is because the folder parent directory is different, e.g. /home/PR123/pyproject.toml vs/ /home/PR124/pyproject.toml.

I think it would be nice to have the virtual env hash be the same in these to instances if and only if the lock file is identical.

@matzhaugen matzhaugen added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Sep 17, 2020
@abn
Copy link
Member

abn commented Sep 17, 2020

@matzhaugen I do not think this is feasible; since this would mean that everytinme the lock changes, poetry re-creates a venv. While that is okay and even preferred in a CI environment, not so much for development environments.

You should consider using poetry config virtualenvs.in-project true.

@matzhaugen
Copy link
Author

matzhaugen commented Sep 17, 2020

Thanks for the quick response. Yes that is a good point. It probably isn't feasible for development environments, but maybe if it were an optional argument? With poetry config virtualenvs.in-project true you will not have a way to label your venv and share it, unless you hash based on the lock file. How about this: When you specify poetry config virtualenvs.in-project true Instead of calling it .venv call it .venv-{hash} where hash is based on the lock file? :) That way you could share it and people would know it by the lock file hash.

However, there still wouldn't be a trivial way to share it without some other project being able to import it, even if you had the venv copied to some global directory. So I recognize that maybe this is not the right way to go about it.

@abn
Copy link
Member

abn commented Sep 17, 2020

Unfortunately, same issue. Also, I would not recommend sharing virtualenvironments unless the systems are identical in the first place. In cases like CI environments, typically you cache the venv based on <os>-<python-version>-<lock hash> if you are inclined to do so. Couldn't your ci environment do the same? As in, cache the .venv directory with the above key?

- name: Configure poetry
shell: bash
run: poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v2
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
shell: bash
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv

I am not sure if this is a large enough use case that cannot be solved elswhere. If it is, we could look at enabling some sort of option for this, virtualenvs.use-lock-hash. If we do implement something like this, this also will need to be handled by #2924 for in-project virtualenvs. Using any other name than .venv for the root directory in this scenario is something that I am not in favour for, as it is convention (eg: ignored by default gitignores etc).

@matzhaugen
Copy link
Author

matzhaugen commented Sep 17, 2020

The code you give above is actually a nice way to solve this in a CI setting. I'll just do that.

More generally, I agree that changing the .venv name would not be ideal. Another option could be to add an poetry export venv option which hashes based on what you specify above, but given your proposed solution, this is not so important for me. I'm happy to close this issue.

@finswimmer finswimmer closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2022
Copy link

github-actions bot commented Mar 1, 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 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants