簡體   English   中英

在使用 github 操作構建期間執行詩歌安裝時,使用預編譯的 numpy package 而不是構建它

[英]Use precompiled numpy package instead of building it when performing poetry install during build with github actions

我正在使用帶有 python 3.10 的詩歌 1.1.12。 我的項目依賴於 numpy 1.21.1,每次運行持續集成管道時都需要 5 分鍾來安裝。

有沒有辦法讓詩歌使用某種編譯的 numpy package 而不是每次構建時都重建它?

我已經按照這個答案中描述的步驟緩存我的虛擬環境存儲庫來緩解這個問題,但是我想要一個即使我更改我的poetry.lock文件或者我的緩存已過期的解決方案。

由於公司政策規則,我只能在 github 操作中使用ubuntu-latest圖像

我的 pyproject.toml

[tool.poetry]
name = "test-poetry"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]

[tool.poetry.dependencies]
python = "^3.10"
numpy = "^1.21.1"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"

[build-system]
requires = ["poetry-core>=1.1.12"]
build-backend = "poetry.core.masonry.api"

我的 github 操作工作流程:

name: Continuous Integration

on: push

jobs:
  test-build:
    runs-on: ubuntu-latest

    steps: 
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Install Python 3.10
        uses: actions/setup-python@v2
        with:
          python-version: '3.10'

      - name: Install Poetry packaging manager
        run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -

      - name: Configure Poetry
        run: |
          poetry config virtualenvs.create true
          poetry config virtualenvs.in-project true

      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v2
        with:
          path: .venv
          key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

      - name: Install project dependencies
        run: poetry install
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

      - name: Run test
        run: poetry run pytest

在 numpy 1.21.2 之前,僅設置了 python 的最低版本。 Numpy 1.21.1 需要 python 版本大於 3.7

但是從 numpy 1.21.2 開始,還有 python 的最高版本。 Numpy 1.21.2(在撰寫此答案時為 1.21.5)要求 python 版本大於 3.7 但嚴格低於 3.11。 以下是 numpy/python 兼容性的總結:

numpy版 python版
1.21.0 Python >=3.7
1.21.1 Python >=3.7
1.21.2 Python >=3.7, <3.11
... ...
1.21.5 Python >=3.7, <3.11

在我的pyproject.toml中,我將 python 版本設置如下:

python = "^3.10"

這與 numpy 1.21.2 和更高版本的 python 版本要求沖突。 因此,詩意決定安裝與我的 python 版本兼容的最新版本,即 1.21.1。 But numpy version 1.21.1 is not precompiled for python 3.10, the first numpy version that is precompiled for python 3.10 is numpy 1.21.2.

所以每次我安裝我的詩歌項目時,我都必須從源代碼重建 numpy。

為了糾正這個問題,我更改了我的pyproject.toml依賴項部分,如下所示:

[tool.poetry.dependencies]
python = ">=3.10,<3.11"
numpy = "^1.21.5"

現在我構建的poetry install部分檢索 python 3.10 numpy 版本 1.21.5 的預編譯,而不是編譯 Z2EA9510C37F7F89E4941FF75F6112F21CBZ 版本 1,如本答案1 中所述。

現在,我在構建中的poetry install步驟只需不到 25 秒而不是 5 分鍾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM