Skip to content

Commit

Permalink
Merge pull request #7 from AllenInstitute/feature/switch-to-uv
Browse files Browse the repository at this point in the history
Switch to use uv instead of pip
rpmcginty authored Jan 14, 2025
2 parents 9ebe0a0 + 62d3095 commit 5d72d72
Showing 7 changed files with 626 additions and 80 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -24,22 +24,40 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
uv-resolution: ["highest", "lowest"]
exclude:
- python-version: "3.10"
uv-resolution: "lowest"
- python-version: "3.11"
uv-resolution: "lowest"
env:
PYTHON_VERSION: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
python-version: ${{ github.event.inputs.python-version }}
- name: Set up AllenInstitute Repo Authorization
uses: ./.github/actions/setup-ai-github-urls
with:
token: ${{ secrets.AI_PACKAGES_TOKEN }}
- name: Run Release
run: |
make release
if [ ${{ matrix.uv-resolution }} == "highest" ]; then
make release
else
# Install dependencies
uv sync --frozen --group all --all-extras --resolution ${{ matrix.uv-resolution }}
# Linting
uv run ruff check
uv run mypy ./
# Testing
uv run pytest -vv --durations=10
fi
shell: bash
- name: Upload coverage reports
if: |
14 changes: 7 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -39,11 +39,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ github.event.inputs.python-version }}
uses: actions/setup-python@v4
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ github.event.inputs.python-version }}
cache: 'pip'
- name: Set up AllenInstitute Repo Authorization
uses: ./.github/actions/setup-ai-github-urls
with:
@@ -61,7 +61,7 @@ jobs:
- name: Bump version with bumpversion
run: |
source .venv/bin/activate
bump-my-version bump ${{ github.event.inputs.part }}
uvx --from bump-my-version bump-my-version bump ${{ github.event.inputs.part }}
- name: Commit and push with tags
if: ${{ github.event.inputs.dry-run == 'false' }}
run: |
@@ -103,11 +103,11 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ needs.bump.outputs.VERSION_TAG }}
- name: Set up Python ${{ github.event.inputs.python-version }}
uses: actions/setup-python@v4
- name: Install uv
id: setup-uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ github.event.inputs.python-version }}
cache: 'pip'
- name: Set up AllenInstitute Repo Authorization
uses: ./.github/actions/setup-ai-github-urls
with:
86 changes: 41 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -65,98 +65,94 @@ obliterate: clean-venv clean ## alias to clean, clean-venv
##@ Installation Commands
#########################

create-venv: $(PYTHON) ## Creates virtualenv
$(PYTHON):
python3 -m venv $(VENV) --prompt $(shell basename $(PACKAGE_DIR))
$(PYTHON) -m pip install --upgrade pip

install: $(INSTALL_STAMP) ## Installs package dependencies
$(INSTALL_STAMP): $(PYTHON) $(DEP_FILES)
@. $(VENV_BIN)/activate;\
$(PIP) install -e .[all];
@touch $(INSTALL_STAMP)
.uv: ## Check that uv is installed
@uv -V || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

install-release: clean-install-stamp $(PYTHON) $(DEP_FILES) ## Installs package for release
@. $(VENV_BIN)/activate;\
$(PIP) install .[release]
.PHONY: .uv

install-force: clean-install-stamp install ## Force install package dependencies
install: .uv ## Installs package dependencies
uv sync --frozen --all-extras

.PHONY: install

rebuild-lockfile: .uv ## Rebuilds the lockfile
uv lock --upgrade

.PHONY: rebuild-lockfiles

make install-release: .uv ## Installs package dependencies
uv sync --frozen --group release

.PHONY: install-release

link-packages: ## Link local packages to virtualenv
@parent_dir=$$(dirname $$(pwd)); \
local_packages=$$(ls $$parent_dir); \
dependencies=$$($(PIP) list --format freeze --exclude-editable | awk -F '==' '{print $$1}');\
dependencies=$$(uv pip list --format freeze --exclude-editable | awk -F '==' '{print $$1}');\
for local_package in $$local_packages; do \
for dependency in $$dependencies; do \
if [ $$local_package == $$dependency ]; then \
echo "Reinstalling $$local_package dependency to local override"; \
$(PIP) install -e $$parent_dir/$$local_package --no-deps; \
uv add -v --editable --frozen $$parent_dir/$$local_package; \
fi \
done; \
done

.PHONY: link-packages

unlink-packages: ## Unlink local packages from virtualenv
@parent_dir=$$(dirname $$(pwd)); \
this_package=$$(basename $$(pwd)); \
local_packages=$$(ls $$parent_dir); \
dependencies=$$($(PIP) list --format freeze --editable | awk -F '==' '{print $$1}');\
dependencies=$$(uv pip list --format freeze --editable | awk -F '==' '{print $$1}');\
is_found=0; \
for local_package in $$local_packages; do \
for dependency in $$dependencies; do \
if [ $$local_package == $$dependency ] && [ $$local_package != $$this_package ]; then \
is_found=1; \
uv remove --frozen $$local_package; \
fi; \
done \
done; \
if [ $$is_found == 1 ]; then \
echo "Found dependencies installed locally, reinstalling..."; \
make clean-install-stamp install; \
make install; \
fi

.PHONY: create-venv install install-force link-packages unlink-packages
.PHONY: .uv install install-release rebuild-lockfile link-packages unlink-packages

#######################
##@ Formatting Commands
#######################

lint-black: $(INSTALL_STAMP) ## Run black (check only)
$(VENV_BIN)/black ./ --check
lint-ruff: .uv ## Run ruff checker
uv run ruff check

