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
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
if [[ -f .env ]]; then
dotenv .env
fi

PATH_add "$PWD/.venv/bin"
export VIRTUAL_ENV="$PWD/.venv"
7 changes: 3 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.11
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- run: uv sync
- uses: pre-commit/action@v3.0.0
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: |
3.11
3.12
- run: pip install tox
- run: tox
- uses: astral-sh/setup-uv@v5
- run: uv sync
- run: uv run coverage erase && uv run coverage run -m pytest && uv run coverage report
44 changes: 19 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
repos:
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [--py311-plus, --add-import, "from __future__ import annotations"]
- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black
language_version: python3.11
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
language_version: python3.11
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
- repo: local
hooks:
- id: ruff-check
name: ruff check
entry: .venv/bin/ruff check --fix
language: system
types: [python]
- id: ruff-format
name: ruff format
entry: .venv/bin/ruff format
language: system
types: [python]
- id: mypy
additional_dependencies:
- "pytest"
# I'd like to just:
# - "-r requirements-dev.in"
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
name: mypy
entry: .venv/bin/mypy
language: system
types: [python]
- id: shellcheck
name: shellcheck
entry: .venv/bin/shellcheck
language: system
types: [shell]
args: [--norc]

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11.4
13 changes: 5 additions & 8 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## Setup

```bash
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements-dev.in -e .
uv sync
```

## Running Tests

```bash
source .venv/bin/activate
pytest tests/
uv run pytest tests/
```

Or with tox: `tox -e py311`
With coverage: `uv run coverage erase && uv run coverage run -m pytest && uv run coverage report`

## Code Style

- Python 3.11+
- Black formatter, 80 char line length
- Ruff formatter/linter, 80 char line length
- Strict mypy/pyright typing
- Run `black .` and `mypy .` before committing
- Run `ruff check --fix .`, `ruff format .`, and `mypy .` before committing

## Project Structure

Expand Down
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
test: docker-image
gh act -W .github/workflows/bootstrap.yml --pull=false

venv: requirements-dev.in
rm -rf venv # prevent recursion
python3.11 -m venv --clear --upgrade-deps --prompt=devenv venv || \
rm -rf venv # failure
./venv/bin/pip install -r requirements-dev.in -e . || \
rm -rf venv # failure
touch venv # success

docker-image:
cd lib/gh-act && make
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ version = v1.3.0

## develop

We use `tox`. The easiest way to run devenv locally is just using the tox venv's executable:
We use `uv`. The easiest way to run devenv locally:

```
~/code/sentry $ ~/code/devenv/.tox/py311/bin/devenv sync
~/code/devenv $ uv sync
~/code/sentry $ uv run --project ~/code/devenv devenv sync
```
18 changes: 6 additions & 12 deletions devenv/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
return 1
pubkey = github.generate_and_configure_ssh_keypair()
if not constants.CI:
input(
f"""
input(f"""
Failed to authenticate with an ssh key to GitHub.
We've generated and configured one for you at ~/.ssh/sentry-github.
Visit https://github.com/settings/ssh/new and add the following Authentication key:
Expand All @@ -95,19 +94,16 @@ def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
and click Configure SSO, for the getsentry organization.

When done, hit ENTER to continue.
"""
)
""")
while not github.check_ssh_access():
input(
"Still failing to authenticate to GitHub. ENTER to retry, otherwise ^C to quit."
)

# Mirror this in bootstrap.py.
print(
f"""\
print(f"""\
Updating global tools (at {constants.root}/bin).
"""
)
""")
os.makedirs(f"{constants.root}/bin", exist_ok=True)

if constants.DARWIN:
Expand All @@ -121,14 +117,12 @@ def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:

os.makedirs(context["code_root"], exist_ok=True)

print(
"""
print("""
All done! Please close this terminal window and start a fresh one.

Afterward, start working on your project using the devenv fetch command
e.g., devenv fetch sentry or devenv fetch ops
"""
)
""")

return 0

