如何在 Github 操作下构建作业时安装本地 python 包?
How to install local python packages when building jobs under Github Actions?
我正在构建一个 python 项目 -- potion
。在将新分支合并到 master 之前,我想使用 Github 操作来自动化一些 linting 和测试。
为此,我使用了 Github 推荐的 python 操作启动工作流程的轻微修改 -- Python Application.
在作业中的“安装依赖项”步骤中,出现错误。这是因为 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 workflow filepython-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+https
、git+ssh
等
注3:我也试过在giturl...potion.git
之后去掉字母数字@8221...
在您的情况下,“被测包”potion
不应该是 requirements.txt 的一部分。相反,只需添加您的行
pip install -e .
在 pip install -r requirements.txt
行之后。这会在开发模式下安装已经签出的包,并使其在本地可用于 import
.
或者,您可以将该行放在最近需要的位置,即就在您 运行 pytest
.
之前
我正在构建一个 python 项目 -- potion
。在将新分支合并到 master 之前,我想使用 Github 操作来自动化一些 linting 和测试。
为此,我使用了 Github 推荐的 python 操作启动工作流程的轻微修改 -- Python Application.
在作业中的“安装依赖项”步骤中,出现错误。这是因为 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 workflow filepython-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+https
、git+ssh
等
注3:我也试过在giturl...potion.git
@8221...
在您的情况下,“被测包”potion
不应该是 requirements.txt 的一部分。相反,只需添加您的行
pip install -e .
在 pip install -r requirements.txt
行之后。这会在开发模式下安装已经签出的包,并使其在本地可用于 import
.
或者,您可以将该行放在最近需要的位置,即就在您 运行 pytest
.