Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Action/Ubuntu: add to PYTHONPATH

On Github Action workflow main.yml, I did the following to add to PYTHONPATH

PWD=$(pwd)
export PYTHONPATH=$PWD/src:$PWD/tests:$PYTHONPATH

I verified the PYTHONPATH using the following command

echo "PYTHONPATH=$PYTHONPATH"

and the output is PYTHONPATH=/home/runner/work/my_api/my_api/src:/home/runner/work/my_api/my_api/tests

I have a module called my_api live under /home/runner/work/my_api/my_api/src

But now I'm getting ModuleNotFoundError: No module named 'my_api' It seems export PYTHONPATH has no impact on the system. Below is the complete workfile YML file.

name: Integration Test Run
env:
    HISTORIC_DATA_FOLDER: /usr/my_api_historic_data
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install Python 3
        uses: actions/setup-python@v1
        with:
          python-version: 3.6
      - name: Filessytem Setup
        run: |
          pwd
          mkdir my_api_historic_data_test
      - name: Docker Compose
        run: |
          sudo docker-compose -f docker-compose-github.yml build
          sudo docker-compose -f docker-compose-github.yml --verbose --env-file .env up &
      - name: Intgration Test Setup
        run: |
          echo "-----pwd-----"
          pwd

          echo "-----ls-----"
          ls

          echo "-----ls src/-----"
          ls src/

          echo "----PYTHONPATH------"
          PWD=$(pwd)
          export PYTHONPATH=$PWD/src:$PWD/tests:$PYTHONPATH
          echo "PYTHONPATH=$PYTHONPATH"

          echo "-----HISTORIC PATH----"
          export HISTORIC_DATA_FOLDER=/home/runner/work/my_api/my_api/my_api_historic_data_test
          echo "HISTORIC_DATA_FOLDER=$HISTORIC_DATA_FOLDER"
      - name: Integreation Test Run
        run: |
          sleep 30
          pip install requests
          sudo python -m unittest discover


like image 921
user1187968 Avatar asked Oct 29 '25 20:10

user1187968


1 Answers

As already said in comments, each step runs in it's own shell. You need to make sure your variable is exported properly, so that it's available in all subsequent steps.

echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV

See docs for more details.

like image 102
frennky Avatar answered Oct 31 '25 11:10

frennky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!