From c33287a4c0a777177d48dabb32bd2e60cb2e0401 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher Date: Wed, 29 Oct 2025 14:31:06 -0700 Subject: [PATCH 1/6] feat: Sync Meta Python Format Deps Requirements --- python/requirements-fmt.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 python/requirements-fmt.txt 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 + From 37edaabb505755525ebc8e3194db933805f6b630 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher Date: Wed, 29 Oct 2025 15:36:07 -0700 Subject: [PATCH 2/6] fix: use ufmt instead of ruff --- .devcontainer/Containerfile | 1 + .devcontainer/devcontainer.json | 11 ++++++++++- .gitignore | 2 +- Justfile | 7 +++---- python/ruff.toml | 7 ------- 5 files changed, 15 insertions(+), 13 deletions(-) delete mode 100644 python/ruff.toml diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile index 2053663..8b126cc 100644 --- a/.devcontainer/Containerfile +++ b/.devcontainer/Containerfile @@ -7,6 +7,7 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ nodejs \ npm \ + python3-venv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b8697ef..86f4116 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,9 @@ "ghcr.io/devcontainers/features/rust:1": {}, "ghcr.io/devcontainers-extra/features/devcontainers-cli:1": {}, "ghcr.io/guiyomh/features/just:0": {} + }, + "postAttachCommand": "source .venv/bin/activate", + "postCreateCommand": { + "installPythonDependencies": "python3 -m venv /workspaces/dotslash/.venv && /workspaces/dotslash/.venv/bin/pip3 install -r /workspaces/dotslash/python/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..028f11c 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 + ufmt diff + ufmt check # Fix static analysis issues for the Python package. [group('Downstream')] [working-directory: 'python'] fix-python: - uvx ruff check --fix - uvx ruff format + ufmt format # Test the Python package. [group('Downstream')] 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"] From 3f521c776bfafcbf5014c436b0db957a75c58dbd Mon Sep 17 00:00:00 2001 From: Shawn Wilsher Date: Wed, 29 Oct 2025 15:36:37 -0700 Subject: [PATCH 3/6] fix: format all files with ufmt --- python/hatch_build.py | 32 ++++++++++++++++++++++++-------- python/tests/test_cli.py | 6 +++++- 2 files changed, 29 insertions(+), 9 deletions(-) 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/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 From c783c582857917016d18b735f4efffeb5df5fa35 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher Date: Thu, 30 Oct 2025 08:50:49 -0700 Subject: [PATCH 4/6] fix: add Meta-required configs for black and ufmt --- python/pyproject.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/pyproject.toml b/python/pyproject.toml index e6ccd10..2a3f413 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -34,6 +34,9 @@ Homepage = "https://dotslash-cli.com" Tracker = "https://github.com/facebook/dotslash/issues" Source = "https://github.com/facebook/dotslash" +[tool.black] +target-version = ["py310"] + [tool.hatch.metadata.hooks.custom] [tool.hatch.metadata.hooks.fancy-pypi-readme] @@ -69,3 +72,6 @@ repair-wheel-command = "" [tool.cibuildwheel.linux] environment-pass = ["DOTSLASH_SOURCE", "DOTSLASH_VERSION"] + +[tool.usort] +first_party_detection = false From bbddc4114c56331b770ac1b8ba45a14bef98d99e Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 30 Oct 2025 14:30:30 -0400 Subject: [PATCH 5/6] Apply suggestions from code review --- .devcontainer/Containerfile | 1 - .devcontainer/devcontainer.json | 3 +-- Justfile | 6 +++--- python/pyproject.toml | 10 +++++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile index 8b126cc..2053663 100644 --- a/.devcontainer/Containerfile +++ b/.devcontainer/Containerfile @@ -7,7 +7,6 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ nodejs \ npm \ - python3-venv \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 86f4116..2dda037 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -37,8 +37,7 @@ "ghcr.io/devcontainers-extra/features/devcontainers-cli:1": {}, "ghcr.io/guiyomh/features/just:0": {} }, - "postAttachCommand": "source .venv/bin/activate", "postCreateCommand": { - "installPythonDependencies": "python3 -m venv /workspaces/dotslash/.venv && /workspaces/dotslash/.venv/bin/pip3 install -r /workspaces/dotslash/python/requirements-fmt.txt" + "installPythonDependencies": "cd /workspaces/dotslash/python && uv venv --no-project && uv pip install -r requirements-fmt.txt" } } diff --git a/Justfile b/Justfile index 028f11c..e27eb45 100644 --- a/Justfile +++ b/Justfile @@ -52,14 +52,14 @@ test-feature-scenarios: [group('Downstream')] [working-directory: 'python'] check-python: - ufmt diff - ufmt check + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt diff + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt check # Fix static analysis issues for the Python package. [group('Downstream')] [working-directory: 'python'] fix-python: - ufmt format + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt format # Test the Python package. [group('Downstream')] diff --git a/python/pyproject.toml b/python/pyproject.toml index 2a3f413..4bb17ff 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -34,9 +34,6 @@ Homepage = "https://dotslash-cli.com" Tracker = "https://github.com/facebook/dotslash/issues" Source = "https://github.com/facebook/dotslash" -[tool.black] -target-version = ["py310"] - [tool.hatch.metadata.hooks.custom] [tool.hatch.metadata.hooks.fancy-pypi-readme] @@ -73,5 +70,12 @@ 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" From 9b257a8aeb1c1d71f810691a9b974062ce3d977c Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 30 Oct 2025 15:03:08 -0400 Subject: [PATCH 6/6] Apply suggestions from code review --- Justfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Justfile b/Justfile index e27eb45..d118356 100644 --- a/Justfile +++ b/Justfile @@ -52,14 +52,14 @@ test-feature-scenarios: [group('Downstream')] [working-directory: 'python'] check-python: - uv run --no-project --with-requirements requirements-fmt.txt -- ufmt diff - uv run --no-project --with-requirements requirements-fmt.txt -- ufmt check + 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: - uv run --no-project --with-requirements requirements-fmt.txt -- ufmt format + uv run --no-project --with-requirements requirements-fmt.txt -- ufmt format src tests # Test the Python package. [group('Downstream')]