Skip to content

Commit

Permalink
Enhance dev docs
Browse files Browse the repository at this point in the history
Add `ruff` and `pyright` workflows
Update pyproject.toml
  • Loading branch information
qexat committed Apr 22, 2024
1 parent 580519d commit ebbe4ca
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 7 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Linting and formatting

on:
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: write

jobs:
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Lint
run: ruff check
- name: Format
run: ruff format
27 changes: 27 additions & 0 deletions .github/workflows/typechecking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Type checking

on:
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: write

jobs:
ruff:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
- name: Type checking
run: pyright
112 changes: 110 additions & 2 deletions README-dev.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
<!-- markdownlint-disable MD033 -->

# Notes to developers

Links: [Building docs](#building-docs) · [Testing](#testing) · [Bumping the version](#bumping-the-version) · [Building the wheel](#building) · [Releasing on PyPI](#releasing)

## Setting up the environment

Most commands in this document require dependencies. It is best to work on a
virtual environment to avoid interferences with your system-level Python
installation.

### Virtual environment

> **Qexat:** I advise to have [`virtualenv`](https://virtualenv.pypa.io/en/latest/) installed globally on your machine.
For everything except documentation, I recommend **using the lowest Python
version that Magic List supports**, i.e. 3.9 at the time of writing.

```sh
virtualenv .venv -ppython39
source .venv/bin/activate.fish # remove `.fish` if you use bash
```

Since documentation uses the type stubs, which is written with the new syntax
features of more recent versions of Python, they should be built with the
latest one.

```sh
virtualenv .venv-docs -ppython312
source .venv-docs/bin/activate.fish # remove `.fish` if you use bash
```

### Local editable installation

Since you intend to work on Magic List, you will use the editable installation
(`-e`) feature of `pip`.
You will also need the development dependencies (`[dev]`).

```sh
pip install -e .[dev]
```

---

## Contributing

<sup>Dependencies: `pre-commit`, `pyright`</sup>

First of all, thank you for your contribution 💞

- Types are checked against the [Pyright](https://github.com/microsoft/pyright) static type checker.
- Linting and formatting are handled by [Ruff](https://github.com/astral-sh/ruff).
- Few other checks are performed as well using [pre-commit](https://pre-commit.com).

In order to provide some guarantees on code quality, they will be enforced on your pull requests.
They are not meant to dissuade people from contributing, but **to prevent common bugs and mistakes**,
as well as to fulfill the common guidelines of Python.

## Building docs

<sup>Dependencies: `pdoc`</sup>

Documentation is automatically built on every pull request, and deployed at
every commit on the `main` branch. The command is provided in case you need to
run them manually and/or locally.

```sh
pdoc magic_list/ -n -d numpy -o docs/
```

## Testing

Tests are automatically run on pull requests.
<sup>Dependencies: `pytest`, `coverage`</sup>

Tests are automatically run on pull requests. Here are the commands in case
you need to run them manually/locally.

### Run tests

Expand All @@ -16,18 +88,54 @@ coverage run -m pytest
coverage report --show-missing --fail-under=100
```

> **Qexat:** personally, I have a shell alias `report` to that command.
## Bumping the version

**It should be done via a PR so the docs get updated upon merging.**

Magic List carefully follows semantic versioning:

- if there are breaking changes, increment the major number
- if there are a few new features, increment the minor number
- if there are only bug fixes, increment the patch number

Regarding bug fixes, it is best if a patch version is released for each.

It is manual for now, but I am not opposed to automate the process if you have
compelling arguments.

## Releasing

PyPI Releases are automatically done when making a GitHub release.
<sup>Dependencies: `build`, `twine`</sup>

> [!WARNING]
> Do NOT make a release if at least one of the status checks are failing.
Once you have [locally built](#building) the wheel, make a release on GitHub including it.
You can check past releases to see how it was done. **Make sure to have bumped
the version beforehand.**

> [!NOTE]
> A GitHub action will handle uploading it to the PyPI.
### Building

To build locally, run the following command:

```sh
python -m build
```

### Uploading to the PyPI

In case the GitHub action is unavailable for one reason or another:

```sh
twine upload dist/* --skip-existing
```

---

Written with 🩷 by [Qexat](https://github.com/qexat).
Thank you for your kind contribution to this project!
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ repository = "https://github.com/qexat/magic-list"

[project.optional-dependencies]
dev = [
"build==1.2.*",
"coverage==7.4.*",
"pdoc==14.4.*",
"build>=1.2,<2.0",
"coverage>=7.4,<8.0",
"pdoc>=14.4,<15.0",
"pre-commit>=3.7,<4.0",
"pytest>=7.4,<8.2",
"pyright==1.1.*",
"twine==5.0.*",
"pyright>=1.1,<2.0",
"ruff>=0.4,<1.0",
"twine>=5.0,<6.0",
]

[build-system]
Expand Down

0 comments on commit ebbe4ca

Please sign in to comment.