Skip to content

Commit 846b6f0

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 846b6f0

31 files changed

+712
-243
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 13 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/actions@v3.0.1
26+
- name: prek
27+
uses: j178/prek-action@v1
2328

2429
- name: pyright
25-
uses: jakebailey/pyright-action@v2
26-
27-
- name: pylint
28-
run: pylint zmk
30+
uses: jakebailey/pyright-action@v3

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-python@v5
13+
- uses: actions/checkout@v6
14+
- uses: actions/setup-python@v6
1515
with:
16-
python-version: ">=3.10"
16+
python-version-file: "pyproject.toml"
1717
- name: Install pypa/build
1818
run: python3 -m pip install build --user
1919
- name: Build wheel and source tarball
2020
run: python3 -m build
2121
- name: Store distribution packages
22-
uses: actions/upload-artifact@v4
22+
uses: actions/upload-artifact@v6
2323
with:
2424
name: python-package-distributions
2525
path: dist/
@@ -37,7 +37,7 @@ jobs:
3737

3838
steps:
3939
- name: Download artifacts
40-
uses: actions/download-artifact@v4
40+
uses: actions/download-artifact@v7
4141
with:
4242
name: python-package-distributions
4343
path: dist/
@@ -61,7 +61,7 @@ jobs:
6161
name: python-package-distributions
6262
path: dist/
6363
- name: Sign artifacts
64-
uses: sigstore/gh-action-sigstore-python@v3.0.0
64+
uses: sigstore/gh-action-sigstore-python@v3.2.0
6565
with:
6666
inputs: >-
6767
./dist/*.tar.gz

.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 & 87 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.
55-
56-
## Install pipx
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).
5712

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 command to install ZMK CLI:
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,44 @@ 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 virtual environment and install dependencies
209+
uv sync
210+
# Install pre-commit hooks
211+
uv run prek install
212+
```
213+
214+
To run the development version of the program, either prefix commands with `uv run`...
215+
216+
```sh
217+
uv run zmk <args...>
218+
```
219+
220+
...or [activate the virtual environment](https://docs.astral.sh/uv/pip/environments/#using-a-virtual-environment) first, and then you can use just `zmk`.
221+
222+
If you want `zmk` to run the development version even when you are not inside the virtual environment, you can install it globally in editable mode:
223+
224+
```sh
225+
uv tool install -e .
226+
```
276227

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.
228+
## Linting
278229

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

281232
```sh
282-
pip install -e ".[dev]"
283-
pre-commit install
233+
# lint codebase
234+
uv run ruff check
235+
# format files
236+
uv run ruff format
284237
```
285238

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:
239+
Type checking is slower and difficult to configure to run as a Git commit hook, so this needs to be run manually.
287240

288241
```sh
289-
pyright .
290-
pylint zmk
242+
uv run pyright .
291243
```
292244

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

0 commit comments

Comments
 (0)