Skip to content

Commit

Permalink
Update build to use uv and fix publishing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-zen committed Dec 7, 2024
1 parent ba4a4e0 commit 24b822f
Show file tree
Hide file tree
Showing 4 changed files with 918 additions and 48 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ permissions:

env:
TERM: xterm
PYTHON_VERSION: 3.12

jobs:
packages-build:
Expand All @@ -27,23 +26,23 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: "pyproject.toml"

- uses: eifinger/setup-rye@v4
- uses: astral-sh/setup-uv@v4

- name: Check format
run: |
make check-format || true
BOLDRED=$(tput bold && tput setaf 1)
RESET=$(tput sgr0)
echo "${BOLDRED}==> We won't fail on formatting errors for the time being, but we will in the future.${RESET}"
echo "${BOLDRED}==> We won't penalise formatting errors for the time being, but we will in the future.${RESET}"
- name: Check lint
run: |
make check-lint || true
BOLDRED=$(tput bold && tput setaf 1)
RESET=$(tput sgr0)
echo "${BOLDRED}==> We won't fail on lint errors for the time being, but we will in the future.${RESET}"
echo "${BOLDRED}==> We won’t enforce linting errors for the time being, but we will in the future.${RESET}"
- name: Build packages
run: make build-dist
Expand All @@ -64,9 +63,9 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: "pyproject.toml"

- uses: eifinger/setup-rye@v4
- uses: astral-sh/setup-uv@v4

- name: Check Dockerfile
run: make check-docker
Expand All @@ -92,9 +91,9 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: "pyproject.toml"

- uses: eifinger/setup-rye@v4
- uses: astral-sh/setup-uv@v4

- name: Check version matching the tag
run: make check-version
Expand All @@ -112,9 +111,9 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: "pyproject.toml"

- uses: eifinger/setup-rye@v4
- uses: astral-sh/setup-uv@v4

- name: Download packages
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -143,9 +142,9 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version-file: "pyproject.toml"

- uses: eifinger/setup-rye@v4
- uses: astral-sh/setup-uv@v4

- name: Login to DockerHub
if: ${{ env.DOCKER_USERNAME != '' }}
Expand Down
74 changes: 44 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ ROOT_DIR := $(shell echo $(dir $(lastword $(MAKEFILE_LIST))) | sed 's|/*$$||')

SHELL := /bin/bash

VERSION = $(shell rye version)
define version
$(shell uv run python -c "from oncodriveclustl import __version__; print(__version__)")
endef

GIT_TAG_OR_SHA = $(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)
define git_tag_or_sha
$(shell git describe --tags --exact-match 2>/dev/null || git rev-parse --short HEAD)
endef

IMAGE_TAG = $(VERSION)
IMAGE := bbglab/oncodriveclustl:$(IMAGE_TAG)
define image
bbglab/oncodriveclustl:$(call version)
endef

BOLDRED := $(shell tput bold && tput setaf 1)
BOLDGREEN := $(shell tput bold && tput setaf 2)
Expand All @@ -34,28 +39,37 @@ help:
@echo "$(BOLDGREEN) clean $(WHITE)-> Clean the working directory (build files, virtual environments, caches)"
@echo "$(RESET)"

.PHONY: rye-installed
rye-installed:
@if ! which rye > /dev/null; then \
echo "$(BOLDRED)This project build is managed by $(BOLDYELLOW)rye$(BOLDRED), which is not installed.$(RESET)"; \
.PHONY: uv-installed
uv-installed:
@if ! which uv > /dev/null; then \
echo "$(BOLDRED)This project build is managed by $(BOLDYELLOW)uv$(BOLDRED), which is not installed.$(RESET)"; \
echo "$(LIGHTBLUE)Please follow these instructions to install it:$(RESET)"; \
echo "$(LIGHTBLUE)--> $(BOLDBLUE)https://rye.astral.sh/guide/installation/$(RESET)"; \
echo "$(LIGHTBLUE)--> $(BOLDBLUE)https://docs.astral.sh/uv/#getting-started$(RESET)"; \
exit 1; \
fi

.PHONY: ruff-installed
ruff-installed: uv-installed
@if ! which ruff > /dev/null; then \
echo "$(BOLDRED)This project requires $(BOLDYELLOW)ruff$(BOLDRED), which is not installed.$(RESET)"; \
echo "$(LIGHTBLUE)Installing it with $(BOLDYELLOW)uv tool install ruff$(RESET)"; \
uv tool install ruff; \
ruff --version; \
fi

.PHONY: checks
checks: check-format check-lint check-docker

.PHONY: check-format
check-format: rye-installed
check-format: ruff-installed
@echo "$(BOLDGREEN)Checking code format ...$(RESET)"
rye fmt --check
ruff format --check
@echo "$(BOLDGREEN)==> Success!$(RESET)"

