Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Python
__pycache__/
/python/.ruff_cache/
.venv/
*.pyc

# Node.js
Expand Down
7 changes: 3 additions & 4 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
32 changes: 24 additions & 8 deletions python/hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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":
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
ofek marked this conversation as resolved.

[tool.ufmt]
formatter = "ruff-api"
sorter = "ruff-api"
7 changes: 7 additions & 0 deletions python/requirements-fmt.txt
Original file line number Diff line number Diff line change
@@ -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

7 changes: 0 additions & 7 deletions python/ruff.toml

This file was deleted.

6 changes: 5 additions & 1 deletion python/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading