Skip to content

Commit 6b095e7

Browse files
Align package structure with scientific-python template (#16)
* draft * style: pre-commit fixes * mute pylint and mypy for later PR * use uv installer for hatch * fix test_physics_at_distance (typo was silencing test) * linter fix * pylint * style: pre-commit fixes * add openblas install for scipy * test uv install on ci * test uvx * update * set minimum python version to 3.11 * style: pre-commit fixes * add python 3.12 * lint * pypy-3.11 * use macos latest --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9f8cc41 commit 6b095e7

37 files changed

+2059
-1209
lines changed

.copier-answers.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
2+
_commit: 2025.01.22-34-g133af09
3+
_src_path: gh:scientific-python/cookie
4+
backend: hatch
5+
6+
full_name: Michael Ortner
7+
license: BSD
8+
org: magpylib
9+
project_name: magpylib-force
10+
project_short_description: Python package extending the Magpylib library that enables
11+
force and torque computationss.
12+
url: https://github.com/magpylib/magpylib-force
13+
vcs: true

.git_archival.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node: $Format:%H$
2+
node-date: $Format:%cI$
3+
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git_archival.txt export-subst

.github/CONTRIBUTING.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
See the [Scientific Python Developer Guide][spc-dev-intro] for a detailed
2+
description of best practices for developing scientific packages.
3+
4+
[spc-dev-intro]: https://learn.scientific-python.org/development/
5+
6+
# Quick development
7+
8+
The fastest way to start with development is to use nox. If you don't have nox,
9+
you can use `pipx run nox` to run it without installing, or `pipx install nox`.
10+
If you don't have pipx (pip for applications), then you can install with
11+
`pip install pipx` (the only case were installing an application with regular
12+
pip is reasonable). If you use macOS, then pipx and nox are both in brew, use
13+
`brew install pipx nox`.
14+
15+
To use, run `nox`. This will lint and test using every installed version of
16+
Python on your system, skipping ones that are not installed. You can also run
17+
specific jobs:
18+
19+
```console
20+
$ nox -s lint # Lint only
21+
$ nox -s tests # Python tests
22+
$ nox -s docs # Build and serve the docs
23+
$ nox -s build # Make an SDist and wheel
24+
```
25+
26+
Nox handles everything for you, including setting up an temporary virtual
27+
environment for each run.
28+
29+
# Setting up a development environment manually
30+
31+
You can set up a development environment by running:
32+
33+
```bash
34+
python3 -m venv .venv
35+
source ./.venv/bin/activate
36+
pip install -v -e .[dev]
37+
```
38+
39+
If you have the
40+
[Python Launcher for Unix](https://github.com/brettcannon/python-launcher), you
41+
can instead do:
42+
43+
```bash
44+
py -m venv .venv
45+
py -m install -v -e .[dev]
46+
```
47+
48+
# Pre-commit
49+
50+
You should prepare pre-commit, which will help you by checking that commits pass
51+
required checks:
52+
53+
```bash
54+
pip install pre-commit # or brew install pre-commit on macOS
55+
pre-commit install # Will install a pre-commit hook into the git repo
56+
```
57+
58+
You can also/alternatively run `pre-commit run` (changes only) or
59+
`pre-commit run --all-files` to check even without installing the hook.
60+
61+
# Testing
62+
63+
Use pytest to run the unit checks:
64+
65+
```bash
66+
pytest
67+
```
68+
69+
# Coverage
70+
71+
Use pytest-cov to generate coverage reports:
72+
73+
```bash
74+
pytest --cov=magpylib-force
75+
```
76+
77+
# Building docs
78+
79+
You can build and serve the docs using:
80+
81+
```bash
82+
nox -s docs
83+
```
84+
85+
You can build the docs only with:
86+
87+
```bash
88+
nox -s docs --non-interactive
89+
```

.github/TEMPLATES/template.yaml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
groups:
9+
actions:
10+
patterns:
11+
- "*"

.github/release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
changelog:
2+
exclude:
3+
authors:
4+
- dependabot
5+
- pre-commit-ci

.github/workflows/cd.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CD
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
release:
10+
types:
11+
- published
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
env:
18+
# Many color libraries just need this to be set to any value, but at least
19+
# one distinguishes color depth, where "3" -> "256-bit color".
20+
FORCE_COLOR: 3
21+
22+
jobs:
23+
dist:
24+
name: Distribution build
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- uses: hynek/build-and-inspect-python-package@v2
33+
34+
publish:
35+
needs: [dist]
36+
name: Publish to PyPI
37+
environment: pypi
38+
permissions:
39+
id-token: write
40+
attestations: write
41+
contents: read
42+
runs-on: ubuntu-latest
43+
if: github.event_name == 'release' && github.event.action == 'published'
44+
45+
steps:
46+
- uses: actions/download-artifact@v4
47+
with:
48+
name: Packages
49+
path: dist
50+
51+
- name: Generate artifact attestation for sdist and wheel
52+
uses: actions/[email protected]
53+
with:
54+
subject-path: "dist/*"
55+
56+
- uses: pypa/gh-action-pypi-publish@release/v1
57+
with:
58+
# Remember to tell (test-)pypi about this repo before publishing
59+
# Remove this line to publish to PyPI
60+
repository-url: https://test.pypi.org/legacy/

.github/workflows/ci.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
FORCE_COLOR: 3
16+
17+
jobs:
18+
pre-commit:
19+
name: Format
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- uses: astral-sh/setup-uv@v5
26+
- uses: pre-commit/[email protected]
27+
with:
28+
extra_args: --hook-stage manual --all-files
29+
- name: Run Pylint
30+
run: uvx nox -s pylint -- --output-format=github
31+
32+
checks:
33+
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
34+
runs-on: ${{ matrix.runs-on }}
35+
needs: [pre-commit]
36+
strategy:
37+
fail-fast: false
38+
matrix:
39+
python-version: ["3.11", "3.12", "3.13"]
40+
runs-on: [ubuntu-latest, windows-latest, macos-latest]
41+
42+
include:
43+
- python-version: "pypy-3.11"
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
51+
- name: Install OpenBLAS
52+
if: runner.os == 'Linux' && startsWith(matrix.python-version, 'pypy')
53+
run: sudo apt-get update && sudo apt-get install -y libopenblas-dev
54+
55+
- name: Install uv and set the python version
56+
uses: astral-sh/setup-uv@v5
57+
with:
58+
python-version: ${{ matrix.python-version }}
59+
60+
- name: Install dependencies with uv
61+
run: uv pip install .[test]
62+
63+
- name: Test package
64+
run: >-
65+
uv run pytest -ra --cov --cov-report=xml --cov-report=term
66+
--durations=20
67+
68+
- name: Upload coverage report
69+
uses: codecov/codecov-action@v5
70+
with:
71+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/publish.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)