.PHONY: check-lint
check-lint: rye-installed
check-lint: ruff-installed
@echo "$(BOLDGREEN)Checking lint ...$(RESET)"
rye lint
ruff check
@echo "$(BOLDGREEN)==> Success!$(RESET)"

.PHONY: check-docker
Expand All @@ -69,47 +83,47 @@ check-docker:
@echo "$(BOLDGREEN)==> Success!$(RESET)"

.PHONY: check-version
check-version: rye-installed
check-version: uv-installed
@echo "$(BOLDGREEN)Checking that the version matches the tag ...$(RESET)"
@if [ "$(VERSION)" != "$(GIT_TAG_OR_SHA)" ]; then \
echo "$(BOLDRED)==> Version $(BOLDYELLOW)$(VERSION)$(BOLDRED) doesn't match the git tag $(BOLDYELLOW)$(GIT_TAG_OR_SHA)$(BOLDRED) !!!$(RESET)"; \
@if [ "$(call version)" != "$(call git_tag_or_sha)" ]; then \
echo "$(BOLDRED)==> Version $(BOLDYELLOW)$(call version)$(BOLDRED) doesn't match the git tag $(BOLDYELLOW)$(call git_tag_or_sha)$(BOLDRED) !!!$(RESET)"; \
echo "$(BOLDRED)==> Please update the $(BOLDYELLOW)__version__$(BOLDRED) in $(BOLDYELLOW)oncodrivefml/__init__.py$(BOLDRED) and re-create the tag.$(RESET)"; \
exit 1; \
fi
@echo "$(BOLDGREEN)==> Success!$(RESET)"

.PHONY: format
format: rye-installed
format: ruff-installed
@echo "$(BOLDGREEN)Formatting code ...$(RESET)"
rye fmt
ruff format

.PHONY: build-dist
build-dist: rye-installed
build-dist: uv-installed
@echo "$(BOLDGREEN)Building packages ...$(RESET)"
rye build
uv build

.PHONY: publish-dist
publish-dist: rye-installed
@echo "$(BOLDGREEN)Publishing OncodriveCLUSTL $(BOLDYELLOW)$(VERSION)$(BOLDGREEN) to PyPI ...$(RESET)"
publish-dist: uv-installed
@echo "$(BOLDGREEN)Publishing OncodriveCLUSTL $(BOLDYELLOW)$(call version)$(BOLDGREEN) to PyPI ...$(RESET)"
@[[ -z "$(PYPI_TOKEN)" ]] && (echo "$(BOLDRED)==> Missing PyPI token !!!$(RESET)"; exit 1)
rye publish --token $(PYPI_TOKEN)
uv publish --token $(PYPI_TOKEN)

.PHONY: build-image
build-image: rye-installed
@echo "$(BOLDGREEN)Building Docker image $(BOLDYELLOW)$(IMAGE)$(BOLDGREEN) ...$(RESET)"
docker build --progress=plain -t $(IMAGE) .
build-image: uv-installed
@echo "$(BOLDGREEN)Building Docker image $(BOLDYELLOW)$(call image)$(BOLDGREEN) ...$(RESET)"
docker build --progress=plain -t $(call image) .
@echo "$(BOLDGREEN)==> Success!$(RESET)"

.PHONY: build-image
push-image: rye-installed
push-image: uv-installed
@echo "$(BOLDGREEN)Pushing the Docker image into the DockerHub ...$(RESET)"
docker push $(IMAGE)
docker push $(call image)
@echo "$(BOLDGREEN)==> Success!$(RESET)"

.PHONY: run-example
run-example: rye-installed
run-example: uv-installed
@echo "$(BOLDGREEN)Running example ...$(RESET)"
rye run oncodriveclustl \
uv run oncodriveclustl \
-i example/PAAD.tsv.gz -r example/cds.hg19.regions.gz -o example/output \
-sw 15 -cw 15 -simw 35 -sim region_restricted --concatenate --clustplot -e KRAS
@echo "$(BOLDGREEN)==> Success!$(RESET)"
Expand Down
6 changes: 1 addition & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
"tqdm==4.66.5",
]
readme = "README.md"
requires-python = ">=3.5,<3.13"
requires-python = ">=3.10,<3.13"
license = { file = "LICENSE" }

[project.scripts]
Expand All @@ -32,10 +32,6 @@ license = { file = "LICENSE" }
requires = ["hatchling"]
build-backend = "hatchling.build"

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

[tool.hatch.version]
path = "oncodriveclustl/__init__.py"

Expand Down
Loading

0 comments on commit 24b822f

Please sign in to comment.