Skip to content

Switch Dependency Management to pyproject.toml + Bonus Changes #273

Switch Dependency Management to pyproject.toml + Bonus Changes

Switch Dependency Management to pyproject.toml + Bonus Changes #273

Workflow file for this run

on:
pull_request_target:
jobs:
autofix:
runs-on: ubuntu-latest
steps:
# git-auto-commit-action is a bit tricky to use.
# See the "advanced" section in its README for an insecure configuration that works.
#
# To make it secure against malicious pull requests, you cannot trust files in the PR,
# because pull_request_target jobs have more permissions than pull_request jobs.
# Here we place the PR's stuff to a subdirectory named "pr".
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
path: ./pr
- uses: actions/setup-python@v4
with:
python-version: "3.11"
cache: pip
- run: pip install wheel
- run: pip install ".[dev]"
- name: Gather a list of Python files in the pull request branch
run: |
(cd pr && git ls-files) | grep -E '\.(py|pyw)$' | sed s:^:pr/: | tee filelist.txt
- run: python3 -m pycln --all --disable-all-dunder-policy $(cat filelist.txt)
- run: python3 -m pyupgrade $(cat filelist.txt) --keep-runtime-typing --py38-plus --exit-zero-even-if-changed
- run: python3 -m black $(cat filelist.txt)
- run: python3 -m isort $(cat filelist.txt)
# I like requirements-dev.txt and some other people like pyproject.toml, so we have both.
# Auto-generating is the easiest way to ensure the two stay in sync.
- name: Generate requirements-dev.txt from pyproject.toml
run: |
echo "# Auto-generated in GitHub Actions. See autofix.yml." > pr/requirements-dev.txt
pip install tomli
python3 -c 'if True:
import tomli
with open("pr/pyproject.toml", "rb") as f:
content = tomli.load(f)
for dep in content["project"]["optional-dependencies"]["dev"]:
print(dep)
' >> pr/requirements-dev.txt
- uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: ./pr
commit_message: "Run pycln, pyupgrade, black, and isort"