Skip to content

Commit

Permalink
Move from Rye to UV (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Oct 8, 2024
1 parent 6962166 commit 9e47aa7
Show file tree
Hide file tree
Showing 11 changed files with 4,331 additions and 634 deletions.
107 changes: 65 additions & 42 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,45 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.8"
- uses: eifinger/[email protected]
- run: rye config --set-bool behavior.use-uv=true
- run: rye sync --no-lock
version: "0.4.12"
enable-cache: true

- name: Set up Python 3.12
run: uv python install 3.12

- name: Install dependencies
run: uv sync --python 3.12 --frozen

- run: make lint
- run: rye run pyright logfire tests
- run: make typecheck

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
# we use uv directly here since I couldn't get rye to work with UV_EXTRA_INDEX_URL
# see https://github.com/pydantic/logfire/pull/12
- run: pip install uv
- run: uv pip install --system -r requirements.lock -r requirements-dev.lock
- run: uv pip install --system -U mkdocs-material mkdocstrings-python griffe==0.48.0
version: "0.4.12"
enable-cache: true

- name: Set up Python 3.12
run: uv python install 3.12

- run: uv sync --python 3.12 --frozen
- run: uv pip install --upgrade mkdocs-material mkdocstrings-python griffe==0.48.0
env:
UV_EXTRA_INDEX_URL: ${{ secrets.UV_EXTRA_INDEX_URL }}
- run: |
if [[ -n "${{ github.head_ref }}" && "${{ github.repository }}" != "${{ github.event.pull_request.head.repo.full_name }}" ]]; then
mkdocs build --no-strict
uv run --no-sync mkdocs build --no-strict
else
mkdocs build
uv run --no-sync mkdocs build
fi
test:
Expand All @@ -57,26 +68,25 @@ jobs:
PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4

- name: Ensure requests to production domains fail
if: runner.os == 'Linux'
run: |
echo "203.0.113.0 logfire.dev" | sudo tee -a /etc/hosts
echo "203.0.113.0 logfire-api.pydantic.dev" | sudo tee -a /etc/hosts
echo "203.0.113.0 logfire.pydantic.dev" | sudo tee -a /etc/hosts
- name: set up python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: ${{ matrix.python-version }}
- uses: eifinger/[email protected]
- name: Pin python-version ${{ matrix.python-version }}
run: rye pin ${{ matrix.python-version }}
- run: rye config --set-bool behavior.use-uv=true
# Update all dependencies to the latest version possible
- run: rye sync --update-all
- run: |
pip install uv
uv pip install "logfire-api @ file://logfire-api"
- run: rye show
version: "0.4.12"
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- run: uv sync --python ${{ matrix.python-version }} --upgrade

- run: mkdir coverage
- run: make test
env:
Expand All @@ -93,24 +103,34 @@ jobs:
needs: [test]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
version: "0.4.12"
enable-cache: true

- name: Set up Python 3.12
run: uv python install 3.12

- name: Create venv
run: uv venv --python 3.12

- name: get coverage files
uses: actions/download-artifact@v4
with:
merge-multiple: true
path: coverage
- run: pip install coverage[toml]
- run: ls -lh coverage
- run: coverage combine coverage
- run: coverage xml

- run: uv pip install coverage[toml]
- run: uv run coverage combine coverage
- run: uv run coverage xml
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
env_vars: PYTHON
- run: coverage report --fail-under 100
- run: uv run coverage report --fail-under 100

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check:
Expand All @@ -134,27 +154,30 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: set up python
uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
python-version: "3.12"
version: "0.4.12"
enable-cache: true

- name: Set up Python 3.12
run: uv python install 3.12

- name: check GITHUB_REF matches package version
uses: samuelcolvin/[email protected]
with:
version_file_path: pyproject.toml

- uses: eifinger/setup-rye@v2
- run: rye config --set-bool behavior.use-uv=true
- run: rye build
- run: uv build

- name: Publish logfire to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true

- name: Build logfire-api
run: rye build
run: uv build
working-directory: logfire-api/

- name: Publish logfire-api to PyPI
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ repos:
types: [python]
- id: pyright
name: pyright
entry: rye
entry: make
language: system
args: ["run", "typecheck"]
args: [typecheck]
types: [python]
pass_filenames: false
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We'd love anyone interested to contribute to the Logfire SDK and documentation.
## How to contribute

1. Fork and clone the repository
2. [Install Rye](https://rye.astral.sh/guide/installation/)
2. [Install uv](https://docs.astral.sh/uv/getting-started/installation/)
3. Run `make install` to install dependencies
4. Run `make test` to run unit tests
5. Run `make format` to format code
Expand Down
46 changes: 25 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
.DEFAULT_GOAL := all
sources = pydantic tests docs/plugins

.PHONY: .rye # Check that Rye is installed
.rye:
@rye --version || echo 'Please install Rye: https://rye-up.com/guide/installation/'
.PHONY: .uv # Check that uv is installed
.uv:
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: .pre-commit # Check that pre-commit is installed
.pre-commit:
@pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'

.PHONY: install # Install the package, dependencies, and pre-commit for local development
install: .rye .pre-commit
rye show
rye sync --no-lock
install: .uv .pre-commit
uv sync --frozen
uv pip install -e logfire-api
pre-commit install --install-hooks

.PHONY: format # Format the code
format:
rye format
rye lint --fix
uv run ruff format
uv run ruff check --fix

.PHONY: lint # Lint the code
lint:
rye lint
rye format --check
uv run ruff check
uv run ruff format --check --diff

.PHONY: typecheck # Typecheck the code
typecheck:
uv run pyright

.PHONY: test # Run the tests
test:
rye run coverage run -m pytest
uv run coverage run -m pytest

.PHONY: generate-stubs # Generate stubs for logfire-api
generate-stubs:
rye run generate-stubs
uv run stubgen -p logfire --include-docstrings --no-analysis
rsync -a out/logfire/ logfire-api/logfire_api/

.PHONY: testcov # Run tests and generate a coverage report
testcov: test
@echo "building coverage html"
@rye run coverage html --show-contexts
uv run coverage html --show-contexts

.PHONY: docs # Build the documentation
docs:
rye run docs
uv run mkdocs build

# no strict so you can build the docs without insiders packages
.PHONY: docs-serve # Build and serve the documentation
docs-serve:
rye run docs-serve
uv run mkdocs serve --no-strict

.PHONY: all
all: format lint test

.PHONY: cf-pages-build # Build the docs for GitHub Pages
cf-pages-build:
python3 -V
python3 -m pip install uv
python3 -m uv pip install --system -r requirements.lock -r requirements-dev.lock
python3 -m uv pip install --system --extra-index-url $(PPPR_URL) -U mkdocs-material mkdocstrings-python griffe==0.48.0
python3 -m mkdocs build
curl -LsSf https://astral.sh/uv/0.4.12/install.sh | sh
${HOME}/.cargo/bin/uv python install 3.12
${HOME}/.cargo/bin/uv sync --python 3.12 --frozen
${HOME}/.cargo/bin/uv pip install --upgrade --extra-index-url $(PPPR_URL) mkdocs-material mkdocstrings-python griffe==0.48.0
${HOME}/.cargo/bin/uv run --no-sync mkdocs build
2 changes: 1 addition & 1 deletion logfire-api/logfire_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def with_settings(self, *args, **kwargs) -> Logfire:

def force_flush(self, *args, **kwargs) -> None: ...

def log_slow_async_callbacks(self, *args, **kwargs) -> None: # pragma: no branch
def log_slow_async_callbacks(self, *args, **kwargs) -> None: # pragma: no cover
return nullcontext()

def install_auto_tracing(self, *args, **kwargs) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion logfire-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = []
readme = "README.md"
requires-python = ">= 3.8"

[tool.rye]
[tool.uv]
managed = true
dev-dependencies = []

Expand Down
2 changes: 1 addition & 1 deletion logfire/_internal/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def _numpy_schema(obj: Any, seen: set[int]) -> JsonDict:
return {
'type': 'array',
'x-python-datatype': 'ndarray',
'x-shape': to_json_value(obj.shape, seen), # type: ignore
'x-shape': to_json_value(obj.shape, seen),
'x-dtype': str(obj.dtype), # type: ignore
}

Expand Down
Loading

0 comments on commit 9e47aa7

Please sign in to comment.