Skip to content

Commit 82a237e

Browse files
committed
chore: Switch tooling to uv, ruff, prek
Switched from Pip to uv for package management, Black, isort, and Pylint to Ruff for linting and formatting, and pre-commit to prek for commit hooks. These are faster and/or easier to work with. Added an initial set of Ruff checks and updated the codebase to address issues detected by them. The minimum Python version of 3.10 was originally set based on what is provided with Ubuntu 22.04 LTS. Now that we're instructing users to install ZMK CLI with uv though, we're no longer dependent on the system Python version. Updated to 3.11 to remove the need for the StrEnum backport.
1 parent 7c4e2d2 commit 82a237e

30 files changed

+702
-233
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ jobs:
88
lint:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v4
12-
- uses: actions/setup-python@v5
11+
- uses: actions/checkout@v6
12+
13+
- name: Setup Python
14+
uses: actions/setup-python@v6
15+
with:
16+
python-version-file: "pyproject.toml"
17+
18+
- name: Setup uv
19+
uses: astral-sh/setup-uv@v7
1320
with:
14-
python-version: ">=3.10"
15-
cache: "pip"
21+
enable-cache: true
22+
1623
- name: Install dependencies
17-
run: |
18-
pip install .
19-
pip install pylint
24+
run: uv sync --locked --all-extras --dev
2025

21-
- name: pre-commit
22-
uses: pre-commit/[email protected]
26+
- name: prek
27+
uses: j178/prek-action@v1
2328

2429
- name: pyright
2530
uses: jakebailey/pyright-action@v2
26-
27-
- name: pylint
28-
run: pylint zmk

.pre-commit-config.yaml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
fail_fast: false
22
repos:
3-
- repo: https://github.com/asottile/pyupgrade
4-
rev: v3.21.2
3+
- repo: https://github.com/astral-sh/ruff-pre-commit
4+
rev: v0.15.2
55
hooks:
6-
- id: pyupgrade
7-
args: [--py310-plus]
8-
- repo: https://github.com/pycqa/isort
9-
rev: "7.0.0"
10-
hooks:
11-
- id: isort
12-
- repo: https://github.com/psf/black
13-
rev: "25.12.0"
14-
hooks:
15-
- id: black
6+
- id: ruff-check
7+
- id: ruff-format
168
- repo: https://github.com/Lucas-C/pre-commit-hooks
17-
rev: v1.5.5
9+
rev: v1.5.6
1810
hooks:
1911
- id: remove-tabs
2012
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -26,7 +18,7 @@ repos:
2618
- id: check-added-large-files
2719
- id: check-shebang-scripts-are-executable
2820
- repo: https://github.com/tombi-toml/tombi-pre-commit
29-
rev: v0.7.14
21+
rev: v0.7.32
3022
hooks:
3123
- id: tombi-format
3224
- id: tombi-lint

.vscode/extensions.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"recommendations": [
3-
"ms-python.black-formatter",
4-
"ms-python.isort",
5-
"ms-python.python"
6-
]
2+
"recommendations": ["charliermarsh.ruff", "ms-python.python"]
73
}

.vscode/settings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"editor.formatOnSave": true,
33
"[python]": {
4-
"editor.defaultFormatter": "ms-python.black-formatter",
4+
"editor.defaultFormatter": "charliermarsh.ruff",
55
"editor.codeActionsOnSave": {
6-
"source.organizeImports": "always"
6+
"source.organizeImports": "explicit"
77
}
88
},
99
"[markdown][yaml]": {
@@ -20,8 +20,8 @@
2020
"**/templates/shield/**": "mako",
2121
"**/templates/common/**": "mako"
2222
},
23-
"isort.check": true,
24-
"isort.args": ["--settings-path", "${workspaceFolder}"],
23+
"pylint.enabled": false,
24+
"ruff.enabled": true,
2525
"python.analysis.importFormat": "relative",
2626
"python.analysis.typeCheckingMode": "standard",
2727
"python-envs.pythonProjects": []

README.md

Lines changed: 39 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,100 +8,30 @@ The instructions below contain commands that need to be run in a terminal progra
88

99
# Installation
1010

