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

Build: expose location of virtualenv #9629

Closed
davidism opened this issue Sep 28, 2022 · 13 comments · Fixed by #9971
Closed

Build: expose location of virtualenv #9629

davidism opened this issue Sep 28, 2022 · 13 comments · Fixed by #9971
Assignees
Labels
Accepted Accepted issue on our roadmap Feature New feature

Comments

@davidism
Copy link

I'm using the PDM dependency management tool, moving away from requirements.txt files. If PDM does not detect an active virtualenv, or is not told about the location of a virtualenv, it will create one and install packages there.

Read the Docs does not activate or expose the path to the virtualenv it creates. It seems that which python does report the virtualenv python despite that, so a hack is used to get the path and tell PDM about it. pdm-project/pdm#1365 (comment)

VIRTUAL_ENV=$(dirname $(dirname $(which python))) ~/.local/bin/pdm sync -dG docs

It would be helpful if Read the Docs made the virtualenv easier to find. You could set VIRTUAL_ENV, or maybe RTD_VIRTUAL_ENV if you don't want to affect other tools by default. Alternatively, activate it.

@humitos
Copy link
Member

humitos commented Sep 28, 2022

Hi @davidism! I don't have experience working with PDM, so maybe what I'm going to suggest makes no sense 😄

However, for Poetry users that have a similar situation where the "feature of auto-creation of the virtualenv interferes with Read the Docs default build workflow" we documented a workaround for that at https://docs.readthedocs.io/en/latest/build-customization.html#install-dependencies-with-poetry. I saw that PDM does support something similar https://pdm.fming.dev/latest/usage/venv/#disable-virtualenv-mode

That solution/workaround does work for your case?

@davidism
Copy link
Author

davidism commented Sep 28, 2022

In PDM, disabling virtualenv support means enable the old __pypackages__ PEP, which won't solve the issue either. There is no way to completely disable venv support as far as I know. Maybe @frostming can say more, but I'm guessing that would have been suggested in the linked PDM issue if it were possible.

@humitos humitos added Feature New feature Needed: design decision A core team decision is required labels Sep 29, 2022
@humitos humitos changed the title expose location of virtualenv Expose location of virtualenv Sep 29, 2022
@davidism
Copy link
Author

@davidfischer @ericholscher This is the virtualenv feature I was talking about yesterday.

@ericholscher
Copy link
Member

Gotcha, I was going to suggest something like VIRTUAL_ENV=$(dirname $(dirname $(which python))) as a workaround, since we do run via the Python executable. I agree that adding an ENV for this would be useful, but that's not the worst workaround for now.

@davidism
Copy link
Author

davidism commented Jan 9, 2023

I'm planning to switch Flask, Click, etc. to PDM soon. It would be nice to be able to directly reference the virtualenv location. What's the status of work on this?

@ericholscher
Copy link
Member

@davidism I will add this to our upcoming sprint so we can take a look at it. I think it's reasonable to add it to the environment, and won't be complex, but mostly just need to do the PR 👍

@github-project-automation github-project-automation bot moved this to Planned in 📍Roadmap Jan 10, 2023
@ericholscher ericholscher self-assigned this Jan 10, 2023
@humitos humitos changed the title Expose location of virtualenv Build: expose location of virtualenv Jan 31, 2023
humitos added a commit that referenced this issue Feb 1, 2023
This variable points to where Read the Docs created the virtualenv.

Closes #9629
@humitos humitos moved this from Planned to Needs review in 📍Roadmap Feb 1, 2023
@humitos humitos self-assigned this Feb 1, 2023
@humitos humitos added Accepted Accepted issue on our roadmap and removed Needed: design decision A core team decision is required labels Feb 1, 2023
@humitos
Copy link
Member

humitos commented Feb 1, 2023

I went ahead and implemented this feature in #9971. Hopefully, we can review it this week and deploy it the next one.

Considering flask-sqlalchemy and 1107 version as example, the value of this variable will be: /home/docs/checkouts/readthedocs.org/user_builds/flask-sqlalchemy/envs/1107. @davidism let me know if that would be accurate for your use case.

@davidism
Copy link
Author

davidism commented Feb 1, 2023

@frostming does this look correct?

@frostming
Copy link

LGTM

@davidism
Copy link
Author

davidism commented Feb 2, 2023

Will you close this once it's deployed? Or is it ready for me to test?

@ericholscher
Copy link
Member

@davidism It should go out in our deploy next week on Tuesday. This issue will likely get closed once the issue is merged, but Tuesday is the day :)

@github-project-automation github-project-automation bot moved this from Needs review to Done in 📍Roadmap Feb 7, 2023
humitos added a commit that referenced this issue Feb 7, 2023
* Build: expose `READTHEDOCS_VIRTUALENV_PATH` variable

This variable points to where Read the Docs created the virtualenv.

Closes #9629

* Build: use our own variable `$READTHEDOCS_VIRTUALENV_PATH`

This variable contains the path we need to call the Python executable.

* Build: use environment variables for Conda as well

* Tests: add missing variable

* Lint

* Lint again

* Missing :

* Test: update env variables

* Test: make it work locally and CicleCI

* Docs: add link to the builds page

* Refactor: make `venv_bin` more concrete to match venv/conda

* Build: missing return

* API: sanitize build command properly

* Update readthedocs/api/v2/serializers.py

Co-authored-by: Eric Holscher <[email protected]>

---------

Co-authored-by: Eric Holscher <[email protected]>
@humitos
Copy link
Member

humitos commented Feb 7, 2023

@davidism @frostming This is already deployed. You should be able to make usage of the variable READTHEDOCS_VIRTUALENV_PATH now from your build commands. Let me know if this works as you expected 👍🏼

@davidism
Copy link
Author

davidism commented Feb 8, 2023

Looks like it worked: https://readthedocs.org/projects/flask-sqlalchemy/builds/19424647/ thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Feature New feature
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants