Skip to content

Conversation

joshuarli
Copy link
Member

@joshuarli joshuarli commented Aug 19, 2025

This introduces devenv, uv and pre-commit in accordance with these repo standards:
https://www.notion.so/sentry/Standard-Spec-devenv-2238b10e4b5d8072a992d8b67d94be22
https://www.notion.so/sentry/Standard-Spec-python-uv-2248b10e4b5d8045b8fff30f8b8b67ca
https://www.notion.so/sentry/Standard-Spec-pre-commit-2238b10e4b5d8019aa1fe1158e39c38e

The ability to run devenv sync and get a dev environment in any repo is the DX i'm aiming for,
and these standards provide a foundation from which later we can easily push updates to all repos.

You should be able to checkout this branch, run direnv allow and devenv sync (might be prompted to run ~/.local/share/sentry-devenv/bin/devenv update first), which will set up everything needed for development (other than cargo).

Thanks to uv and our internal pypi, setting up the venv is near instant now (excluding the rust build of py/ of course).


Originally I was going to split this into 2 PRs, where the latter would configure py/ for uv, but it's not very good DX since uv sync will erase it as it doesn't know about it.


Note

Introduce devenv + uv for Python envs and pre-commit hooks, update CI to use uv/venv with targeted linting, and replace legacy venv/requirements workflow across repo.

  • Developer Environment:
    • Add devenv/ (config and sync.py), Brewfile, root pyproject.toml, py/pyproject.toml, uv.lock, and .pre-commit-config.yaml to standardize setup with uv and pre-commit.
    • Replace .envrc to load .env, add uv/devenv to PATH, and require devenv; export .venv.
    • Add setup.cfg for flake8; remove requirements-dev.txt and scripts/git-precommit-hook.
  • CI/CD:
    • Migrate workflows to uv: replace actions/setup-python with astral-sh/setup-uv + getsentry/action-setup-venv; install deps via uv sync.
    • In ci.yml, add changed-file detection and run pre-commit on modified files; cache pre-commit; adjust Python build/test to use uv; update devservices validation to read version from uv.lock.
    • In build_library.yml, trigger on PR, use uv-based venv for macOS and sdist builds; comment out artifact merge step.
  • Makefile & Docs:
    • Simplify Makefile: drop Python style/lint/format targets and legacy venv management; setup-venv now runs devenv sync and installs py/ via uv.
    • Update README.md to use devenv sync and uv pip commands.

Written by Cursor Bugbot for commit ab5c3b7. This will update automatically on new commits. Configure here.

@joshuarli joshuarli changed the title feat: devenv and pre-commit feat: devenv + uv + pre-commit Aug 20, 2025
# TODO: reactivate when fixed
# - id: check-github-workflows

- repo: local
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit now runs in ci and now runs black/flake8/mypy (locked+installed via uv) on python files!


# Style checking

style: style-rust style-python ## check code style
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style and lint for python's moved into pre-commit

i decided to leave rust alone for now to keep things simple (will need some work as tools like rustfmt and clippy-driver are needed to accept individual file arguments)

$$RELAY_PYTHON_VERSION -m venv --copies .venv
.venv/bin/pip install -U pip wheel

.venv/python-requirements-stamp: requirements-dev.txt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rerunning make setup-venv will always make sure python stuff is up to date and reexecutes the build - all this complexity can be removed

# Make will re-run 'pip install' if the mtime on requirements-dev.txt is higher again.
touch .venv/python-requirements-stamp

.git/hooks/pre-commit:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has been rolled up into pre-commit install --install-hooks in devenv sync

#!/bin/bash
#!/not/executable/bash

# Our policy is that the .envrc is entirely optional, and a user
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devenv/sync.py and .pre-commit-config.yaml are all using .venv/bin explicitly so this policy you have here is still being respected! although you will need a global install of devenv: https://github.com/getsentry/devenv/?tab=readme-ov-file#install

(chances are and i would hope relay devs already have devenv installed as it is required for sentry development)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually well it is needed to put .devenv/bin on path so you have access to devenv's uv at .devenv/bin/uv

@joshuarli joshuarli marked this pull request as ready for review August 21, 2025 23:36
@joshuarli joshuarli requested a review from a team as a code owner August 21, 2025 23:36
cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@loewenheim loewenheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I would appreciate a second opinion

hooks:
- id: check-github-actions
- id: check-github-workflows
# TODO: reactivate when fixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this referring to? What needs to be fixed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://gist.github.com/joshuarli/36587aeb18445bf18f36abcd4b82382e
(upgraded to 0.33.0 since in previous versions output is a lot less readable)

mostly complaining about 'uses' is a required property which... it is not? lol

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you able to test this workflow? Any chance we will face surprises next time we want to release the library?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, I'll run it and see!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup it's totally broken haha, will fix

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@joshuarli joshuarli force-pushed the devenv-and-pre-commit branch from 8625a9c to 38369f3 Compare September 4, 2025 21:57
cursor[bot]

This comment was marked as outdated.

@joshuarli joshuarli changed the title feat: devenv + uv + pre-commit feat(dev): devenv + uv + pre-commit Sep 29, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

)

if not shutil.which("rustup"):
raise SystemExit("rustup not on PATH. Did you run `direnv allow`?")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Rustup Check Fails During Fresh Setup

The rustup check runs too early in the sync script. Although brew bundle installs rustup earlier, it's not immediately available on PATH until the environment (like direnv) reloads. This causes the script to exit prematurely on a fresh setup with a misleading error.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants