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
16 changes: 16 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
if [[ -f "${PWD}/.env" ]]; then
dotenv
fi

PATH_add "${HOME}/.local/share/sentry-devenv/bin"

if ! command -v devenv >/dev/null; then
echo "install devenv: https://github.com/getsentry/devenv#install"
return 1
fi

PATH_add "${PWD}/.devenv/bin"

export VIRTUAL_ENV="${PWD}/.venv"

PATH_add "${PWD}/.venv/bin"
38 changes: 34 additions & 4 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,38 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
Copy link
Member Author

Choose a reason for hiding this comment

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

todo replace with https://github.com/getsentry/action-pre-commit, i'll do this on monday


- name: Get changed files
id: changes
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd # v3.0.0
with:
list-files: json
filters: |
all:
- added|modified: '**/*'

- uses: astral-sh/setup-uv@884ad927a57e558e7a70b92f2bccf9198a4be546 # v6
with:
version: '0.8.2'
# we just cache the venv-dir directly in action-setup-venv
enable-cache: false

- uses: getsentry/[email protected]
with:
python-version: '3.11'
- uses: pre-commit/[email protected]
cache-dependency-path: uv.lock
install-cmd: uv sync --frozen --active

- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ~/.cache/pre-commit
key: cache-epoch-1|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml', 'uv.lock') }}

- name: Install pre-commit
run: pre-commit install-hooks

- name: Run pre-commit
run: |
jq '.[]' --raw-output <<< '${{steps.changes.outputs.all_files}}' |
# Run pre-commit to lint and format check files that were changed (but not deleted)
xargs pre-commit run --files
52 changes: 33 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,42 @@ repos:
hooks:
- id: reorder-python-imports
args: [--py311-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py311-plus]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
- repo: local
hooks:
- id: format-packages-ini
name: format packages.ini
language: python
entry: python -m format_ini
entry: .venv/bin/python -m format_ini
files: ^packages\.ini$
additional_dependencies: [packaging==21.3]

# Configuration for black exists in pyproject.toml,
# but we let pre-commit take care of the file filtering.
- id: black
name: black
entry: .venv/bin/black
language: system
types_or: [python, pyi]
require_serial: true

# Configuration for flake8 exists in setup.cfg,
# but we let pre-commit take care of the file filtering.
- id: flake8
name: flake8
entry: .venv/bin/flake8
language: system
types: [python]
require_serial: true

- id: pyupgrade
name: pyupgrade
entry: .venv/bin/pyupgrade
language: system
types: [python]
args: [--py311-plus]

- id: mypy
name: mypy
entry: .venv/bin/mypy
language: system
types: [python]
require_serial: true
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.13.3
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ sentry internal pypi
this repository contains the tools to import and/or build packages from public pypi for the
platforms and achitectures required for sentry development.

## setup

```bash
devenv sync
direnv allow
```

to run tests: `tox`


## adding packages

packages are configured in the `packages.ini` file.
Expand Down
10 changes: 5 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def _brew_paths(*pkgs: str) -> list[str]:


@contextlib.contextmanager
def _brew_install(packages: tuple[str, ...]) -> Generator[None, None, None]:
def _brew_install(packages: tuple[str, ...]) -> Generator[None]:
installed_before = _darwin_installed_packages()

