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

Relative cache-dir breaks the new installer #3049

Closed
3 tasks done
matejcik opened this issue Oct 2, 2020 · 10 comments
Closed
3 tasks done

Relative cache-dir breaks the new installer #3049

matejcik opened this issue Oct 2, 2020 · 10 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@matejcik
Copy link

matejcik commented Oct 2, 2020

  • I am on the latest Poetry version.

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

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: Linux Mint 20, Python 3.8.2

  • Poetry version: 1.1.0, master

  • Link of a Gist with the contents of your pyproject.toml file: https://gist.github.com/matejcik/f7b0d6ca9bea9e6613f7a99433d7ad65

Issue

When cache-dir is set to a relative path (in poetry.toml), bad things happen.

To reproduce:

  1. place contents of above gist into a directory
  2. poetry install
  3. rm -r .venv
  4. poetry install again

Expected result: this should work fine

Actual result: a spectacularly unhelpful stack trace with the following error: ValueError: relative path can't be expressed as a file URI

after modifying something or other, the actual stack trace shows up:

ValueError: relative path can't be expressed as a file URI
Traceback (most recent call last):
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/executor.py", line 180, in _execute_operation
    result = self._do_execute_operation(operation)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/executor.py", line 255, in _do_execute_operation
    result = getattr(self, "_execute_{}".format(method))(operation)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/executor.py", line 390, in _execute_install
    return self._install(operation)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/executor.py", line 416, in _install
    archive = self._download(operation)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/executor.py", line 559, in _download
    return self._download_link(operation, link)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/executor.py", line 564, in _download_link
    archive = self._chef.get_cached_archive_for_link(link)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/chef.py", line 49, in get_cached_archive_for_link
    archives = self.get_cached_archives_for_link(link)
  File "/home/matejcik/.local/lib/python3.8/site-packages/poetry/installation/chef.py", line 84, in get_cached_archives_for_link
    links.append(Link(archive.as_uri()))

Far as I could tell, archive above is a relative path starting with .cache, which can't be converted to an URI.

After changing the line in chef.py to:

links.append(Link(archive.resolve().as_uri())

the issue goes away. I'm not sure if that is even the right place to fix it, but if yes, I'll send a PR.

@matejcik matejcik added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 2, 2020
@abn
Copy link
Member

abn commented Oct 2, 2020

That should fix the specific issue.

An additional fix may be to resolve the cache-dir value when it is loaded in. However, not sure if there would be any unintentional side-effects in doing so.

@ericriff
Copy link

ericriff commented Oct 8, 2020

Just came across this myself, on poetry version 1.1.2, but only if I'm using python 3.7. With 3.6 and 3.5 it works as expected.
Also links.append(Link(archive.resolve().as_uri()) worked for me.

@ericriff
Copy link

ericriff commented Oct 9, 2020

Are you guys going to open a PR for this?
I don't know how the internals of Poetry work, but if it is just that line I don't mind changing it.
I would hate to steal the credit, but it blocking some of my work since I can't move past python 3.6 if I'm using relative paths on the cache.

By the way, I'm using the relative paths as a workaround to in-project only allowing you to have ONE environment per project. I just moved the whole cache inside my project (since we need it to be self contained) and now I can have all the environments I want (I only care about different python versions) inside my project folder.
I'm not sure if there is a better way to do this.

@rvorias
Copy link

rvorias commented Jan 12, 2021

I accidentally removed the _build/ contents. After restoring them, poetry couldn't be installed due to this error.

Solved it by removing _build/ and .venv/ and ran poetry install which uses the .lock. Seems to be fixed now.

@prusnak
Copy link

prusnak commented Jan 14, 2021

I was just with the same issue today

@pawamoy
Copy link

pawamoy commented Mar 12, 2021

Same thing in CI when setting cache directory with a relative path: https://github.com/pawamoy/duty/runs/2098788727?check_suite_focus=true

@ericriff
Copy link

ericriff commented Mar 12, 2021

I would love to have a way to make it relative to pyproject.toml.

@pawamoy
Copy link

pawamoy commented Mar 12, 2021

Here's how I worked around this in CI:

env:
  # To fix an error when running Poetry on Windows
  # (https://github.com/python-poetry/poetry/issues/2629),
  # we set Poetry's cache directory to .poetry_cache in the current directory.
  # It makes it easier to later remove the virtualenv when it's broken.
  # Absolute path is necessary to avoid this issue:
  # https://github.com/python-poetry/poetry/issues/3049
  POETRY_CACHE_DIR: ${{ github.workspace }}/.poetry_cache

Damn it's hard to make things work on Windows.

@neersighted neersighted changed the title problem when cache-dir is relative Relative cache-dir breaks the new installer Oct 4, 2022
@finswimmer
Copy link
Member

Closing this, because I cannot reproduce this anymore.

Feel free to leave a comment if you disagree.

Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants