Skip to content

Commit

Permalink
feat: ✨ switch to justfile
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainBrault committed Jan 22, 2025
1 parent 6092ff8 commit 7fde2d2
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 144 deletions.
39 changes: 16 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,36 @@ on:
branches: ["main"]
tags-ignore: ["**"]
pull_request:
schedule:
- cron: "0 4 * * *"

concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
name: tox env ${{ matrix.tox_env }} under python ${{ matrix.python }}
name: just ${{ matrix.receipt }}
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python:
- "3.13"
tox_env:
receipt:
- pre-commit
steps:
- name: Check out the repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install uv
uses: astral-sh/setup-uv@b5f58b2abc5763ade55e4e9d0fe52cd1ff7979ca # v5
- name: Pick environment to run
run: |
import os;
env = "TOXENV=${{ matrix.tox_env }}\n"
with open(os.environ["GITHUB_ENV"], mode="a", encoding="utf-8") as file_handler:
file_handler.write(env)
shell: python
- name: Install just
uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2
- name: Run the test suite
run: |
uvx --no-progress --quiet --with tox-uv tox run
just ${{ matrix.receipt }}
test:
name: Run ${{ matrix.session }} tests under python ${{ matrix.python }} on ${{ matrix.os }}
name: Run ${{ matrix.diffusion }} tests under python ${{ matrix.python }} on ${{ matrix.os }}
needs: check
runs-on: ${{ matrix.os }}
timeout-minutes: 10
Expand All @@ -55,27 +52,23 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
session:
diffusion:
- open-source
- proprietary
steps:
- name: Check out the repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Install uv
uses: astral-sh/setup-uv@b5f58b2abc5763ade55e4e9d0fe52cd1ff7979ca # v5
- name: Pick environment to run
run: |
import os;
toxenv = "TOXENV=py{}{}-test-${{ matrix.session }}\n".format(*"${{ matrix.python }}".split("."))
os_name = "OS_NAME=${{ matrix.os }}\n"
env = toxenv + os_name
with open(os.environ["GITHUB_ENV"], mode="a", encoding="utf-8") as file_handler:
file_handler.write(env)
shell: python
- name: Install just
uses: extractions/setup-just@dd310ad5a97d8e7b41793f8ef055398d51ad4de6 # v2
- name: Github Login
run: |
echo "${{ secrets.GH_TOKEN }}" | gh auth login --with-token
- name: Run the test suite
- name: Setup Git
run: |
gh auth setup-git
git config --global init.defaultBranch main
uvx --no-progress --quiet --with tox-uv tox run
- name: Run the test suite
run: |
just test-${{ matrix.diffusion }} ${{ matrix.python }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
.secrets.*

## Integration
.nox
.tox
.just
.venv

## Generated files
Expand Down
5 changes: 5 additions & 0 deletions .python-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3.9
3.10
3.11
3.12
3.13
3 changes: 2 additions & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ SPDX-License-Identifier = "MIT-0"
## Project configuration

[[annotations]]
path = "tox.ini"
path = ".python-versions"
precedence = "override"
SPDX-FileCopyrightText = "© 2024 The Whiteprints Authors <whiteprints@pm.me>"
SPDX-License-Identifier = "MIT-0"

Expand Down
156 changes: 156 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
# SPDX-FileCopyrightText: © 2024 The "Whiteprints" contributors <whiteprints@pm.me>
#
# SPDX-License-Identifier: MIT-0


# Uncomment this to use project local uv cache.
# export UV_CACHE_DIR := ".just/.cache/uv"
export UV_NO_PROGRESS := "true"
export GH_TOKEN := env("GH_TOKEN", "")


# list all receipts
default:
@just --list

# Clean Python temporary files
clean-python:
@just uvx "pyclean ."

# Clean the generated Bill of Material (BOM)
clean-BOM:
rm -rf BOM

# Clean the documentation
clean-docs:
rm -rf docs_build

# Clean the just working directory
clean-just:
rm -rf .just

# Clean everything
clean-all:
@just clean-python
@just clean-BOM
@just clean-just
@just clean-docs

# Run a receipt for all Python versions (found in the .python-versions file). Works for all receipt whose first argument is a Python version
for-all-python receipt args="":
for python in `grep -v '^#' {{ justfile_directory() }}/.python-versions`; do \
just {{ receipt }} $python {{ args }}; \
done

# initialise Just working directory and synchronize the virtualenv
init:
[ -d .just ] || mkdir -p .just

venv receipt python license="": init
[ -d ".just/{{ receipt }}/{{ license }}/{{ python }}" ] || \
mkdir -p ".just/{{ receipt }}/{{ license }}/{{ python }}"
rm -rf ".just/{{ receipt }}/{{ license }}/{{ python }}/tmp"
mkdir -p ".just/{{ receipt }}/{{ license }}/{{ python }}/tmp"
uv venv \
--no-project \
--no-config \
--python={{ python }} \
".just/{{ receipt }}/{{ license }}/{{ python }}/.venv"

# Run `uv`
uv args="":
uv \
{{ args }}

# Run `uv tool run`
uvx args="":
@just uv " \
tool run \
--isolated \
{{ args }} \
"

# Remove the test repository
delete-repostitory python license:
-gh repo delete --yes "\
whiteprints-tests/test-gh-pypi\
{{ if license == '' { '-' } else { prepend('-', append('-', kebabcase(license))) } }}\
{{ os() }}-$(echo {{ python }} | tr -d .)\
"

# Test the template
test python license: (venv "test" python license) (delete-repostitory python license) && (delete-repostitory python license)
@just uvx "\
--with whiteprints-template-context \
copier copy \
--trust \
--force \
https://github.com/whiteprints/template-python.git \
'{{ justfile_directory() }}/.just/test/{{ license }}/{{ python }}/tmp' \
--data project_name='test gh-pypi {{ kebabcase(license) }} {{ os() }} {{ python }}' \
--data author='Romain Brault' \
--data organisation='whiteprints-tests' \
--data author_email='mail@romainbrault.com' \
--data organisation_email='mail@romainbrault.com' \
--data code_license_id='{{ license }}' \
--data resources_license_id='{{ license }}' \
--data copyright_holder='Romain Brault' \
--data copyright_holder_email='mail@romainbrault.com' \
--data line_length='79' \
--data target_python_version='`echo \"py{{ python }}\" | tr -d .`'\
"
@just uvx "\
--with whiteprints-template-context \
copier copy \
--trust \
--force \
https://github.com/whiteprints/template-github.git \
'{{ justfile_directory() }}/.just/test/{{ license }}/{{ python }}/tmp'\
"
@just uvx "\
--with whiteprints-template-context \
copier copy \
--trust \
--force \
--vcs-ref HEAD \
'{{ justfile_directory() }}' \
'{{ justfile_directory() }}/.just/test/{{ license }}/{{ python }}/tmp'\
"
@just uvx "\
--directory '\
{{ justfile_directory() }}/\
.just/test/{{ license }}/{{ python }}/tmp\
' \
--from rust-just just all\
"

test-open-source python:
@just test {{ python }} "MIT OR Apache-2.0"

test-proprietary python:
@just test {{ python }} ""

all:
@just for-all-python test-open-source
@just for-all-python test-proprietary

# Run pre-commit
pre-commit args="":
@just uvx " \
--with pre-commit-uv \
pre-commit run \
--all-files \
--show-diff-on-failure \
{{ args }} \
"

# Run `reuse`
reuse args="":
@just uvx " \
reuse \
{{ args }} \
"

# Check licenses
check-licenses:
@just reuse lint
118 changes: 0 additions & 118 deletions tox.ini

This file was deleted.

0 comments on commit 7fde2d2

Please sign in to comment.