Expand Down
6 changes: 2 additions & 4 deletions devenv/checks/limaDns.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ def fix() -> tuple[bool, str]:
stdout=True,
)
except RuntimeError as e:
print(
f"""
print(f"""
failed to restart the vm's resolved:
{e}

we're going to try restarting colima
"""
)
""")
try:
proc.run(
(sys.executable, "-P", "-m", "devenv", "colima", "restart")
Expand Down
2 changes: 1 addition & 1 deletion devenv/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def run_checks(


def filter_failing_checks(
results: Dict[Check, tuple[bool, str]]
results: Dict[Check, tuple[bool, str]],
) -> List[Check]:
"""Print a report of the results, and return a list of failing checks."""
failing_checks: list[Check] = []
Expand Down
6 changes: 2 additions & 4 deletions devenv/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ def main(context: Context, argv: Sequence[str] | None = None) -> ExitCode:
if not constants.CI and not constants.EXTERNAL_CONTRIBUTOR:
fetch(code_root, "getsentry/getsentry")

print(
f"""
print(f"""

All done! Please close this terminal window and start a fresh one.
Sentry has been set up in {code_root}/sentry.
cd into it and you should be able to run `sentry devserver`.

"""
)
""")
else:
fetch(code_root, args.repo)

Expand Down
10 changes: 5 additions & 5 deletions devenv/lib/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ def strip1(
members: Sequence[tarfile.TarInfo],
) -> Generator[tarfile.TarInfo, None, None]:
for member in members:
i = member.path.find("/")
i = member.name.find("/")
if i == -1:
continue
elif i == 0:
i = member.path[1:].find("/") + 1
i = member.name[1:].find("/") + 1
if i == 0:
continue

member.path = member.path[i + 1 :] # noqa: E203
member.name = member.name[i + 1 :] # noqa: E203

# hardlink target (linkname) is relative to the root of the
# archive and must also be stripped
Expand All @@ -135,7 +135,7 @@ def unpack(

if strip1_new_prefix:
for member in members:
member.path = f"{strip1_new_prefix}/{member.path}"
member.name = f"{strip1_new_prefix}/{member.name}"

tarf.extractall(into, members=members, filter="tar")

Expand All @@ -150,6 +150,6 @@ def unpack_strip_n(path: str, into: str, n: int, new_prefix: str = "") -> None:

if new_prefix:
for member in members:
member.path = f"{new_prefix}/{member.path}"
member.name = f"{new_prefix}/{member.name}"

tarf.extractall(into, members=members, filter="tar")
2 changes: 1 addition & 1 deletion devenv/lib/brew.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from shutil import which

from devenv.constants import DARWIN
from devenv.constants import INTEL_MAC
from devenv.constants import homebrew_bin
from devenv.constants import homebrew_repo
from devenv.constants import INTEL_MAC
from devenv.constants import user
from devenv.lib import fs
from devenv.lib import proc
Expand Down
10 changes: 7 additions & 3 deletions devenv/lib/colima.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import tempfile
from enum import Enum

from devenv.constants import SYSTEM_MACHINE
from devenv.constants import home
from devenv.constants import root
from devenv.constants import SYSTEM_MACHINE
from devenv.lib import archive
from devenv.lib import docker
from devenv.lib import fs
from devenv.lib import proc
from devenv.lib import rosetta


ColimaStatus = Enum("ColimaStatus", ("UP", "DOWN", "UNHEALTHY"))


Expand Down Expand Up @@ -174,7 +173,12 @@ def start(restart: bool = False) -> ColimaStatus:
raise SystemExit("failed to determine memsize_bytes")
memsize_bytes = os.sysconf("SC_PAGE_SIZE") * os.sysconf("SC_PHYS_PAGES")

args = ["--cpu", f"{cpus//2}", "--memory", f"{memsize_bytes//(2*1024**3)}"]
args = [
"--cpu",
f"{cpus // 2}",
"--memory",
f"{memsize_bytes // (2 * 1024**3)}",
]
if platform.machine() == "arm64":
args = [*args, "--vm-type=vz", "--vz-rosetta", "--mount-type=virtiofs"]

Expand Down
6 changes: 3 additions & 3 deletions devenv/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def initialize_config(config_path: str, defaults: Config) -> None:
val: str = config.get(
section,
var,
fallback=(opts.default() if opts else "")
if _val is None
else _val,
fallback=(
(opts.default() if opts else "") if _val is None else _val
),
)

if not CI:
Expand Down
3 changes: 1 addition & 2 deletions devenv/lib/direnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def install() -> None:
machine = "arm64" if MACHINE == "arm64" else "amd64"
name = f"direnv.{sys.platform}-{machine}"
url = (
"https://github.com/direnv/direnv/releases/download"
f"/v{_version}/{name}"
f"https://github.com/direnv/direnv/releases/download/v{_version}/{name}"
)

archive.download(url, _sha256[name], dest=direnv_path)
Expand Down
2 changes: 1 addition & 1 deletion devenv/lib/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import tempfile
from threading import Thread

from devenv.constants import SYSTEM_MACHINE
from devenv.constants import home
from devenv.constants import root
from devenv.constants import SYSTEM_MACHINE
from devenv.lib import archive
from devenv.lib import proc

Expand Down
9 changes: 4 additions & 5 deletions devenv/lib/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def shellrc() -> str:


def gitroot(cd: str = "") -> str:
from os.path import normpath, join
from os.path import join
from os.path import normpath

if not cd:
cd = os.getcwd()
Expand Down Expand Up @@ -74,11 +75,9 @@ def ensure_binroot(reporoot: str) -> str:
os.makedirs(binroot, exist_ok=True)
if not os.path.exists(f"{binroot}/.gitignore"):
with open(f"{binroot}/.gitignore", "w") as f:
f.write(
"""*
f.write("""*
# automatically written by devenv ensure_binroot! feel free to modify.
"""
)
""")
return binroot


Expand Down
2 changes: 1 addition & 1 deletion devenv/lib/limactl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import shutil
import tempfile

from devenv.constants import SYSTEM_MACHINE
from devenv.constants import home
from devenv.constants import root
from devenv.constants import SYSTEM_MACHINE
from devenv.lib import archive
from devenv.lib import proc

Expand Down
1 change: 0 additions & 1 deletion devenv/lib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from devenv.lib import fs
from devenv.lib import proc


_shims = ("node", "npm", "npx")


Expand Down
Loading