Closed marverix closed 1 month ago
Hello @marverix, Thank you for creating this issue and we will get back to you once we have some feedback :)
Hi @marverix ,
The setup-python
action prepends the installed Python version directory to the PATH
environment variable and automatically makes it available to all subsequent actions in the current job. This ensures the specified Python version is used in subsequent steps. To prioritize your custom paths, explicitly set the PATH
environment variable in the steps after setup-python
. For more details, refer to the documentation.
For virtual environments, you need to activate the virtual environment, which prepends …/.venv/bin/
to $PATH
. Here are few approaches to handle this:
1: Activate the virtual environment in every step:
- name: Run Tests
run: |
. .venv/bin/activate
pytest
2: Activate it once and store $PATH
in a file that Actions use to restore environment variables at every step:
- name: Activate virtualenv
run: |
. .venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
Both approaches ensure the virtual environment's bin directory is added to the PATH after the setup-python
action, allowing the virtual environment to be used effectively.
Alternatively, you can use the update-environment
flag provided by setup-python. This flag determines whether the action should update the PATH environment variable. You can look at this example.
If you continue to experience issues or have further questions, please share more details.
Hi @priyagupta108 , thanks for the answer but have you read the description?
Any later (after this action) changes to PATH do not really matter, because the installed Python directory is always first.
Currently because of this behavior I'm forced to set update-environment: false
and then manually update PATH
.
@marverix 👋 ,
Thanks for your response! The action uses core.addPath()
which prepends the installed Python directory to the PATH
environment variable.
For additional PATH
customization, you can use the GITHUB_PATH
environment variable after setup-python
to prepend your desired paths. Here is an example that might work for you:
- name: Prepend custom path
run: echo "/your/custom/path" >> $GITHUB_PATH
This way, the custom path will be prepended to the PATH
variable, ensuring it takes precedence.
For further details, you may refer to the GitHub Actions documentation.
Additionally, here is a screenshot of my test run results showing the PATH modification:
Hi @marverix, just giving you a gentle ping to see if there are any updates on your end regarding this issue? Thank you!
Hi @marverix , just checking in to see if there are any updates on this issue. Thank you!
Hello @marverix Due to inactivity, I'm going to close this issue for now. Please feel free to reopen this issue or create a new one if necessary. Thank you.
Description: I don't know what kind of sorcery is this, maybe it's deeper - in
core.addPath()
, but when this action is amendingPATH
, the installed Python version directory is always first. Like, you cannot change it. Any later (after this action) changes toPATH
do not really matter, because the installed Python directory is always first. This does not allow setupping any virtualenv on hosted runners.Action version: v5
Platform:
Runner type:
Tools version: Any
Repro steps:
Just run this action
Expected behavior: This action should ofc amend the
PATH
but should allow to do any later amendments toPATH
also. Currently this is not possible.Actual behavior: Already described earlier.