Skip to content

Commit 03b862a

Browse files
sdwilshofek
andauthored
Python ufmt fixes (#2)
Co-authored-by: Ofek Lev <[email protected]>
1 parent d506289 commit 03b862a

File tree

8 files changed

+59
-22
lines changed

8 files changed

+59
-22
lines changed

.devcontainer/devcontainer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
"extensions": [
1010
"GitHub.vscode-github-actions",
1111
"ms-python.python",
12-
"nefrob.vscode-just-syntax"
12+
"nefrob.vscode-just-syntax",
13+
"omnilib.ufmt"
1314
],
1415
"settings": {
1516
"python.analysis.include": [
1617
"python/**"
1718
],
19+
"python.defaultInterpreterPath": ".venv/bin/python3",
20+
"python.editor.defaultFormatter": "omnilib.ufmt",
21+
"python.editor.formatOnSave": true,
22+
"python.terminal.activateEnvInCurrentTerminal": true,
1823
"rust-analyzer.linkedProjects": [
1924
"./Cargo.toml"
2025
]
@@ -31,5 +36,8 @@
3136
"ghcr.io/devcontainers/features/rust:1": {},
3237
"ghcr.io/devcontainers-extra/features/devcontainers-cli:1": {},
3338
"ghcr.io/guiyomh/features/just:0": {}
39+
},
40+
"postCreateCommand": {
41+
"installPythonDependencies": "cd /workspaces/dotslash/python && uv venv --no-project && uv pip install -r requirements-fmt.txt"
3442
}
3543
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Python
88
__pycache__/
9-
/python/.ruff_cache/
9+
.venv/
1010
*.pyc
1111

1212
# Node.js

Justfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ test-feature-scenarios:
5252
[group('Downstream')]
5353
[working-directory: 'python']
5454
check-python:
55-
uvx ruff check
56-
uvx ruff format --check --diff
55+
uv run --no-project --with-requirements requirements-fmt.txt -- ufmt diff src tests
56+
uv run --no-project --with-requirements requirements-fmt.txt -- ufmt check src tests
5757

5858
# Fix static analysis issues for the Python package.
5959
[group('Downstream')]
6060
[working-directory: 'python']
6161
fix-python:
62-
uvx ruff check --fix
63-
uvx ruff format
62+
uv run --no-project --with-requirements requirements-fmt.txt -- ufmt format src tests
6463

6564
# Test the Python package.
6665
[group('Downstream')]

python/hatch_build.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from contextlib import contextmanager
1313
from functools import cached_property
1414
from platform import machine
15-
from typing import TYPE_CHECKING, Any, BinaryIO
15+
from typing import Any, BinaryIO, TYPE_CHECKING
1616

1717
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1818
from hatchling.metadata.plugin.interface import MetadataHookInterface
@@ -34,7 +34,9 @@ def update(self, metadata: dict[str, Any]) -> None:
3434
"Accept": "application/vnd.github+json",
3535
"X-GitHub-Api-Version": "2022-11-28",
3636
}
37-
if github_token := (os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")):
37+
if github_token := (
38+
os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")
39+
):
3840
headers["Authorization"] = f"Bearer {github_token}"
3941

4042
with http_get(
@@ -49,12 +51,16 @@ def update(self, metadata: dict[str, Any]) -> None:
4951

5052

5153
class CustomBuildHook(BuildHookInterface):
52-
def initialize(self, version: str, build_data: dict[str, Any]) -> None: # noqa: ARG002
54+
def initialize(
55+
self, version: str, build_data: dict[str, Any]
56+
) -> None: # noqa: ARG002
5357
if self.__source == "release":
5458
asset = self.__release_asset
5559
elif os.path.isdir(self.__source):
5660
asset = self.__local_asset
57-
elif not os.path.isabs(self.__source) and os.path.isfile(os.path.join(self.root, "PKG-INFO")):
61+
elif not os.path.isabs(self.__source) and os.path.isfile(
62+
os.path.join(self.root, "PKG-INFO")
63+
):
5864
msg = (
5965
"The current directory has a `PKG-INFO` file, which likely means that the wheel is being "
6066
"built from an unpacked source distribution. You must do one of the following:\n"
@@ -79,7 +85,9 @@ def initialize(self, version: str, build_data: dict[str, Any]) -> None: # noqa:
7985
build_data["shared_scripts"][self.__binary_path] = self.__binary_name
8086
build_data["tag"] = f"py3-none-{self.__wheel_arch}"
8187

82-
def finalize(self, version: str, build_data: dict[str, Any], artifact: str) -> None: # noqa: ARG002
88+
def finalize(
89+
self, version: str, build_data: dict[str, Any], artifact: str
90+
) -> None: # noqa: ARG002
8391
import shutil
8492

8593
shutil.rmtree(self.__temp_dir)
@@ -121,9 +129,15 @@ def __arch(self) -> str:
121129
def __target_data(self) -> tuple[str, str]:
122130
match self.__platform, self.__arch:
123131
case "linux", "aarch64":
124-
return "dotslash-linux-musl.aarch64.tar.gz", self.__get_linux_wheel_arch()
132+
return (
133+
"dotslash-linux-musl.aarch64.tar.gz",
134+
self.__get_linux_wheel_arch(),
135+
)
125136
case "linux", "x86_64":
126-
return "dotslash-linux-musl.x86_64.tar.gz", self.__get_linux_wheel_arch()
137+
return (
138+
"dotslash-linux-musl.x86_64.tar.gz",
139+
self.__get_linux_wheel_arch(),
140+
)
127141
case "windows", "arm64":
128142
return "dotslash-windows-arm64.tar.gz", "win_arm64"
129143
case "windows", "amd64":
@@ -146,7 +160,9 @@ def __wheel_arch(self) -> str:
146160

147161
@cached_property
148162
def __source(self) -> str:
149-
return os.environ.get("DOTSLASH_SOURCE") or self.config.get("source") or "release"
163+
return (
164+
os.environ.get("DOTSLASH_SOURCE") or self.config.get("source") or "release"
165+
)
150166

151167
@cached_property
152168
def __temp_dir(self) -> str:

python/pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,13 @@ repair-wheel-command = ""
6969

7070
[tool.cibuildwheel.linux]
7171
environment-pass = ["DOTSLASH_SOURCE", "DOTSLASH_VERSION"]
72+
73+
[tool.black]
74+
target-version = ["py310"]
75+
76+
[tool.usort]
77+
first_party_detection = false
78+
79+
[tool.ufmt]
80+
formatter = "ruff-api"
81+
sorter = "ruff-api"

python/requirements-fmt.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# generated by `pyfmt --requirements`
2+
black==24.4.2
3+
ruff-api==0.1.0
4+
stdlibs==2024.1.28
5+
ufmt==2.8.0
6+
usort==1.0.8.post1
7+

python/ruff.toml

Lines changed: 0 additions & 7 deletions
This file was deleted.

python/tests/test_cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414

1515
def test_cli() -> None:
16-
result = subprocess.run([sys.executable, "-m", "dotslash", "--version"], capture_output=True, encoding="utf-8")
16+
result = subprocess.run(
17+
[sys.executable, "-m", "dotslash", "--version"],
18+
capture_output=True,
19+
encoding="utf-8",
20+
)
1721
output = result.stdout.strip()
1822
assert result.returncode == 0, output
1923

0 commit comments

Comments
 (0)