当我使用 Github 工作流程构建包并将其发布到 testpypi 时,我遇到以下错误。
当我尝试在本地构建包时,我只得到两个文件,但当我使用工作流 yml 时,它还会创建第三个文件 *.egg。如何避免生成 .egg 文件?
这是我构建此包的 yml 文件:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Sets up python3
- uses: actions/setup-python@v3
with:
python-version: 3.8
# Installs and upgrades pip, installs other dependencies and installs the package from setup.py
- name: "Installs and upgrades pip, installs other dependencies and installs the package from setup.py"
run: |
# Upgrade pip
python3 -m pip install --upgrade pip
# Install build deps
python3 -m pip install setuptools wheel twine
# If requirements.txt exists, install from it
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
# Install the package from setup.py
python3 setup.py install
# Tests with unittest
# - name: Test with unittest
# run: |
# cd tests
# python3 -m unittest discover
# cd ..
# Upload to TestPyPI
- name: Build and Upload to TestPyPI
run: |
python3 setup.py sdist bdist_wheel
python3 -m twine upload --verbose dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_TEST_TOKEN }}
TWINE_REPOSITORY: testpypi
删除步骤
python3 setup.py install
——这就是创建有问题的文件的原因。不应该需要它(用于构建/发布)。您还可以使用 pip install .
作为可能的替代方案。
或者,如果您确实希望保留此步骤,请在构建 sdist/wheel 之前删除
dist
目录。
run: |
# clear eggs from setup.py install
rm -rf ./dist
# build clean distribution for PyPI
python3 setup.py sdist bdist_wheel
python3 -m twine upload --verbose dist/*