如何在 Github Actions 中构建作业时安装本地 Python 包?

8

我正在构建一个名为potion的Python项目。 我想使用Github actions在将新分支合并到主分支之前自动化一些代码检查和测试。

为此,我正在使用Github推荐的Python Actions Starter Workflow的略微修改版本-- 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...


你能否在你的帖子中包含 requirements.txt 文件中的 potion 条目? - jidicula
-e git+git@github.com:<github_username>/potion.git@a3edd62c15257dc0e3755558ab1faa573bf0cd3d#egg=potion -> 这是 requirements.txt 文件中 potion 库的样子。 - PallavBakshi
1个回答

8
"被测试的软件包", 在您的情况下是 potion,不应该包含在 requirements.txt 中。相反,只需添加您的行即可。"
pip install -e .

在包含 pip install -r requirements.txt 的那一行之后。这将以开发模式安装已经签出的包,并使其在本地可用于 import
或者,您可以将该行放置在最新需要的点上,即在运行 pytest 之前。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接