Skip to content

Commit 8394de3

Browse files
committed
refactor: migrate to ruff-only linting
1 parent 3df452f commit 8394de3

File tree

8 files changed

+58
-44
lines changed

8 files changed

+58
-44
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ name: CI
22

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

117
jobs:
128
test:
139
strategy:
1410
fail-fast: false
1511
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']
12+
python-version: ["3.10", "3.11", "3.12", "3.13"]
13+
os: [ubuntu-latest]
14+
vaultwarden-version: ["1.32.7", "1.33.2", "1.34.3"]
1915
runs-on: ${{ matrix.os }}
2016
steps:
2117
- uses: actions/checkout@v3
@@ -54,7 +50,7 @@ jobs:
5450
- name: Setup Python
5551
uses: actions/setup-python@v4
5652
with:
57-
python-version: '3.13'
53+
python-version: "3.13"
5854
- name: Install Python dependencies
5955
run: |
6056
python -m pip install --upgrade hatch
@@ -75,10 +71,11 @@ jobs:
7571
- name: Setup Python
7672
uses: actions/setup-python@v4
7773
with:
78-
python-version: '3.10'
74+
python-version: "3.10"
7975
- name: Install Hatch
8076
run: |
8177
python -m pip install -U hatch
8278
- name: Build package
8379
run: |
84-
hatch build
80+
hatch build
81+

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)