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

Poetry 1.8 change regarding virtualenvs behaviour (failing ReadTheDocs builds) #9025

Closed
4 tasks done
ewjoachim opened this issue Feb 25, 2024 · 6 comments
Closed
4 tasks done
Labels
kind/question User questions (candidates for conversion to discussion)

Comments

@ewjoachim
Copy link

ewjoachim commented Feb 25, 2024

  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

This issue relates to a problem with Poetry and ReadTheDocs (RTD).
The official RTD integration doc advocates for running the following commands:

$ pip install poetry
$ poetry config virtualenvs.create false
$ poetry install --with docs

In the environment this runs in, there is a virtualenv created with python -mvirtualenv $READTHEDOCS_VIRTUALENV_PATH and $READTHEDOCS_VIRTUALENV_PATH/bin is added in the PATH as the first element, though VIRTUAL_ENV is not set.

  • In 1.7, poetry install added packages to the $READTHEDOCS_VIRTUALENV_PATH venv.
  • In 1.8, packages are added to the underlying Python env, not in the virtualenv.

Consequently, packages added this way are not seen by subsequent steps, and the builds fail.

See Discord discussion at https://discord.com/channels/487711540787675139/487711540787675143/1211368925158183004

See RTD corresponding issue: readthedocs/readthedocs.org#11150

@ewjoachim ewjoachim added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 25, 2024
@ewjoachim ewjoachim changed the title Poetry 1.8 change regarding virtualenvs.create behaviour (failing ReadTheDocs builds) Poetry 1.8 change regarding virtualenvs behaviour (failing ReadTheDocs builds) Feb 25, 2024
@dimbleby
Copy link
Contributor

sounds like you have been relying on a bug

poetry config virtualenvs.create false

recommend not doing that.

Seems like you already have a virtual environment: activate it properly - including setting the environment variable - so that poetry can detect it

@abn
Copy link
Member

abn commented Feb 25, 2024

As discussed on discord, I suspect the correct fix here is to activate the virtual environment correctly within the build environment as @dimbleby mentioned.

In particular, replace this.

poetry config virtualenvs.create false

With the following.

export VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH

For my own reference here is a simplified reproducer.

podman run --rm -i --entrypoint bash docker.io/python:3.12 <<EOF
set -xe
export PATH="/root/.local/bin:\${PATH}"
OLD_PYTHON=\$(which python)

# not usually recommended
python -m pip install --disable-pip-version-check -q poetry

# do not do this unless there is a REAL reason for it
export POETRY_VIRTUALENVS_CREATE=false

# create a global virtual env
python -m venv global
NEW_PYTHON="\$(realpath global)/bin/python"

# fake activiate it (this is bad practice)
export PATH="\$(realpath global)/bin:\${PATH}"

poetry new demo
pushd demo
poetry add cowsay

# if active python is ignored and system python gets used the package
# appears here
\${OLD_PYTHON} -m pip show cowsay || :

# if active python is correctly detected the package should be here
\${NEW_PYTHON} -m pip show cowsay || :
EOF

@ewjoachim
Copy link
Author

ewjoachim commented Feb 25, 2024

For the record, those are the new instructions in the RTD docs:

version: 2

build:
  os: "ubuntu-22.04"
  tools:
    python: "3.10"
  jobs:
    post_create_environment:
      - pip install poetry
    post_install:
      - VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs

@abn abn added kind/question User questions (candidates for conversion to discussion) and removed status/triage This issue needs to be triaged kind/bug Something isn't working as expected labels Feb 26, 2024
@ewjoachim
Copy link
Author

ewjoachim commented Feb 27, 2024

Ok, the snippet above has been merged in the RTD docs as "this is the way". I'll let you decide whether you want to close this issue, leave it open for a few week for visibility or what, but I'm ok with the state of things so far.

@abn
Copy link
Member

abn commented Feb 27, 2024

@ewjoachim great work. Thank you.

@abn abn closed this as completed Feb 27, 2024
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 4, 2024
It seems we've been relying on a Poetry bug (or at least on
a buggy behavior)[1].

This made our documentation builds to stop working with Poetry 1.8[2]:

    Running Sphinx v7.2.6
    making output directory... done

    Traceback (most recent call last):
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/cmd/build.py", line 293, in build_main
        app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/application.py", line 272, in __init__
        self._init_builder()
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/application.py", line 342, in _init_builder
        self.builder.init()
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 219, in init
        self.init_templates()
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 270, in init_templates
        self.theme = theme_factory.create(themename)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/theming.py", line 230, in create
        raise ThemeError(__('no theme named %r found (missing theme.conf?)') % name)
    sphinx.errors.ThemeError: no theme named 'sphinx_rtd_theme' found (missing theme.conf?)

    Theme error:
    no theme named 'sphinx_rtd_theme' found (missing theme.conf?)

[1] python-poetry/poetry#9025
[2] https://readthedocs.org/projects/ts-results-es/builds/23635323/
jstasiak added a commit to lune-climate/ts-results-es that referenced this issue Mar 4, 2024
It seems we've been relying on a Poetry bug (or at least on
a buggy behavior)[1].

This made our documentation builds to stop working with Poetry 1.8[2]:

    Running Sphinx v7.2.6
    making output directory... done

    Traceback (most recent call last):
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/cmd/build.py", line 293, in build_main
        app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/application.py", line 272, in __init__
        self._init_builder()
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/application.py", line 342, in _init_builder
        self.builder.init()
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 219, in init
        self.init_templates()
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 270, in init_templates
        self.theme = theme_factory.create(themename)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/docs/checkouts/readthedocs.org/user_builds/ts-results-es/envs/109/lib/python3.11/site-packages/sphinx/theming.py", line 230, in create
        raise ThemeError(__('no theme named %r found (missing theme.conf?)') % name)
    sphinx.errors.ThemeError: no theme named 'sphinx_rtd_theme' found (missing theme.conf?)

    Theme error:
    no theme named 'sphinx_rtd_theme' found (missing theme.conf?)

[1] python-poetry/poetry#9025
[2] https://readthedocs.org/projects/ts-results-es/builds/23635323/
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 Mar 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/question User questions (candidates for conversion to discussion)
Projects
None yet
Development

No branches or pull requests

3 participants