Skip to content

Commit

Permalink
Merge pull request #25 from AllenInstitute/feature/switch-to-uv
Browse files Browse the repository at this point in the history
Switch to using uv and ruff
  • Loading branch information
rpmcginty authored Jan 15, 2025
2 parents f972fc6 + 877cd54 commit 3f88ff7
Show file tree
Hide file tree
Showing 59 changed files with 1,262 additions and 338 deletions.
27 changes: 22 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,38 @@ 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"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install 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/configure-org-repo-authorization
with:
token: ${{ secrets.AI_PACKAGES_TOKEN }}
ssh_private_key: ${{ secrets.AIBSGITHUB_PRIVATE_KEY }}
- 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: |
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.AIBSGITHUB_PRIVATE_KEY }}
- 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/configure-org-repo-authorization
with:
Expand Down Expand Up @@ -105,11 +105,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/configure-org-repo-authorization
with:
Expand Down
94 changes: 45 additions & 49 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,41 @@ 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
.uv: ## Check that uv is installed
@uv -V || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

install: $(INSTALL_STAMP) ## Installs package dependencies
$(INSTALL_STAMP): $(PYTHON) $(DEP_FILES)
@. $(VENV_BIN)/activate;\
$(PIP) install -e .[dev];
@touch $(INSTALL_STAMP)

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


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


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

install-force: clean-install-stamp install ## Force install package dependencies

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 pip install -e $$parent_dir/$$local_package; \
fi \
done; \
done


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 \
Expand All @@ -110,53 +110,42 @@ unlink-packages: ## Unlink local packages from virtualenv
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-isort: $(INSTALL_STAMP) ## Run isort (check only)
$(VENV_BIN)/isort ./ --check

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

lint-mypy: .uv ## Run mypy
uv run mypy ./

lint: lint-isort lint-black lint-mypy ## Run all lint targets (black, isort, mypy)
lint: lint-ruff lint-mypy ## Run all lint targets (ruff, mypy)


format-black: $(INSTALL_STAMP) ## Format code using black
$(VENV_BIN)/black ./
format-ruff: .uv ## Run ruff formatter
uv run ruff check --fix
uv run ruff format

format-isort: $(INSTALL_STAMP) ## Format code using isort
$(VENV_BIN)/isort ./
format: format-ruff ## Run all formatters (ruff)


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
Expand All @@ -165,22 +154,28 @@ 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

#####################
##@ Packaging Commands
##@ Docker Commands
#####################

package: $(INSTALL_STAMP) ## Build package distribution
$(PIP) install -U build
$(PYTHON) -m build
docker-build: ## Build docker image
@docker build \
--ssh default \
--platform linux/amd64 \
--tag aibs-informatics-core:latest \
--file $(PACKAGE_DIR)/docker/Dockerfile \
$(PACKAGE_DIR)

.PHONY: docker-build

#####################
##@ 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

Expand All @@ -190,4 +185,5 @@ 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

27 changes: 24 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
FROM public.ecr.aws/lts/ubuntu:22.04_stable

ARG PYTHON_VERSION=3.11
ARG UV_VERSION=0.5.18

# Update and install deps
RUN apt-get update -y && apt-get install -y \
python3.9 \
# uv installer requires curl (and certificates) to download the release archive
RUN apt-get update -y && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
python${PYTHON_VERSION} \
python3-pip

# Download the latest installer
# ENV UV_INSTALL_DIR="/opt/.uv"
# ENV UV_UNMANAGED_INSTALL="/opt/.uv"
RUN if [ -n "$UV_VERSION" ]; then \
curl -sSL "https://astral.sh/uv/${UV_VERSION}/install.sh" -o /uv-installer.sh; \
else \
curl -sSL "https://astral.sh/uv/install.sh" -o /uv-installer.sh; \
fi

# Run the installer then remove it
RUN env UV_INSTALL_DIR='/opt/.uv' UV_UNMANAGED_INSTALL="/opt/.uv" sh /uv-installer.sh \
&& rm /uv-installer.sh

COPY . /opt/python/aibs-informatics-core/

WORKDIR /opt/python/aibs-informatics-core
RUN pip3 install --no-cache-dir .
RUN /opt/.uv/uv pip install --system .
WORKDIR /

RUN rm -rf /opt/.uv

CMD ["python3"]
58 changes: 40 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,35 @@ dependencies = [

[project.optional-dependencies]
dev = [
"aibs-informatics-test-resources[all]~=0.0.4",
"aibs-informatics-test-resources~=0.1",
]

[dependency-groups]

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

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

linting = [
"ruff~=0.9",
]

typing = [
"mypy~=1.13",
]

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

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

Expand All @@ -58,6 +81,13 @@ Homepage = "https://github.com/AllenInstitute/aibs-informatics-core/"
Issues = "https://github.com/AllenInstitute/aibs-informatics-core/issues"
Repository = "https://github.com/AllenInstitute/aibs-informatics-core/"

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

[tool.uv]


# -----------------------------------------------------------------------------
## Pyright Configurations
Expand Down Expand Up @@ -200,25 +230,17 @@ 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"]
# ignore = ["E501"]

# -----------------------------------------------------------------------------
## bumpversion Configurations
Expand Down
Loading

0 comments on commit 3f88ff7

Please sign in to comment.