Skip to content

Commit

Permalink
feat(pip-compile)!: move configuration to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Dec 13, 2024
1 parent 6627cae commit 4732513
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 72 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/_check-pip-compile-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,4 @@ jobs:
- uses: actions/checkout@v4
- uses: deargen/workflows/actions/check-pip-compile@master
with:
cwd: python-projector
pyproject-toml-file: pyproject.toml
requirements-in-dir: deps
requirements-out-dir: deps/lock
project-dir: python-projector
1 change: 1 addition & 0 deletions .github/workflows/_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ jobs:
- uses: deargen/workflows/actions/setup-python-and-uv@master
- name: Build and upload to PyPI
run: |
cd python-projector
uv build --sdist
uv publish
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ jobs:
uses: deargen/workflows/.github/workflows/check-ruff.yml@master
with:
check-type: format
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
ruff-isort:
uses: deargen/workflows/.github/workflows/check-ruff.yml@master
with:
check-type: isort
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
ruff-lint:
uses: deargen/workflows/.github/workflows/check-ruff.yml@master
with:
check-type: lint
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
```

### Style checking for changed files only
Expand All @@ -52,17 +52,17 @@ jobs:
uses: deargen/workflows/.github/workflows/check-ruff-only-changed.yml@master
with:
check-type: format
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
ruff-isort-on-changes:
uses: deargen/workflows/.github/workflows/check-ruff-only-changed.yml@master
with:
check-type: isort
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
ruff-lint-on-changes:
uses: deargen/workflows/.github/workflows/check-ruff-only-changed.yml@master
with:
check-type: lint
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
```


Expand All @@ -87,7 +87,7 @@ jobs:
with:
ruff-select: ${{ github.event.inputs.ruff-select }}
ruff-ignore: ${{ github.event.inputs.ruff-ignore }}
ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
# ruff-version-file: deps/lock/x86_64-manylinux_2_28/requirements_dev.txt
```

## Cargo clippy and fmt checking for Rust projects
Expand Down Expand Up @@ -117,6 +117,8 @@ jobs:
## Compiling requirements.txt (generate locked versions)
This uses `projector pip-compile` command thus requires configuring `pyproject.toml` file accordingly. See [python-projector](python-projector) for more information.

### Check uv pip compile

```yaml
Expand All @@ -135,11 +137,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: deargen/workflows/actions/check-pip-compile@master
with:
pyproject-toml-file: pyproject.toml
requirements-in-dir: deps
requirements-out-dir: deps/lock
python-platforms: x86_64-manylinux_2_28,aarch64-apple-darwin,x86_64-apple-darwin
```

### Apply uv pip compile
Expand All @@ -156,11 +153,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: deargen/workflows/actions/apply-pip-compile@master
with:
pyproject-toml-file: pyproject.toml
requirements-in-dir: deps
requirements-out-dir: deps/lock
python-platforms: x86_64-manylinux_2_28,aarch64-apple-darwin,x86_64-apple-darwin
```

## mkdocs build
Expand Down
62 changes: 40 additions & 22 deletions actions/apply-pip-compile/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,50 @@ description: Freeze dependencies using uv pip compile
author: Kiyoon Kim

inputs:
project-dir:
description: Directory to search pyproject.toml. Default is the root directory.
required: false
pyproject-toml-file:
description: Path to pyproject.toml file for getting the minimum python version
required: true
default: pyproject.toml
required: false
deprecationMessage: Use project-dir instead. It will read the pyproject.toml file in the directory.
requirements-in-dir:
description: Directory to search all requirements*.in files
required: true
default: deps
required: false
deprecationMessage: Use project-dir instead. It will read the configuration in pyproject.toml.
requirements-out-dir:
description: Directory to save compiled requirements*.txt files
required: true
default: deps/lock
required: false
deprecationMessage: Use project-dir instead. It will read the configuration in pyproject.toml.
python-platforms:
description: Platforms to support (comma-separated)
required: true
default: x86_64-manylinux_2_28,aarch64-apple-darwin,x86_64-apple-darwin,x86_64-pc-windows-msvc
cwd:
description: 'The directory to run uv (and the whole script) in'
required: false
deprecationMessage: Use project-dir instead. It will read the configuration in pyproject.toml.

