Skip to content

Commit

Permalink
Auto-create pyproject.toml (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans authored Nov 15, 2024
1 parent 509e63b commit 531d31b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 48 deletions.
104 changes: 58 additions & 46 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,56 +88,69 @@ runs:
git config user.email ${{ inputs.git_committer_email }}
shell: bash

- name: check for deprecated features
- name: Check pyproject.toml for project migration
if: env.IS_GIT_BEHIND != 'true'
run: |
# if needed: auto-create a minimal pyproject.toml
if [[ ! -f pyproject.toml ]]; then
touch pyproject.toml
# TODO: update logic when https://github.com/WIPACrepo/wipac-dev-py-setup-action/issues/62
# add required fields
echo "# WIPACrepo/wipac-dev-py-setup-action@v4+ Migration Helper:" >> pyproject.toml
echo "" >> pyproject.toml
echo "# set these fields:" >> pyproject.toml
echo "[project]" >> pyproject.toml
echo "version = \"0.0.0\"" >> pyproject.toml
# add most likely needed fields
echo "dependencies = [] # leave empty if there are no dependencies" >> pyproject.toml
echo "" >> pyproject.toml
echo "# optional sections:" >> pyproject.toml
echo "" >> pyproject.toml
echo "# [project.optional-dependencies]" >> pyproject.toml
echo "# foo = []" >> pyproject.toml
echo "# bar = []" >> pyproject.toml
# commit, push, exit
msg="added pyproject.toml -- ALERT: user needs to set values for auto-added fields"
git add .
git commit -m "<bot> $msg"
git push
echo $msg
echo "IS_GIT_BEHIND=true" >> $GITHUB_ENV
fi
# no setup.cfg allowed!
if [[ -f setup.cfg ]]; then
if [[ ! -f pyproject.toml ]]; then
# auto-create a minimal toml
# when this action runs on next commit, it will match the 'else' condition below
touch pyproject.toml
# TODO: update logic when https://github.com/WIPACrepo/wipac-dev-py-setup-action/issues/62
# add required fields
echo "# WIPACrepo/wipac-dev-py-setup-action@v4+ Migration Helper:" >> pyproject.toml
echo "" >> pyproject.toml
echo "# set these fields:" >> pyproject.toml
echo "[project]" >> pyproject.toml
echo "version = \"0.0.0\"" >> pyproject.toml
# add most likely needed fields
echo "dependencies = [] # leave empty if there are no dependencies" >> pyproject.toml
echo "" >> pyproject.toml
echo "# optional sections:" >> pyproject.toml
echo "" >> pyproject.toml
echo "# [project.optional-dependencies]" >> pyproject.toml
echo "# foo = []" >> pyproject.toml
echo "# bar = []" >> pyproject.toml
# commit, push, exit
msg="added pyproject.toml -- user needs to set values for auto-added fields"
git add .
git commit -m "<bot> $msg"
git push
echo $mgs
echo "IS_GIT_BEHIND=true" >> $GITHUB_ENV
else
echo " "
echo "WIPACrepo/wipac-dev-py-setup-action no longer supports 'setup.cfg'"
echo "Migration Steps:"
echo " 1. Look at 'pyproject.toml'--this action may have auto-added fields."
echo " Fill out any needed values."
echo " 2. Manually move attributes from setup.cfg's [wipac:cicd_setup_builder]"
echo " section to WIPACrepo/wipac-dev-py-setup-action's 'with' block."
echo " See https://github.com/WIPACrepo/wipac-dev-py-setup-action#inputs."
echo " 3. Migrate any non-autogenerated configuration to 'pyproject.toml'."
echo " 4. Delete 'setup.cfg'."
echo " 5. If used, update WIPACrepo/wipac-dev-py-versions-action to most"
echo " recent version."
echo " See https://github.com/WIPACrepo/wipac-dev-py-versions-action."
echo " 6. Push these changes!"
exit 1
fi
echo " "
echo "WIPACrepo/wipac-dev-py-setup-action no longer supports 'setup.cfg'"
echo "Migration Steps:"
echo " 1. Look at 'pyproject.toml'--this action may have auto-added fields."
echo " Fill out any needed values."
echo " 2. Manually move attributes from setup.cfg's [wipac:cicd_setup_builder]"
echo " section to WIPACrepo/wipac-dev-py-setup-action's 'with' block."
echo " See https://github.com/WIPACrepo/wipac-dev-py-setup-action#inputs."
echo " 3. Migrate any non-autogenerated configuration to 'pyproject.toml'."
echo " 4. Delete 'setup.cfg'."
echo " 5. If used, update WIPACrepo/wipac-dev-py-versions-action to most"
echo " recent version."
echo " See https://github.com/WIPACrepo/wipac-dev-py-versions-action."
echo " 6. Push these changes!"
exit 1
fi
shell: bash


- name: Prepare Keywords
if: env.IS_GIT_BEHIND != 'true'
run: |
# Wrap each line in quotes if not already quoted, then replace newlines with spaces
PYPROJECT_KEYWORDS=$(sed 's/^[^"].*[^"]$/"&"/' <<EOF | tr '\n' ' '
${{ inputs.keywords }}
EOF
)
echo "keywords in a line:"
echo "$PYPROJECT_KEYWORDS"
echo "PYPROJECT_KEYWORDS=$PYPROJECT_KEYWORDS" >> $GITHUB_ENV
shell: bash

- name: Build pyproject.toml + README.md (and commit)
if: env.IS_GIT_BEHIND != 'true'
run: |
Expand All @@ -149,13 +162,12 @@ runs:
# Build!
set -x
# NOTE: when an arg is a list, don't quote it
export PYPROJECT_KEYWORDS
python3 ${{ github.action_path }}/pyproject_toml_builder.py \
--toml pyproject.toml \
--github-full-repo $GITHUB_REPOSITORY \
--token ${{ github.token }} \
--python-min "${{ inputs.python_min }}" \
--keywords ${{ inputs.keywords }} \
--python-max "${{ inputs.python_max }}" \
--package-dirs ${{ inputs.package_dirs }} \
--exclude-dirs ${{ inputs.exclude_dirs }} \
Expand Down
5 changes: 3 additions & 2 deletions pyproject_toml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import re
import shlex
import subprocess
from pathlib import Path
from typing import Any, cast
Expand Down Expand Up @@ -147,7 +148,7 @@ def get_requires_python(self) -> str:
Ex: "">=3.6, <3.10" (cannot do "<=3.9" because 3.9.1 > 3.9)
"""
return f">={self.python_min[0]}.{self.python_min[1]}, <{self.python_max[0]}.{self.python_max[1]+1}"
return f">={self.python_min[0]}.{self.python_min[1]}, <{self.python_max[0]}.{self.python_max[1] + 1}"

def python_classifiers(self) -> list[str]:
"""Get auto-detected `Programming Language :: Python :: *` list.
Expand Down Expand Up @@ -714,7 +715,7 @@ def coerce_python_version(val: str | None) -> None | tuple[int, int]:
"--keywords",
nargs="*",
type=str,
default=[],
default=shlex.split(os.getenv("PYPROJECT_KEYWORDS", "")),
help="Space-separated list of keywords",
)
parser.add_argument(
Expand Down

0 comments on commit 531d31b

Please sign in to comment.