Skip to content

#247 Refactor bitbucket #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
53 changes: 0 additions & 53 deletions src/usethis/_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,6 @@ def is_bitbucket_used() -> bool:
return (Path.cwd() / "bitbucket-pipelines.yml").exists()


def get_bitbucket_pre_commit_step() -> Step:
return Step(
name="Run pre-commit",
caches=["uv", "pre-commit"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run pre-commit run --all-files",
]
),
)


def get_bitbucket_ruff_step() -> Step:
return Step(
name="Run Ruff",
caches=["uv"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run ruff check --fix",
"uv run ruff format",
]
),
)


def get_bitbucket_deptry_step() -> Step:
return Step(
name="Run Deptry",
caches=["uv"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run deptry src",
]
),
)


def get_bitbucket_pyproject_fmt_step() -> Step:
return Step(
name="Run pyproject-fmt",
caches=["uv"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run pyproject-fmt pyproject.toml",
]
),
)


def update_bitbucket_pytest_steps() -> None:
matrix = get_supported_major_python_versions()
for version in matrix:
Expand Down
60 changes: 60 additions & 0 deletions src/usethis/_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Protocol

from usethis._console import tick_print
from usethis._integrations.bitbucket.anchor import ScriptItemAnchor
from usethis._integrations.bitbucket.schema import Script, Step
from usethis._integrations.pre_commit.hooks import (
add_repo,
get_hook_names,
Expand Down Expand Up @@ -37,6 +39,15 @@ def name(self) -> str:
with the tool; if not, make sure to override methods which access this property.
"""

def get_bitbucket_step(self) -> Step | None:
"""Get the Bitbucket pipeline step for this tool.

Returns:
Optional[Step]: A Bitbucket pipeline step configuration for CI/CD, or None if the tool
doesn't have a pipeline step.
"""
return None

@property
def dev_deps(self) -> list[Dependency]:
"""The tool's development dependencies."""
Expand Down Expand Up @@ -238,6 +249,18 @@ def get_pre_commit_repos(self) -> list[LocalRepo | UriRepo]:
)
]

def get_bitbucket_step(self) -> Step:
return Step(
name="Run Deptry",
caches=["uv"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run deptry src",
]
),
)


class PreCommitTool(Tool):
@property
Expand All @@ -251,6 +274,18 @@ def dev_deps(self) -> list[Dependency]:
def get_managed_files(self) -> list[Path]:
return [Path(".pre-commit-config.yaml")]

def get_bitbucket_step(self) -> Step:
return Step(
name="Run pre-commit",
caches=["uv", "pre-commit"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run pre-commit run --all-files",
]
),
)


class PyprojectFmtTool(Tool):
@property
Expand Down Expand Up @@ -281,6 +316,18 @@ def get_pyproject_configs(self) -> list[PyProjectConfig]:
def get_pyproject_id_keys(self) -> list[list[str]]:
return [["tool", "pyproject-fmt"]]

def get_bitbucket_step(self) -> Step:
return Step(
name="Run pyproject-fmt",
caches=["uv"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run pyproject-fmt pyproject.toml",
]
),
)


class PytestTool(Tool):
@property
Expand Down Expand Up @@ -414,6 +461,19 @@ def get_pyproject_id_keys(self) -> list[list[str]]:
def get_managed_files(self) -> list[Path]:
return [Path("ruff.toml"), Path(".ruff.toml")]

def get_bitbucket_step(self) -> Step:
return Step(
name="Run Ruff",
caches=["uv"],
script=Script(
[
ScriptItemAnchor(name="install-uv"),
"uv run ruff check --fix",
"uv run ruff format",
]
),
)


ALL_TOOLS: list[Tool] = [
CoverageTool(),
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.