pythongithubpipgithub-actionsrequirements.txt

How to install local python packages when building jobs under Github Actions?


I am building a python project -- potion. I want to use Github actions to automate some linting & testing before merging a new branch to master.

To do that, I am using a slight modification of a Github recommended python actions starter workflow -- Python Application.

During the step of "Install dependencies" within the job, I am getting an error. This is because pip is trying to install my local package potion and failing.

The code that is failing if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

The corresponding error is:

ERROR: git+https@github.com:<github_username>/potion.git@82210990ac6190306ab1183d5e5b9962545f7714#egg=potion is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, svn+http, svn+https, svn+svn, svn+file).
Error: Process completed with exit code 1.

Most likely, the job is not able install the package potion because it is not able to find it. I installed it on my own computer using pip install -e . and later used pip freeze > requirements.txt to create the requirements file.

Since I use this package for testing therefore I need to install this package so that pytest can run its tests properly.

How can I install a local package (which is under active development) on Github Actions?

Here is part of the Github workflow file python-app.yml

...
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install flake8 pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Lint with flake8
...

Note 1: I have already tried changing from git+git@github.com:<github_username>... to git_git@github.com/<github_username>.... Pay attention to / instead of :.

Note 2: I have also tried using other protocols such as git+https, git+ssh, etc.

Note 3: I have also tried to remove the alphanumeric @8221... after git url ...potion.git


Solution

  • The "package under test", potion in your case, should not be part of the requirements.txt. Instead, simply add your line

    pip install -e .
    

    after the line with pip install -r requirements.txt in it. That installs the already checked out package in development mode and makes it available locally for an import.

    Alternatively, you could put that line at the latest needed point, i.e. right before you run pytest.