runs:
using: 'composite'
steps:
- shell: bash
- name: Check deprecated inputs
shell: bash
run: |
if [[ -n "${{ inputs.cwd }}" ]]; then
cd "${{ inputs.cwd }}"
if [[ -n "${{ inputs.pyproject-toml-file }}" ]]; then
echo "The input 'pyproject-toml-file' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
echo "min_python_version=$(python3 ${{ github.action_path }}/../../scripts/get_min_python_version.py "${{ inputs.pyproject-toml-file }}")" >> "$GITHUB_OUTPUT"
pip3 install uv --break-system-packages
if [[ -n "${{ inputs.requirements-in-dir }}" ]]; then
echo "The input 'requirements-in-dir' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "${{ inputs.requirements-out-dir }}" ]]; then
echo "The input 'requirements-out-dir' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "${{ inputs.python-platforms }}" ]]; then
echo "The input 'python-platforms' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Install uv
uses: astral-sh/setup-uv@v4
- shell: bash
run: |
uv tool install ${{ github.action_path }}/../../python-projector
echo "min_python_version=$(projector get-min-python-version ${{ inputs.project-dir }})" >> "$GITHUB_OUTPUT"
id: get-python-version
- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -42,14 +56,18 @@ runs:
name: Run uv pip compile and push
run: |
# set +e # Do not exit shell on failure
if [[ -n "${{ inputs.cwd }}" ]]; then
cd "${{ inputs.cwd }}"
if [[ -n "${{ inputs.project-dir }}" ]]; then
projector pip-compile ${{ inputs.project-dir }}
elif [[ -z "${{ inputs.requirements-in-dir }}" ]]; then
projector pip-compile
else
# deprecated inputs
bash ${{ github.action_path }}/../../scripts/compile_requirements.sh \
"${{ inputs.requirements-in-dir }}" \
"${{ inputs.requirements-out-dir }}" \
"${{ steps.get-python-version.outputs.min_python_version }}" \
"${{ inputs.python-platforms }}"
fi
bash ${{ github.action_path }}/../../scripts/compile_requirements.sh \
"${{ inputs.requirements-in-dir }}" \
"${{ inputs.requirements-out-dir }}" \
"${{ steps.get-python-version.outputs.min_python_version }}" \
"${{ inputs.python-platforms }}"
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
Expand Down
63 changes: 40 additions & 23 deletions actions/check-pip-compile/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,50 @@ description: Detect changes in requirements*.in files that are not compiled yet
author: Kiyoon Kim

inputs:
project-dir:
description: Directory to search pyproject.toml. Default is the root directory.
required: false
pyproject-toml-file:
description: Path to pyproject.toml file for getting the minimum python version
required: true
default: pyproject.toml
required: false
deprecationMessage: Use project-dir instead. It will read the pyproject.toml file in the directory.
requirements-in-dir:
description: Directory to search all requirements*.in files
required: true
default: deps
required: false
deprecationMessage: Use project-dir instead. It will read the configuration in pyproject.toml.
requirements-out-dir:
description: Directory to save compiled requirements*.txt files
required: true
default: deps/lock
required: false
deprecationMessage: Use project-dir instead. It will read the configuration in pyproject.toml.
python-platforms:
description: Platforms to support (comma-separated)
required: true
default: x86_64-manylinux_2_28,aarch64-apple-darwin,x86_64-apple-darwin,x86_64-pc-windows-msvc
cwd:
description: 'The directory to run uv (and the whole script) in'
required: false
deprecationMessage: Use project-dir instead. It will read the configuration in pyproject.toml.

