Skip to content

3 configure testing suite ii #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI
on:
workflow_dispatch:
push:
branches: ['main', 'develop']
pull_request:
jobs:
tests:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Setup uv and handle its cache
uses: hynek/setup-cached-uv@49a39f911c85c6ec0c9aadd5a426ae2761afaba2 # v2.0.0

- name: "Set up Python"
uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
with:
python-version: ${{ matrix.python-version }}

- name: Setup dependencies
run: |
uv pip install --system --break-system-packages -r ./.requirements/${{ matrix.python-version }}-${{ runner.os }}.txt
uv pip install --system --break-system-packages pytest pytest-md pytest-emoji

- name: Run pytest
uses: pavelzw/pytest-action@510c5e90c360a185039bea56ce8b3e7e51a16507 # v2.2.0
with:
custom-arguments: tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.12]
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.4
2 changes: 2 additions & 0 deletions .requirements/3.12-Linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --generate-hashes --python-version 3.12 --python-platform linux --output-file .requirements/3.12-Linux.txt
2 changes: 2 additions & 0 deletions .requirements/3.12-Windows.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --generate-hashes --python-version 3.12 --python-platform windows --output-file .requirements/3.12-Windows.txt
2 changes: 2 additions & 0 deletions .requirements/3.12-macOS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml --generate-hashes --python-version 3.12 --python-platform macos --output-file .requirements/3.12-macOS.txt
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY requirements:
requirements:
uv pip compile "pyproject.toml" --quiet --generate-hashes --python-version 3.12 --python-platform linux --output-file .requirements/3.12-Linux.txt
uv pip compile "pyproject.toml" --quiet --generate-hashes --python-version 3.12 --python-platform macos --output-file .requirements/3.12-macOS.txt
uv pip compile "pyproject.toml" --quiet --generate-hashes --python-version 3.12 --python-platform windows --output-file .requirements/3.12-Windows.txt
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# usethis-python
# usethis

Automate Python package and project setup tasks that are otherwise performed manually.

## Development

[![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)
71 changes: 71 additions & 0 deletions doc/philosophy/introspection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Introspection when developing

Nathan McDougall, August 2024.

When developing, so many of our actions are reflexive. If you are interesting in
developing usethis, then it is very valuable to slow down, and consider thoroughly
which actions you are undertaking. Some of them might be running off-the-shelf automated
tools. Sometimes you might be setting up bespoke configuration for those tools.
Other times, you might have to do something manually.

These are all useful points to note down and can provide a lot of insight into potential
features for usethis (besides just being useful documentation).

For example, when developing usethis, here are a list of actions that I undertook (not
necessarily listed chronologically):

## Toolset decisions

- Use GitHub Actions for CI.
- Always use the hash to pin the version of a GitHub action `uses:`
- Use uv for package management.

## Repo configuration

- Created a repo on GitHub wih template .gitignore, MIT license and README.
- Created a develop branch.
- Set up sensible rulesets for branches.
- Created a template for GitHub issues that are development tasks.
- Created a Makefile.
- Created a `make requirements` command to make platform-specific requirements files.
- Ran `uv init --name usethis`.
- Ran `uv python pin 3.12.4`.
- Created a `.requirements` directory with Python version and OS specific files.

## Add GitHub Actions CI

- Create a GitHub workflow file for CI manually in `.github/workflows/ci.yml`.
- Use the following configuration to support GitFlow-style branch management:

```yml
name: CI
on:
workflow_dispatch:
push:
branches: ['main', 'develop']
pull_request:
```

- Add <https://github.com/hynek/setup-cached-uv>.
- Add <https://github.com/actions/checkout>.
- Set up the GitHub actions matrix to use Ubuntu, Windows and MacOS.
- Set up the GitHub actions to use different Python versions.
- Set up logic to use uv in GitHub actions.

## Local development configuration

- Cloned the repo from GitHub.
- Ran `uv sync`.
- Set up git username, email, and signing key.

## Set up tests

- Ran `uv add --dev pytest`.
- Created a tests folder.
- Added a trivial test module `test_nothing.py`.
- Add a trivial test `test_pass` to the test module.
- Add step to CI to install pytest
- Add step to CI to install pytest-md and pytest-emoji (used by Action).
- Confirm pytest is working with `pytest tests` in the CLI.
- Add <https://github.com/pavelzw/pytest-action> to set up pytest in CI, using the
correct CLI args to pytest.
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "usethis"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = ["pytest>=8.3.2"]
2 changes: 2 additions & 0 deletions src/usethis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def hello() -> str:
return "Hello from usethis!"
2 changes: 2 additions & 0 deletions tests/test_nothing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_pass():
pass
66 changes: 66 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.