Skip to content

Commit ad575f2

Browse files
3 configure testing suite ii (#5)
* Init package, add pytest, GitHub actions config Some documation about the need for introspection when working on this. * Fix reference to .venv folder in ci.yml * Install Python via uv in ci.yml. * Improving process documentation. * Use system Python in CI for uv * Try custom lockfile approach for now. * Add missing $ syntax. * Add missing requirements files. * Synchronize capitalization of requirements files with GitHub actions. * Fix typo in CI path to .requirements dir. * Add relative path spec * Add debug ls statement in CI * Fix capitalization of requirements files and remove debug line. * Remove --system in `uv pip install` commands in ci.yml * Use --system --break-system-packages * Update actions/checkout and pin * Use --user instead of --system * Set up Python version with GitHub action.
1 parent 5d0cbbb commit ad575f2

File tree

12 files changed

+207
-1
lines changed

12 files changed

+207
-1
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: ['main', 'develop']
6+
pull_request:
7+
jobs:
8+
tests:
9+
runs-on: ${{ matrix.os }}
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
13+
14+
- name: Setup uv and handle its cache
15+
uses: hynek/setup-cached-uv@49a39f911c85c6ec0c9aadd5a426ae2761afaba2 # v2.0.0
16+
17+
- name: "Set up Python"
18+
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- name: Setup dependencies
23+
run: |
24+
uv pip install --system --break-system-packages -r ./.requirements/${{ matrix.python-version }}-${{ runner.os }}.txt
25+
uv pip install --system --break-system-packages pytest pytest-md pytest-emoji
26+
27+
- name: Run pytest
28+
uses: pavelzw/pytest-action@510c5e90c360a185039bea56ce8b3e7e51a16507 # v2.2.0
29+
with:
30+
custom-arguments: tests
31+
strategy:
32+
matrix:
33+
os: [ubuntu-latest, macos-latest, windows-latest]
34+
python-version: [3.12]

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12.4

.requirements/3.12-Linux.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile pyproject.toml --generate-hashes --python-version 3.12 --python-platform linux --output-file .requirements/3.12-Linux.txt

.requirements/3.12-Windows.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile pyproject.toml --generate-hashes --python-version 3.12 --python-platform windows --output-file .requirements/3.12-Windows.txt

.requirements/3.12-macOS.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile pyproject.toml --generate-hashes --python-version 3.12 --python-platform macos --output-file .requirements/3.12-macOS.txt

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.PHONY requirements:
2+
requirements:
3+
uv pip compile "pyproject.toml" --quiet --generate-hashes --python-version 3.12 --python-platform linux --output-file .requirements/3.12-Linux.txt
4+
uv pip compile "pyproject.toml" --quiet --generate-hashes --python-version 3.12 --python-platform macos --output-file .requirements/3.12-macOS.txt
5+
uv pip compile "pyproject.toml" --quiet --generate-hashes --python-version 3.12 --python-platform windows --output-file .requirements/3.12-Windows.txt

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
# usethis-python
1+
# usethis
2+
23
Automate Python package and project setup tasks that are otherwise performed manually.
4+
5+
## Development
6+
7+
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)

doc/philosophy/introspection.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Introspection when developing
2+
3+
Nathan McDougall, August 2024.
4+
5+
When developing, so many of our actions are reflexive. If you are interesting in
6+
developing usethis, then it is very valuable to slow down, and consider thoroughly
7+
which actions you are undertaking. Some of them might be running off-the-shelf automated
8+
tools. Sometimes you might be setting up bespoke configuration for those tools.
9+
Other times, you might have to do something manually.
10+
11+
These are all useful points to note down and can provide a lot of insight into potential
12+
features for usethis (besides just being useful documentation).
13+
14+
For example, when developing usethis, here are a list of actions that I undertook (not
15+
necessarily listed chronologically):
16+
17+
## Toolset decisions
18+
19+
- Use GitHub Actions for CI.
20+
- Always use the hash to pin the version of a GitHub action `uses:`
21+
- Use uv for package management.
22+
23+
## Repo configuration
24+
25+
- Created a repo on GitHub wih template .gitignore, MIT license and README.
26+
- Created a develop branch.
27+
- Set up sensible rulesets for branches.
28+
- Created a template for GitHub issues that are development tasks.
29+
- Created a Makefile.
30+
- Created a `make requirements` command to make platform-specific requirements files.
31+
- Ran `uv init --name usethis`.
32+
- Ran `uv python pin 3.12.4`.
33+
- Created a `.requirements` directory with Python version and OS specific files.
34+
35+
## Add GitHub Actions CI
36+
37+
- Create a GitHub workflow file for CI manually in `.github/workflows/ci.yml`.
38+
- Use the following configuration to support GitFlow-style branch management:
39+
40+
```yml
41+
name: CI
42+
on:
43+
workflow_dispatch:
44+
push:
45+
branches: ['main', 'develop']
46+
pull_request:
47+
```
48+
49+
- Add <https://github.com/hynek/setup-cached-uv>.
50+
- Add <https://github.com/actions/checkout>.
51+
- Set up the GitHub actions matrix to use Ubuntu, Windows and MacOS.
52+
- Set up the GitHub actions to use different Python versions.
53+
- Set up logic to use uv in GitHub actions.
54+
55+
## Local development configuration
56+
57+
- Cloned the repo from GitHub.
58+
- Ran `uv sync`.
59+
- Set up git username, email, and signing key.
60+
61+
## Set up tests
62+
63+
- Ran `uv add --dev pytest`.
64+
- Created a tests folder.
65+
- Added a trivial test module `test_nothing.py`.
66+
- Add a trivial test `test_pass` to the test module.
67+
- Add step to CI to install pytest
68+
- Add step to CI to install pytest-md and pytest-emoji (used by Action).
69+
- Confirm pytest is working with `pytest tests` in the CLI.
70+
- Add <https://github.com/pavelzw/pytest-action> to set up pytest in CI, using the
71+
correct CLI args to pytest.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[project]
2+
name = "usethis"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = []
8+
9+
[build-system]
10+
requires = ["hatchling"]
11+
build-backend = "hatchling.build"
12+
13+
[tool.uv]
14+
dev-dependencies = ["pytest>=8.3.2"]

src/usethis/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def hello() -> str:
2+
return "Hello from usethis!"

tests/test_nothing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_pass():
2+
pass

uv.lock

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)