Skip to content
Open
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [--py311-plus, --add-import, "from __future__ import annotations"]
args: [--py310-plus, --add-import, "from __future__ import annotations"]
- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
Expand Down
Empty file added devenv/commands/__init__.py
Empty file.
43 changes: 25 additions & 18 deletions devenv/bootstrap.py → devenv/commands/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

import argparse
import os
import shutil
from collections.abc import Sequence
from typing import cast

from devenv.constants import CI
from devenv.constants import EXTERNAL_CONTRIBUTOR
Expand All @@ -14,25 +14,33 @@
from devenv.lib.config import Config
from devenv.lib.config import initialize_config
from devenv.lib.context import Context
from devenv.lib.modules import DevModuleInfo
from devenv.lib.modules import argument_fn
from devenv.lib.modules import command
from devenv.lib.modules import ExitCode


def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
parser = argparse.ArgumentParser()
parser.add_argument(
"-d",
"--default-config",
action="append",
help="Provide a default config value. e.g., -d coderoot:path/to/root",
from devenv.lib.modules import ModuleDef
from devenv.lib.modules import ParserFn


@command("bootstrap", "Bootstraps the development environment.")
@argument_fn(
cast(
ParserFn,
lambda x: x.add_argument(
"-d",
"--default-config",
metavar="config:value",
required=False,
action="append",
help="Provide a default config value. e.g., -d coderoot:path/to/root",
),
)

args = parser.parse_args(argv)
)
def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
args = context["args"]

configs = {
k: v for k, v in [i.split(":", 1) for i in args.default_config or []]
}

if "coderoot" not in configs and "code_root" in context:
configs["coderoot"] = context["code_root"]

Expand Down Expand Up @@ -103,9 +111,8 @@ def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
return 0


module_info = DevModuleInfo(
action=main,
name=__name__,
command="bootstrap",
module_info = ModuleDef(
module_name=__name__,
name="bootstrap",
help="Bootstraps the development environment.",
)
13 changes: 7 additions & 6 deletions devenv/doctor.py → devenv/commands/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from typing import List

from devenv.lib.context import Context
from devenv.lib.modules import DevModuleInfo
from devenv.lib.modules import command
from devenv.lib.modules import ModuleDef
from devenv.lib.modules import require_repo
from devenv.lib.repository import Repository
from devenv.lib_check.types import checker
Expand Down Expand Up @@ -161,6 +162,7 @@ def attempt_fix(check: Check, executor: ThreadPoolExecutor) -> tuple[bool, str]:
return False, f"Fix threw a runtime exception: {e}"


@command("doctor", "Diagnose common issues, and optionally try to fix them.")
@require_repo
def main(context: Context, argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -232,9 +234,8 @@ def main(context: Context, argv: Sequence[str] | None = None) -> int:
return 1


module_info = DevModuleInfo(
action=main,
name=__name__,
command="doctor",
help="Diagnose common issues, and optionally try to fix them.",
module_info = ModuleDef(
module_name=__name__,
name="doctor",
help="Diagnose common issues, and optionally try to fix them",
)
28 changes: 14 additions & 14 deletions devenv/fetch.py → devenv/commands/fetch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import argparse
import os
import sys
from collections.abc import Sequence
Expand All @@ -11,18 +10,16 @@
from devenv.constants import homebrew_bin
from devenv.lib import proc
from devenv.lib.context import Context
from devenv.lib.modules import DevModuleInfo
from devenv.lib.modules import argument
from devenv.lib.modules import command
from devenv.lib.modules import ExitCode
from devenv.lib.modules import ModuleDef


@command("fetch", "Fetches a repository")
@argument("repo", help="the repository to fetch")
def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
parser = argparse.ArgumentParser()

parser.add_argument(
"repo", type=str, help="the repository to fetch e.g., getsentry/sentry"
)

args = parser.parse_args(argv)
args = context["args"]
code_root = context["code_root"]

if args.repo in ["ops", "getsentry/ops"]:
Expand Down Expand Up @@ -78,17 +75,20 @@ def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
)

else:
if "/" not in args.repo:
print("Repository names must be in the form of <owner>/<repo>")
return 1
fetch(code_root, args.repo)

return 0


def fetch(
coderoot: str, repo: str, auth: bool = True, sync: bool = True
code_root: str, repo: str, auth: bool = True, sync: bool = True
) -> None:
org, slug = repo.split("/")

codepath = f"{coderoot}/{slug}"
codepath = f"{code_root}/{slug}"

if os.path.exists(codepath):
print(f"{codepath} already exists")
Expand All @@ -112,7 +112,7 @@ def fetch(
(
"git",
"-C",
coderoot,
code_root,
"clone",
"--filter=blob:none",
*additional_args,
Expand All @@ -124,6 +124,6 @@ def fetch(
proc.run((sys.executable, "-P", "-m", "devenv", "sync"), cwd=codepath)


module_info = DevModuleInfo(
action=main, name=__name__, command="fetch", help="Fetches a respository"
module_info = ModuleDef(
module_name=__name__, name="fetch", help="Fetches a repository"
)
8 changes: 5 additions & 3 deletions devenv/pin_gha.py → devenv/commands/pin_gha.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from functools import lru_cache

from devenv.lib.context import Context
from devenv.lib.modules import DevModuleInfo
from devenv.lib.modules import command
from devenv.lib.modules import ModuleDef


@lru_cache(maxsize=None)
Expand Down Expand Up @@ -38,6 +39,7 @@ def extract_repo(action: str) -> str:
return f"{parts[0]}/{parts[1]}"


@command("pin-gha", "Pins github actions.")
def main(context: Context, argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down Expand Up @@ -70,6 +72,6 @@ def main(context: Context, argv: Sequence[str] | None = None) -> int:
return 0


module_info = DevModuleInfo(
action=main, name=__name__, command="pin_gha", help="Pins github actions."
module_info = ModuleDef(
module_name=__name__, name="pin_gha", help="Pins github actions"
)
8 changes: 5 additions & 3 deletions devenv/sync.py → devenv/commands/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from collections.abc import Sequence

from devenv.lib.context import Context
from devenv.lib.modules import DevModuleInfo
from devenv.lib.modules import command
from devenv.lib.modules import ModuleDef
from devenv.lib.modules import require_repo


@command("sync", "Resyncs the current project")
@require_repo
def main(context: Context, argv: Sequence[str] | None = None) -> int:
repo = context["repo"]
Expand All @@ -33,6 +35,6 @@ def main(context: Context, argv: Sequence[str] | None = None) -> int:
return module.main(context_compat) # type: ignore


module_info = DevModuleInfo(
action=main, name=__name__, command="sync", help="Resyncs the environment."
module_info = ModuleDef(
module_name=__name__, name="sync", help="Resyncs the current project"
)
8 changes: 2 additions & 6 deletions devenv/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ def initialize_config(config_path: str, defaults: Config) -> None:
else _val,
)

if not CI:
if not CI and opts:
try:
if opts:
print(opts.prompt)
else:
print(f"{var}?")

print(opts.prompt)
val = input(f" [{val}]: ") or val
except EOFError:
# noninterative, use the defaults
Expand Down
2 changes: 2 additions & 0 deletions devenv/lib/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from argparse import Namespace
from typing import TypedDict

from devenv.lib.repository import Repository
Expand All @@ -9,3 +10,4 @@ class Context(TypedDict):
config_path: str
code_root: str
repo: Repository | None
args: Namespace
Loading