diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b8697ef..2dda037 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,12 +9,17 @@ "extensions": [ "GitHub.vscode-github-actions", "ms-python.python", - "nefrob.vscode-just-syntax" + "nefrob.vscode-just-syntax", + "omnilib.ufmt" ], "settings": { "python.analysis.include": [ "python/**" ], + "python.defaultInterpreterPath": ".venv/bin/python3", + "python.editor.defaultFormatter": "omnilib.ufmt", + "python.editor.formatOnSave": true, + "python.terminal.activateEnvInCurrentTerminal": true, "rust-analyzer.linkedProjects": [ "./Cargo.toml" ] @@ -31,5 +36,8 @@ "ghcr.io/devcontainers/features/rust:1": {}, "ghcr.io/devcontainers-extra/features/devcontainers-cli:1": {}, "ghcr.io/guiyomh/features/just:0": {} + }, + "postCreateCommand": { + "installPythonDependencies": "cd /workspaces/dotslash/python && uv venv --no-project && uv pip install -r requirements-fmt.txt" } } diff --git a/.gitignore b/.gitignore index 93b7dfd..ecd9fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ # Python __pycache__/ -/python/.ruff_cache/ +.venv/ *.pyc # Node.js diff --git a/Justfile b/Justfile index 9f4ed0a..d118356 100644 --- a/Justfile +++ b/Justfile @@ -52,15 +52,14 @@ test-feature-scenarios: [group('Downstream')] [working-directory: 'python'] check-python: - uvx ruff check - uvx ruff format --check --diff + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt diff src tests + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt check src tests # Fix static analysis issues for the Python package. [group('Downstream')] [working-directory: 'python'] fix-python: - uvx ruff check --fix - uvx ruff format + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt format src tests # Test the Python package. [group('Downstream')] diff --git a/python/hatch_build.py b/python/hatch_build.py index 3657451..3b3e95f 100644 --- a/python/hatch_build.py +++ b/python/hatch_build.py @@ -12,7 +12,7 @@ from contextlib import contextmanager from functools import cached_property from platform import machine -from typing import TYPE_CHECKING, Any, BinaryIO +from typing import Any, BinaryIO, TYPE_CHECKING from hatchling.builders.hooks.plugin.interface import BuildHookInterface from hatchling.metadata.plugin.interface import MetadataHookInterface @@ -34,7 +34,9 @@ def update(self, metadata: dict[str, Any]) -> None: "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", } - if github_token := (os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN")): + if github_token := ( + os.environ.get("GH_TOKEN") or os.environ.get("GITHUB_TOKEN") + ): headers["Authorization"] = f"Bearer {github_token}" with http_get( @@ -49,12 +51,16 @@ def update(self, metadata: dict[str, Any]) -> None: class CustomBuildHook(BuildHookInterface): - def initialize(self, version: str, build_data: dict[str, Any]) -> None: # noqa: ARG002 + def initialize( + self, version: str, build_data: dict[str, Any] + ) -> None: # noqa: ARG002 if self.__source == "release": asset = self.__release_asset elif os.path.isdir(self.__source): asset = self.__local_asset - elif not os.path.isabs(self.__source) and os.path.isfile(os.path.join(self.root, "PKG-INFO")): + elif not os.path.isabs(self.__source) and os.path.isfile( + os.path.join(self.root, "PKG-INFO") + ): msg = ( "The current directory has a `PKG-INFO` file, which likely means that the wheel is being " "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: build_data["shared_scripts"][self.__binary_path] = self.__binary_name build_data["tag"] = f"py3-none-{self.__wheel_arch}" - def finalize(self, version: str, build_data: dict[str, Any], artifact: str) -> None: # noqa: ARG002 + def finalize( + self, version: str, build_data: dict[str, Any], artifact: str + ) -> None: # noqa: ARG002 import shutil shutil.rmtree(self.__temp_dir) @@ -121,9 +129,15 @@ def __arch(self) -> str: def __target_data(self) -> tuple[str, str]: match self.__platform, self.__arch: case "linux", "aarch64": - return "dotslash-linux-musl.aarch64.tar.gz", self.__get_linux_wheel_arch() + return ( + "dotslash-linux-musl.aarch64.tar.gz", + self.__get_linux_wheel_arch(), + ) case "linux", "x86_64": - return "dotslash-linux-musl.x86_64.tar.gz", self.__get_linux_wheel_arch() + return ( + "dotslash-linux-musl.x86_64.tar.gz", + self.__get_linux_wheel_arch(), + ) case "windows", "arm64": return "dotslash-windows-arm64.tar.gz", "win_arm64" case "windows", "amd64": @@ -146,7 +160,9 @@ def __wheel_arch(self) -> str: @cached_property def __source(self) -> str: - return os.environ.get("DOTSLASH_SOURCE") or self.config.get("source") or "release" + return ( + os.environ.get("DOTSLASH_SOURCE") or self.config.get("source") or "release" + ) @cached_property def __temp_dir(self) -> str: diff --git a/python/pyproject.toml b/python/pyproject.toml index e6ccd10..4bb17ff 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -69,3 +69,13 @@ repair-wheel-command = "" [tool.cibuildwheel.linux] environment-pass = ["DOTSLASH_SOURCE", "DOTSLASH_VERSION"] + +[tool.black] +target-version = ["py310"] + +[tool.usort] +first_party_detection = false + +[tool.ufmt] +formatter = "ruff-api" +sorter = "ruff-api" diff --git a/python/requirements-fmt.txt b/python/requirements-fmt.txt new file mode 100644 index 0000000..676e63e --- /dev/null +++ b/python/requirements-fmt.txt @@ -0,0 +1,7 @@ +# generated by `pyfmt --requirements` +black==24.4.2 +ruff-api==0.1.0 +stdlibs==2024.1.28 +ufmt==2.8.0 +usort==1.0.8.post1 + diff --git a/python/ruff.toml b/python/ruff.toml deleted file mode 100644 index acf3b6b..0000000 --- a/python/ruff.toml +++ /dev/null @@ -1,7 +0,0 @@ -line-length = 120 - -[lint.flake8-tidy-imports] -ban-relative-imports = "all" - -[lint.isort] -known-first-party = ["dotslash"] diff --git a/python/tests/test_cli.py b/python/tests/test_cli.py index 02eb4b4..dd2f4fe 100644 --- a/python/tests/test_cli.py +++ b/python/tests/test_cli.py @@ -13,7 +13,11 @@ def test_cli() -> None: - result = subprocess.run([sys.executable, "-m", "dotslash", "--version"], capture_output=True, encoding="utf-8") + result = subprocess.run( + [sys.executable, "-m", "dotslash", "--version"], + capture_output=True, + encoding="utf-8", + ) output = result.stdout.strip() assert result.returncode == 0, output