在GithubActions下构建作业时,如何安装本地python包



我正在构建一个python项目——potion。我想使用Github操作来自动化一些linting&在将新分支合并到master之前进行测试。

为了做到这一点,我对Github推荐的python操作启动工作流——python应用程序进行了轻微修改。

在步骤";安装依赖项";在工作中,我犯了一个错误。这是因为pip正在尝试安装我的本地包potion,但失败了。

if [ -f requirements.txt ]; then pip install -r requirements.txt; fi失败的代码

相应的错误为:

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.

很可能,作业无法安装程序包potion,因为找不到它。我使用pip install -e .将其安装在自己的计算机上,后来使用pip freeze > requirements.txt创建需求文件。

由于我使用这个包进行测试,因此我需要安装这个包,以便pytest能够正确运行其测试。

如何在Github Actions上安装本地包(正在积极开发中(

这是Github工作流文件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
...

注1:我已经尝试过从git+git@github.com:<github_username>...更改为git_git@github.com/<github_username>...。注意/而不是:

注2:我也尝试过使用其他协议,如git+httpsgit+ssh等。

注意3:我还尝试删除git url...potion.git之后的字母数字@8221...

;测试中的包装";,在您的情况下,potion不应该是requirements.txt的一部分。相反,只需添加您的行

pip install -e .

在其中包含pip install -r requirements.txt的行之后。这将在开发模式下安装已经签出的包,并使其在本地可用于import

或者,您可以将该行放在最新需要的点,即运行pytest之前。

最新更新