11-
## Install Git
12-
13-
Install Git from https://git-scm.com/downloads.
14-
15-
If you have Windows 11, you can instead open a terminal and run:
16-
17-
```sh
18-
winget install git.git -i
19-
```
20-
21-
The Windows installer will give you lots of options. You can leave all of them as their defaults, but when you get to the "choosing the default editor used by Git" screen, you may want to select a different text editor to use when writing Git commit messages.
22-
23-
## Install Python
24-
25-
ZMK CLI requires Python 3.10 or newer.
26-
27-
### On Windows and macOS
28-
29-
Install the latest version of Python from https://www.python.org/downloads/.
30-
31-
If you have Windows 11, you can instead open a terminal and run:
32-
33-
```sh
34-
winget install python3
35-
```
36-
37-
### On Linux
38-
39-
Most Linux distributions come with Python already installed. Open a terminal and run the following command to check its version:
40-
41-
```sh
42-
python3 --version
43-
```
44-
45-
If Python is not installed, install `python3` with your package manager.
46-
47-
If the version is older than 3.10, you will need to find and install a package for a newer version of Python. On Ubuntu 20.04 and older, you can get Python 3.10 from the deadsnakes PPA with the following commands:
48-
49-
```sh
50-
sudo add-apt-repository ppa:deadsnakes/ppa
51-
sudo apt install python3.10
52-
```
53-
54-
You will then need to replace `python3` with `python3.10` in the rest of the installation instructions.
11+
This readme will provide brief instructions for installing ZMK CLI. For instructions in more detail, see the [ZMK Documentation](https://zmk.dev/docs/user-setup).
5512

56-
## Install pipx
57-
58-
ZMK CLI can be installed with pip, but using [pipx](https://github.com/pypa/pipx) is recommended to avoid conflicts between Python packages.
59-
60-
### On Windows and Linux
61-
62-
Open a terminal and run:
63-
64-
```sh
65-
python3 -m pip install --user pipx
66-
python3 -m pipx ensurepath
67-
```
68-
69-
Some Linux distributions may disallow installing packages with pip. If this gives you an error, see the [install instructions](https://github.com/pypa/pipx?tab=readme-ov-file#on-linux) specific to your distribution.
70-
71-
Close and reopen your terminal, then run the following command. It should print a version number if everything is installed correctly:
13+
## Install Git
7214

73-
```sh
74-
pipx --version
75-
```
15+
Install Git from https://git-scm.com/downloads or your OS's package manager.
7616

77-
### On macOS
17+
You will also need a [GitHub account](https://github.com/signup).
7818

79-
Open Terminal and run:
19+
## Install uv
8020

81-
```
82-
brew install pipx
83-
pipx ensurepath
84-
```
21+
Install uv from https://docs.astral.sh/uv/getting-started/installation/
8522

8623
## Install ZMK CLI
8724

88-
Next, run the following commands:
25+
Run the following
8926

9027
```sh
91-
pipx install zmk
92-
zmk --help
28+
uv tool install zmk
9329
```
9430

95-
It should print a help message if everything installed correctly.
96-
97-
On Linux, you may get an error saying you need to install another package such as `python3.10-venv`. If so, follow the instructions in the error message, then try the above commands again.
98-
99-
## Update ZMK CLI
100-
10131
If you have already installed ZMK CLI, you can update to the latest version with the following command:
10232

10333
```sh
104-
pipx upgrade zmk
34+
uv tool upgrade zmk
10535
```
10636

10737
# Usage
@@ -272,22 +202,45 @@ zmk config user.home ~/Documents/zmk-config
272202

273203
# Development
274204

275-
If you would like to help improve ZMK CLI, you can clone this repo and install it in editable mode so your changes to the code apply when you run `zmk`. First, open a terminal to the root directory of the repository.
205+
If you would like to help improve ZMK CLI, you can clone this repo and install it into a virtual environment where you can modify it. First, open a terminal to the root directory of the repository. Then, create a virtual environment and install the project's dependencies:
206+
207+
```sh
208+
# Create the virtual environment
209+
uv venv .venv
210+
# This will print a message like "Activate with: source .venv/Scripts/activate"
211+
# If it prints a command that's different than the one shown here, run that instead.
212+
source .venv/Scripts/activate
213+
# Install dependencies
214+
uv sync
215+
# Install pre-commit hooks
216+
prek install
217+
```
218+
219+
Running `zmk` while inside the virtual environment will run the development version of the program, so you can make and test changes to the code.
220+
221+
Note that you will need to run the "activate" command again every time you open a new terminal (some IDEs such as VS Code will automate this for you). Alternatively, you can use `uv run zmk` to run the program instead of just `zmk`, which will automatically enter the virtual environment, run `zmk`, and then exit it.
222+
223+
If you want `zmk` to run the development version even when you are not inside the virtual environment, you can install it globablly in editable mode:
224+
225+
```sh
226+
uv tool install -e .
227+
```
276228

277-
You may optionally run the following commands inside a [virtual environment](https://docs.python.org/3/library/venv.html) if you don't want to install ZMK CLI's dependencies globally or if your OS disallows doing this.
229+
## Linting
278230

279-
To install ZMK CLI in editable mode, run:
231+
After running `prek install`, linting and code formatting will be run automatically when you make a commit. You can also run these tools manually:
280232

281233
```sh
282-
pip install -e ".[dev]"
283-
pre-commit install
234+
# lint codebase
235+
ruff check
236+
# format files
237+
ruff format
284238
```
285239

286-
After running `pre-commit install`, your code will be checked when you make a commit, but there are some slower checks that do not run automatically. To run these additional checks, run these commands:
240+
Type checking is slower and difficult to configure to run as a Git commit hook, so this needs to be run manually.
287241

288242
```sh
289243
pyright .
290-
pylint zmk
291244
```
292245

293246
GitHub will also run these checks and report any errors when you make a pull request.

pyproject.toml

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
name = "zmk"
33
description = "A command line program to help set up ZMK Firmware"
44
readme = "README.md"
5-
requires-python = ">=3.10"
6-
license = { file = "LICENSE" }
5+
requires-python = ">=3.11"
6+
license-files = ["LICENSE"]
77
classifiers = [
88
"Development Status :: 3 - Alpha",
99
"Environment :: Console",
@@ -15,11 +15,10 @@ classifiers = [
1515
"Topic :: Utilities",
1616
]
1717
dependencies = [
18-
"backports.strenum; python_version < '3.11'",
1918
"dacite >= 1.9.2, < 2.0.0",
2019
"giturlparse >= 0.14.0, < 0.15.0",
2120
"mako >= 1.3.10, < 2.0.0",
22-
"rich >= 14.2.0, < 15.0.0",
21+
"rich >= 14.3.3, < 15.0.0",
2322
"ruamel.yaml >= 0.18.17, < 0.19.0",
2423
"shellingham >= 1.5.4, < 2.0.0",
2524
"typer >= 0.21.0, < 0.22.0",
@@ -36,30 +35,62 @@ Documentation = "https://zmk.dev/docs"
3635
[project.scripts]
3736
zmk = "zmk.main:app"
3837

39-
[project.optional-dependencies]
40-
dev = ["pre-commit", "pylint", "pyright"]
38+
[dependency-groups]
39+
dev = [
40+
"prek>=0.3.3",
41+
"pyright>=1.1.408",
42+
"ruff>=0.15.2",
43+
]
4144

4245
[build-system]
4346
requires = ["setuptools", "setuptools-scm"]
4447
build-backend = "setuptools.build_meta"
4548

46-
[tool.isort]
47-
profile = "black"
48-
49-
[tool.pylint.MAIN]
50-
ignore = "_version.py"
51-
52-
[tool.pylint."MESSAGES CONTROL"]
53-
disable = [
54-
"arguments-differ", # Covered by pyright
55-
"fixme",
56-
"too-few-public-methods",
57-
"too-many-arguments",
58-
"too-many-branches",
59-
"too-many-instance-attributes",
60-
"too-many-locals",
61-
"too-many-positional-arguments",
62-
"too-many-statements",
49+
[tool.ruff.lint]
50+
select = [
51+
# flake8-builtins
52+
"A",
53+
# flake8-bugbear
54+
"B",
55+
# flake8-blind-except
56+
"BLE",
57+
# flake8-comprehensions
58+
"C4",
59+
# pycodestyle
60+
"E4",
61+
"E7",
62+
"E9",
63+
# pyflakes
64+
"F",
65+
# flake8-boolean-trap
66+
"FBT",
67+
# refurb
68+
"FURB",
69+
# flake8-implicit-str-concat
70+
"ISC",
71+
# pep8-naming
72+
"N",
73+
# perflint
74+
"PERF1",
75+
"PERF4",
76+
# flake8-pie
77+
"PIE",
78+
# flake8-use-pathlib
79+
"PTH",
80+
# flake8-return
81+
"RET",
82+
# ruff
83+
"RUF",
84+
# flake8-bandit
85+
# "S", TODO: enable this and fix issues in a separate commit
86+
# flake8-simplify
87+
"SIM",
88+
# flake8-self
89+
"SLF",
90+
# flake8-type-checking
91+
"TC",
92+
# pyupgrade
93+
"UP"
6394
]
6495

6596
[tool.setuptools]

0 commit comments

Comments
 (0)