subprocess.check_call(
Expand Down Expand Up @@ -180,7 +180,7 @@ def _paths(*parts: str) -> list[str]:


@contextlib.contextmanager
def _darwin_install(package: Package) -> Generator[None, None, None]:
def _darwin_install(package: Package) -> Generator[None]:
with contextlib.ExitStack() as ctx:
if package.brew_requires:
ctx.enter_context(_brew_install(package.brew_requires))
Expand Down Expand Up @@ -252,7 +252,7 @@ def _linux_installed_packages() -> frozenset[str]:


@contextlib.contextmanager
def _apt_install(packages: tuple[str, ...]) -> Generator[None, None, None]:
def _apt_install(packages: tuple[str, ...]) -> Generator[None]:
_apt_update()

installed_before = _linux_installed_packages()
Expand Down Expand Up @@ -280,7 +280,7 @@ def _apt_install(packages: tuple[str, ...]) -> Generator[None, None, None]:


@contextlib.contextmanager
def _linux_install(package: Package) -> Generator[None, None, None]:
def _linux_install(package: Package) -> Generator[None]:
with contextlib.ExitStack() as ctx:
if package.apt_requires:
ctx.enter_context(_apt_install(package.apt_requires))
Expand Down Expand Up @@ -446,7 +446,7 @@ def _join_env(
@contextlib.contextmanager
def _prebuild(
package: Package, tmpdir: str, *, env: MutableMapping[str, str] | None = None
) -> Generator[None, None, None]:
) -> Generator[None]:
if env is None:
env = os.environ

Expand Down
14 changes: 14 additions & 0 deletions devenv/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[devenv]
minimum_version = 1.22.1

[uv]
darwin_arm64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-aarch64-apple-darwin.tar.gz
darwin_arm64_sha256 = 954d24634d5f37fa26c7af75eb79893d11623fc81b4de4b82d60d1ade4bfca22
darwin_x86_64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-x86_64-apple-darwin.tar.gz
darwin_x86_64_sha256 = ae755df53c8c2c1f3dfbee6e3d2e00be0dfbc9c9b4bdffdb040b96f43678b7ce
linux_arm64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-aarch64-unknown-linux-gnu.tar.gz
linux_arm64_sha256 = 27da35ef54e9131c2e305de67dd59a07c19257882c6b1f3cf4d8d5fbb8eaf4ca
linux_x86_64 = https://github.com/astral-sh/uv/releases/download/0.8.2/uv-x86_64-unknown-linux-gnu.tar.gz
linux_x86_64_sha256 = 6dcb28a541868a455aefb2e8d4a1283dd6bf888605a2db710f0530cec888b0ad
# used for autoupdate
version = 0.8.2
26 changes: 26 additions & 0 deletions devenv/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import annotations

from devenv import constants
from devenv.lib import config
from devenv.lib import proc
from devenv.lib import uv


def main(context: dict[str, str]) -> int:
reporoot = context["reporoot"]
cfg = config.get_repo(reporoot)

uv.install(
cfg["uv"]["version"],
cfg["uv"][constants.SYSTEM_MACHINE],
cfg["uv"][f"{constants.SYSTEM_MACHINE}_sha256"],
reporoot,
)

print("syncing .venv ...")
proc.run(("uv", "sync", "--frozen", "--quiet"))

print("installing pre-commit hooks ...")
proc.run((f"{reporoot}/.venv/bin/pre-commit", "install", "--install-hooks"))

return 0
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[project]
name = "pypi"
version = "0.0.0"

[dependency-groups]
# Currently we're just doing this much to get `devenv sync` to be able to
# run tox and packaging for local python -m add_pkg.
# Not sure it would be worth the effort right now to move everything to pure pytest
# and run pytest on 3 different python versions in ci by swapping out .python-version.
# Tox remains the most ergonomic solution to test on multiple pythons.
dev = [
"black>=22.10.0",
"flake8>=7.3.0",
"mypy>=1.18.2",
"packaging==21.3",
"pre-commit==4.2.0",
"pyupgrade>=3.19.1",
"sentry-devenv>=1.25.0",
"tox==3.25.1",
]

[tool.uv]
environments = ["sys_platform == 'darwin' or sys_platform == 'linux'"]

[[tool.uv.index]]
url = "https://pypi.devinfra.sentry.io/simple"
default = true
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ warn_unused_ignores = true

[mypy-tests.*]
disallow_untyped_defs = false

[mypy-devenv.*]
follow_imports = skip
Loading
Loading