Skip to content

Commit 9b5184d

Browse files
committed
refactor: migrate to ruff-only linting and add CI workflow
1 parent 3df452f commit 9b5184d

File tree

8 files changed

+75
-102
lines changed

8 files changed

+75
-102
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,39 @@ name: CI
22

33
on:
44
push:
5-
branches:
6-
- main
75
pull_request:
8-
branches:
9-
- main
106

117
jobs:
12-
test:
8+
lint:
9+
name: Lint with ruff
10+
runs-on: ubuntu-latest
1311
strategy:
14-
fail-fast: false
1512
matrix:
16-
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
17-
os: [ ubuntu-latest ]
18-
vaultwarden-version: [ '1.32.7', '1.33.2' , '1.34.3']
19-
runs-on: ${{ matrix.os }}
13+
python-version: ["3.10", "3.11", "3.12", "3.13"]
2014
steps:
21-
- uses: actions/checkout@v3
22-
with:
23-
lfs: true
24-
- name: Setup Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v4
15+
- uses: actions/checkout@v4
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v5
2618
with:
2719
python-version: ${{ matrix.python-version }}
28-
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade hatch
31-
- name: Run Vaultwarden server
32-
run: |
33-
temp_dir=$(mktemp -d)
34-
cp ${{ github.workspace }}/tests/fixtures/server/* $temp_dir
35-
docker run -d --name vaultwarden -v $temp_dir:/data --env I_REALLY_WANT_VOLATILE_STORAGE=true --env ADMIN_TOKEN=admin --restart unless-stopped -p 80:80 vaultwarden/server:${{ matrix.vaultwarden-version }}
36-
- name: Run tests
37-
run: |
38-
hatch run +py=${{ matrix.py || matrix.python-version }} test:with-coverage
39-
env:
40-
VAULTWARDEN_URL: "http://127.0.0.1:80"
41-
VAULTWARDEN_ADMIN_TOKEN: "admin"
42-
BITWARDEN_URL: "http://127.0.0.1:80"
43-
BITWARDEN_EMAIL: "test-account@example.com"
44-
BITWARDEN_PASSWORD: "test-account"
45-
BITWARDEN_CLIENT_ID: "user.a8be340c-856b-481f-8183-2b7712995da2"
46-
BITWARDEN_CLIENT_SECRET: "ag66paVUq4h7tBLbCbJOY5tJkQvUuT"
47-
BITWARDEN_TEST_ORGANIZATION: "cda840d2-1de0-4f31-bd49-b30dacd7e8b0"
48-
BITWARDEN_DEVICE_ID: "e54ba5f5-7d58-4830-8f2b-99194c70c14f"
20+
- name: Install hatch
21+
run: pip install hatch
22+
- name: Run ruff check
23+
run: hatch run style:check
4924

50-
lint:
51-
runs-on: ubuntu-latest
52-
steps:
53-
- uses: actions/checkout@v3
54-
- name: Setup Python
55-
uses: actions/setup-python@v4
56-
with:
57-
python-version: '3.13'
58-
- name: Install Python dependencies
59-
run: |
60-
python -m pip install --upgrade hatch
61-
- name: Check with black + isort
62-
if: always()
63-
run: hatch run style:format && git diff --exit-code
64-
- name: Check with ruff
65-
if: always()
66-
run: hatch run style:lint
67-
- name: Check with mypy
68-
if: always()
69-
run: hatch run types:check
70-
71-
package:
25+
test:
26+
name: Test
7227
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
python-version: ["3.10", "3.11", "3.12", "3.13"]
7331
steps:
74-
- uses: actions/checkout@v3
75-
- name: Setup Python
76-
uses: actions/setup-python@v4
32+
- uses: actions/checkout@v4
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v5
7735
with:
78-
python-version: '3.10'
79-
- name: Install Hatch
80-
run: |
81-
python -m pip install -U hatch
82-
- name: Build package
83-
run: |
84-
hatch build
36+
python-version: ${{ matrix.python-version }}
37+
- name: Install hatch
38+
run: pip install hatch
39+
- name: Run tests
40+
run: hatch run test:test

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,38 @@ You can now install the project and its dependencies using:
134134
```bash
135135
pip install -e .[test]
136136
```
137+
138+
### Code Style and Linting
139+
140+
This project uses [ruff](https://docs.astral.sh/ruff/) for both linting and code formatting. Before submitting a pull request, ensure your code follows the project's style guidelines.
141+
142+
To check for linting and formatting issues:
143+
```bash
144+
hatch run style:check
145+
```
146+
147+
To automatically fix linting issues and format your code:
148+
```bash
149+
hatch run style:format
150+
```
151+
152+
To only run linting (with auto-fix):
153+
```bash
154+
hatch run style:lint
155+
```
156+
137157
### Testing
138158
To run the tests, use:
139159

140160
```bash
141161
bash tests/e2e/run_tests.sh
142162
```
143163

164+
Or using hatch:
165+
```bash
166+
hatch run test:test
167+
```
168+
144169
## License
145170

146171
Python-vaultwarden is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.

pyproject.toml

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,51 +93,47 @@ check = "mypy src/vaultwarden"
9393
[tool.hatch.envs.style]
9494
detached = true
9595
dependencies = [
96-
"black",
97-
"isort",
9896
"ruff",
9997
]
10098
[tool.hatch.envs.style.scripts]
10199
lint = [
102-
"ruff check --fix src/vaultwarden",
100+
"ruff check --fix src/vaultwarden tests",
103101
]
104102
check = [
105-
"isort --check-only --diff src/vaultwarden",
106-
"black -q --check --diff src/vaultwarden",
107-
"ruff check src/vaultwarden",
103+
"ruff check src/vaultwarden tests",
104+
"ruff format --check src/vaultwarden tests",
108105
]
109106
format = [
110-
"isort -q src/vaultwarden",
111-
"black -q src/vaultwarden",
112-
"lint"
107+
"ruff format src/vaultwarden tests",
108+
"lint",
113109
]
114110

115111
[tool.ruff]
116-
# Add "Q" to the list of enabled codes.
117-
select = ["B", "E", "F", "I", "N", "Q", "RUF", "SIM", "TCH"]
118-
ignore = ["N815"]
119-
fixable = ["ALL"]
120112
src = ["src/vaultwarden", "tests"]
121113
exclude = ["src/vaultwarden/utils/crypto.py"]
122114
target-version = "py310"
123115
line-length = 79
124116

125-
[tool.ruff.flake8-quotes]
117+
[tool.ruff.lint]
118+
# Add "Q" to the list of enabled codes.
119+
select = ["B", "E", "F", "I", "N", "Q", "RUF", "SIM", "TCH"]
120+
ignore = ["N815"]
121+
fixable = ["ALL"]
122+
123+
[tool.ruff.lint.flake8-quotes]
126124
docstring-quotes = "double"
127125

128-
[tool.ruff.flake8-bugbear]
126+
[tool.ruff.lint.flake8-bugbear]
129127
extend-immutable-calls = ["typer.Argument"]
130128

131-
[tool.ruff.isort]
129+
[tool.ruff.lint.isort]
132130
force-sort-within-sections = true
133131

134-
[tool.black]
135-
line-length = 79
136-
target-version = ["py310", "py311"]
137-
138-
[tool.isort]
139-
profile = "black"
140-
line_length = 80
132+
[tool.ruff.format]
133+
quote-style = "double"
134+
indent-style = "space"
135+
skip-magic-trailing-comma = false
136+
line-ending = "auto"
141137

142138
[tool.mypy]
143139
ignore_missing_imports = true

src/vaultwarden/clients/bitwarden.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def __init__(
3434
self._http_client = Client(
3535
base_url=f"{self.url}/",
3636
event_hooks={"response": [log_raise_for_status]},
37-
headers={
38-
"Bitwarden-Client-Version": "2024.1.0"
39-
},
37+
headers={"Bitwarden-Client-Version": "2024.1.0"},
4038
timeout=timeout,
4139
)
4240
self._connect_token: ConnectToken | None = None

src/vaultwarden/models/sync.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ class UserProfile(PermissiveBaseModel):
8484
Providers: list
8585
SecurityStamp: str
8686
TwoFactorEnabled: bool
87+
# original Bitwarden doesn't support disabling users
8788
status: VaultwardenUserStatus = Field(
88-
default=VaultwardenUserStatus.Enabled, # original Bitwarden doesn't support disabling users
89-
validation_alias=AliasChoices("_status", "_Status")
89+
default=VaultwardenUserStatus.Enabled,
90+
validation_alias=AliasChoices("_status", "_Status"),
9091
)
9192

9293

tests/models/validation/test_bitwarden_models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import unittest
22

33
from pydantic import TypeAdapter
4-
54
from vaultwarden.models.bitwarden import (
5+
CollectionUser,
66
Organization,
7-
ResplistBitwarden,
87
OrganizationUserDetails,
9-
CollectionUser,
8+
ResplistBitwarden,
109
)
1110

1211

tests/models/validation/test_pascal_camel_cases.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import unittest
22

33
from pydantic import TypeAdapter
4-
54
from src.vaultwarden.models.sync import SyncData, VaultwardenUser
65
from vaultwarden.models.bitwarden import (
76
Organization,
8-
ResplistBitwarden,
97
OrganizationCollection,
8+
ResplistBitwarden,
109
)
1110

1211

tests/models/validation/test_vaultwarden_models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import unittest
22

33
from pydantic import TypeAdapter
4-
54
from vaultwarden.models.sync import VaultwardenUser
65

76

0 commit comments

Comments
 (0)