runs:
using: 'composite'
steps:
- shell: bash
- name: Check deprecated inputs
shell: bash
run: |
if [[ -n "${{ inputs.cwd }}" ]]; then
cd "${{ inputs.cwd }}"
if [[ -n "${{ inputs.pyproject-toml-file }}" ]]; then
echo "The input 'pyproject-toml-file' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "${{ inputs.requirements-in-dir }}" ]]; then
echo "The input 'requirements-in-dir' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
echo "min_python_version=$(python3 ${{ github.action_path }}/../../scripts/get_min_python_version.py "${{ inputs.pyproject-toml-file }}")" >> "$GITHUB_OUTPUT"
pip3 install uv --break-system-packages
if [[ -n "${{ inputs.requirements-out-dir }}" ]]; then
echo "The input 'requirements-out-dir' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "${{ inputs.python-platforms }}" ]]; then
echo "The input 'python-platforms' is deprecated." >> "$GITHUB_STEP_SUMMARY"
fi
- name: Install uv
uses: astral-sh/setup-uv@v4
- shell: bash
run: |
uv tool install ${{ github.action_path }}/../../python-projector
echo "min_python_version=$(projector get-min-python-version ${{ inputs.project-dir }})" >> "$GITHUB_OUTPUT"
id: get-python-version
- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -43,15 +57,18 @@ runs:
run: |
set +e # Do not exit shell on failure
if [[ -n "${{ inputs.cwd }}" ]]; then
cd "${{ inputs.cwd }}"
if [[ -n "${{ inputs.project-dir }}" ]]; then
out=$(projector pip-compile ${{ inputs.project-dir }} 2> _stderr.txt)
elif [[ -z "${{ inputs.requirements-in-dir }}" ]]; then
out=$(projector pip-compile 2> _stderr.txt)
else
# deprecated inputs
out=$(bash ${{ github.action_path }}/../../scripts/compile_requirements.sh \
"${{ inputs.requirements-in-dir }}" \
"${{ inputs.requirements-out-dir }}" \
"${{ steps.get-python-version.outputs.min_python_version }}" \
"${{ inputs.python-platforms }}" 2> _stderr.txt)
fi
out=$(bash ${{ github.action_path }}/../../scripts/compile_requirements.sh \
"${{ inputs.requirements-in-dir }}" \
"${{ inputs.requirements-out-dir }}" \
"${{ steps.get-python-version.outputs.min_python_version }}" \
"${{ inputs.python-platforms }}" 2> _stderr.txt)
exit_code=$?
err=$(<_stderr.txt)
Expand Down
8 changes: 5 additions & 3 deletions python-projector/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ authors = [
]
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.13,<4"
requires-python = ">=3.11,<4"
classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: Apache Software License",
]
Expand All @@ -42,7 +44,7 @@ license-files = []
dependencies = {file = ["deps/requirements.in"]}

[tool.setuptools.package-data]
python_projector = ["template.env"] # CHANGE (name of the importing module name)
python_projector = ["shell/*.sh"] # CHANGE (name of the importing module name)

[tool.setuptools.packages.find]
where = ["src"]
Expand Down Expand Up @@ -72,7 +74,7 @@ typeCheckingMode = "standard"
useLibraryCodeForTypes = true
autoImportCompletions = true

pythonVersion = "3.13"
pythonVersion = "3.11"
# pythonPlatform = "Linux"

reportDuplicateImport = true
Expand Down
3 changes: 0 additions & 3 deletions python-projector/src/python_projector/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
from pathlib import Path
from typing import Annotated

import rich
import typer
from rich.prompt import Prompt
from rich.syntax import Syntax

app = typer.Typer(
no_args_is_help=True, context_settings={"help_option_names": ["-h", "--help"]}
Expand Down

0 comments on commit 4732513

Please sign in to comment.