lint-isort: $(INSTALL_STAMP) ## Run isort (check only)
$(VENV_BIN)/isort ./ --check
lint-mypy: .uv ## Run mypy
uv run mypy ./

lint-mypy: $(INSTALL_STAMP) ## Run mypy
$(VENV_BIN)/mypy ./
lint: lint-ruff lint-mypy ## Run all lint targets (ruff, mypy)


lint: lint-isort lint-black lint-mypy ## Run all lint targets (black, isort, mypy)
format-ruff: .uv ## Run ruff formatter
uv run ruff check --fix
uv run ruff format

format: format-ruff ## Run all formatters (ruff)

format-black: $(INSTALL_STAMP) ## Format code using black
$(VENV_BIN)/black ./

format-isort: $(INSTALL_STAMP) ## Format code using isort
$(VENV_BIN)/isort ./


format: format-isort format-black ## Run all formatters (black, isort)

.PHONY: lint-isort lint-black lint-mypy lint format-lint format-black format-mypy format
.PHONY: lint-ruff lint-mypy lint format-ruff format-mypy format

#####################
##@ Testing Commands
#####################

pytest: $(INSTALL_STAMP) ## Run test (pytest)
$(VENV_BIN)/pytest -vv --durations=10

tox: $(INSTALL_STAMP) ## Run Test in tox environment
$(VENV_BIN)/tox
pytest: install ## Run test (pytest)
uv run pytest -vv --durations=10

test: pytest ## Run Standard Tests

.PHONY: pytest tox test

.PHONY: pytest test

#####################
##@ Inspect Commands
@@ -165,14 +161,14 @@ test: pytest ## Run Standard Tests
coverage-server: $(INSTALL_STAMP) ## Run coverage server
$(PYTHON) -m http.server $(COVERAGE_SERVER_PORT) -d $(COVERAGE_DIR)

.PHONY: coverage-server

#####################
##@ Release Commands
#####################

dist: install-release ## Build source and wheel package
@. $(VENV_BIN)/activate;\
$(PYTHON) -m build;
uv build

reinstall: obliterate install ## Recreate environment and install

@@ -182,4 +178,4 @@ post-build: lint test ## Run linters and tests
release: pre-build build post-build ## Runs pre-build, build, post-build
run: release

.PHONY: reinstall pre-build build post-build release run
.PHONY: dist reinstall pre-build build post-build release run
65 changes: 44 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -26,26 +26,50 @@ dependencies = [

[project.optional-dependencies]
all = [
"aibs-informatics-test-resources[formatting]",
"aibs-informatics-test-resources[linting]",
"aibs-informatics-test-resources[typing]",
]

formatting = [
"black==23.11.0",
"flake8~=6.1.0",
linting = [
"black~=23.11.0",
"isort~=5.10",
"ruff~=0.9",
]

typing = [
"mypy~=1.6",
]

[dependency-groups]

dev = [
{ include-group = 'linting' },
{ include-group = 'typing' },
]

release = [
"build",
{ include-group = 'bump' },
{ include-group = 'build' }
]

linting = [
"ruff~=0.9",
]

typing = [
"mypy",
]

bump = [
"bump-my-version",
]

build = [
"build",
"wheel",
]


[tool.setuptools.packages.find]
where = ["src"]

@@ -58,6 +82,14 @@ Homepage = "https://github.com/AllenInstitute/aibs-informatics-test-resources/"
Issues = "https://github.com/AllenInstitute/aibs-informatics-test-resources/issues"
Repository = "https://github.com/AllenInstitute/aibs-informatics-test-resources/"


# -----------------------------------------------------------------------------
## astral-uv Configurations
# https://docs.astral.sh/uv/getting-started/
# -----------------------------------------------------------------------------

[tool.uv]

# -----------------------------------------------------------------------------
## Pyright Configurations
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md
@@ -187,25 +219,16 @@ ignore_errors = false


# -----------------------------------------------------------------------------
## Black Configurations
# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#what-on-earth-is-a-pyproject-toml-file
## ruff Configurations
# https://beta.ruff.rs/docs/configuration/
# -----------------------------------------------------------------------------


[tool.black]
[tool.ruff]
line-length = 99
include = '\.pyi?$'

# -----------------------------------------------------------------------------
## isort Configurations
# https://pycqa.github.io/isort/docs/configuration/config_files.html
# -----------------------------------------------------------------------------
src = ["src", "test"]

[tool.isort]
# required for compatibility with black:
line_length = 99
profile = "black"
src_paths = ["src", "test"]
[tool.ruff.lint]
select = ["E", "F", "W", "C90"]

# -----------------------------------------------------------------------------
## bumpversion Configurations
@@ -232,4 +255,4 @@ tag_name = "v{new_version}"
[[tool.bumpversion.files]]
filename = "src/aibs_informatics_test_resources/__version__.py"
search = "__version__ = \"{current_version}\""
replace = "__version__ = \"{new_version}\""
replace = "__version__ = \"{new_version}\""
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

7 changes: 6 additions & 1 deletion src/aibs_informatics_test_resources/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
__all__ = [
"BaseTest",
"does_not_raise",
]

import json
import os
import re
@@ -7,7 +12,7 @@
from contextlib import nullcontext as does_not_raise
from copy import deepcopy
from pathlib import Path
from typing import Any, Callable, ClassVar, List, Optional, Tuple, Union, cast
from typing import Any, ClassVar, List, Optional, Tuple, Union
from unittest.mock import MagicMock, patch

import pytest
Loading

0 comments on commit 5d72d72

Please sign in to comment.