Skip to content

Commit f9568a3

Browse files
authored
Merge branch 'main' into explore-public-service-api
2 parents 8d18eb3 + 2509699 commit f9568a3

37 files changed

+1278
-122
lines changed

.github/workflows/tycho.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Tycho
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
types: [ opened, synchronize, reopened, edited ]
9+
paths:
10+
- "src/tycho/**"
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build-tycho:
17+
runs-on: ubuntu-latest
18+
defaults:
19+
run:
20+
working-directory: ./src/tycho
21+
steps:
22+
- uses: actions/checkout@v5
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v7
25+
with:
26+
version: "0.9.7"
27+
enable-cache: true
28+
- name: Set up Python
29+
uses: actions/setup-python@v6
30+
with:
31+
python-version-file: "./src/tycho/.python-version"
32+
- name: Install the project
33+
run: uv sync --locked --all-extras --dev
34+
35+
build-docker-tycho:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v5
39+
- name: Build tycho Docker image
40+
run: bin/compose build tycho
41+
42+
lint-tycho:
43+
needs: build-tycho
44+
runs-on: ubuntu-latest
45+
defaults:
46+
run:
47+
working-directory: ./src/tycho
48+
env:
49+
TYCHO_SECRET_KEY: the_secret_key
50+
TYCHO_DATABASE_URL: psql://tycho:pass@postgresql:5432/tycho
51+
steps:
52+
- uses: actions/checkout@v5
53+
- name: Install uv
54+
uses: astral-sh/setup-uv@v7
55+
with:
56+
version: "0.9.7"
57+
enable-cache: true
58+
- name: Set up Python
59+
uses: actions/setup-python@v6
60+
with:
61+
python-version-file: "./src/tycho/.python-version"
62+
- name: Lint with Ruff
63+
run: uv run ruff check .
64+
- name: Lint format with Ruff
65+
run: uv run ruff format --check .
66+
- name: Lint with MyPy
67+
run: uv run mypy .
68+
69+
test-tycho:
70+
needs: build-tycho
71+
runs-on: ubuntu-latest
72+
services:
73+
postgresql:
74+
image: postgres:16.10
75+
env:
76+
POSTGRES_DB: test-tycho
77+
POSTGRES_USER: tycho
78+
POSTGRES_PASSWORD: pass
79+
TEST: true
80+
options: >-
81+
--health-cmd pg_isready
82+
--health-interval 10s
83+
--health-timeout 5s
84+
--health-retries 5
85+
ports:
86+
- 5432:5432
87+
defaults:
88+
run:
89+
working-directory: ./src/tycho
90+
env:
91+
TYCHO_SECRET_KEY: the_secret_key
92+
TYCHO_DATABASE_URL: psql://tycho:pass@postgresql:5432/test-tycho
93+
steps:
94+
- uses: actions/checkout@v5
95+
- name: Install uv
96+
uses: astral-sh/setup-uv@v7
97+
with:
98+
version: "0.9.7"
99+
enable-cache: true
100+
- name: Set up Python
101+
uses: actions/setup-python@v6
102+
with:
103+
python-version-file: "./src/tycho/.python-version"
104+
- name: Test with pytest
105+
run: uv run pytest .

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ share/python-wheels/
2929
*.egg
3030
MANIFEST
3131

32-
# Installed pipenv packages
32+
# Installed packages
3333
.cache
3434
.local
3535

@@ -63,3 +63,4 @@ scripts/*.csv
6363
# Data
6464
*.csv
6565
*.json
66+
.coverage

.pre-commit-config.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,3 @@ repos:
99
- id: trailing-whitespace
1010
- id: debug-statements
1111
files: ^src/.+\.py$
12-
13-
# Python linting and formatting with Make
14-
- repo: https://github.com/astral-sh/ruff-pre-commit
15-
# Ruff version.
16-
rev: v0.13.2
17-
hooks:
18-
# Run the linter.
19-
- id: ruff-check
20-
args: [--config, dev/pyproject.toml]
21-
# Run the formatter.
22-
- id: ruff-format
23-
args: [--config, dev/pyproject.toml]

Makefile

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22
SHELL := /bin/bash
33

44
# -- Docker
5-
COMPOSE = bin/compose
6-
COMPOSE_UP = $(COMPOSE) up -d --remove-orphans
7-
COMPOSE_RUN = $(COMPOSE) run --rm --no-deps
8-
COMPOSE_RUN_DEV_UV = $(COMPOSE_RUN) dev uv run --project dev
5+
COMPOSE = bin/compose
6+
COMPOSE_UP = $(COMPOSE) up -d --remove-orphans
7+
COMPOSE_RUN = $(COMPOSE) run --rm --no-deps
8+
COMPOSE_RUN_DEV_UV = $(COMPOSE_RUN) dev uv run
9+
COMPOSE_RUN_TYCHO_UV = $(COMPOSE_RUN) tycho uv run
910

1011
default: help
1112

1213
## -- Files
1314
.pre-commit-cache:
1415
mkdir .pre-commit-cache
1516

17+
.git/hooks/_commons.inc.sh:
18+
cp bin/_commons.inc.sh .git/hooks/_commons.inc.sh
19+
1620
.git/hooks/pre-commit:
1721
cp bin/git-pre-commit-hook .git/hooks/pre-commit
1822

@@ -22,15 +26,18 @@ default: help
2226
### BOOTSTRAP
2327
bootstrap: ## setup development environment (build dev service and install git hooks)
2428
bootstrap: \
25-
build \
26-
jupytext--to-ipynb
29+
build \
30+
migrate \
31+
create-superuser \
32+
jupytext--to-ipynb
2733
.PHONY: bootstrap
2834

2935
git-hooks: ## install pre-commit hook
3036
git-hooks: \
31-
.pre-commit-cache \
32-
.git/hooks/pre-commit \
33-
.git/hooks/commit-msg
37+
.pre-commit-cache \
38+
.git/hooks/_commons.inc.sh \
39+
.git/hooks/pre-commit \
40+
.git/hooks/commit-msg
3441
.PHONY: git-hooks
3542

3643
### BUILD
@@ -46,6 +53,10 @@ build-notebook: ## build custom jupyter notebook image
4653
@$(COMPOSE) build notebook
4754
.PHONY: build-notebook
4855

56+
build-tycho: ## build tycho image
57+
@$(COMPOSE) build tycho
58+
.PHONY: build-tycho
59+
4960
jupytext--to-md: ## convert local ipynb files into md
5061
bin/jupytext --to md **/*.ipynb
5162
.PHONY: jupytext--to-md
@@ -63,6 +74,21 @@ logs-notebook: ## display notebook logs (follow mode)
6374
@$(COMPOSE) logs -f notebook
6475
.PHONY: logs-notebook
6576

77+
logs-tycho: ## display tycho logs (follow mode)
78+
@$(COMPOSE) logs -f tycho
79+
.PHONY: logs-tycho
80+
81+
### Setup
82+
migrate: ## migrate tycho database
83+
@echo "Migrating tycho database…"
84+
@bin/manage migrate
85+
.PHONY: migrate
86+
87+
create-superuser: ## create tycho super user
88+
@echo "Creating tycho super user…"
89+
@bin/manage createsuperuser --noinput || true
90+
.PHONY: create-superuser
91+
6692
### RUN
6793
run-all: ## run the whole stack
6894
run-all: \
@@ -78,16 +104,22 @@ run-es: ## run the elasticsearch service
78104
$(COMPOSE_UP) elasticsearch
79105
.PHONY: run-es
80106

107+
run-tycho: ## run the tycho service
108+
$(COMPOSE_UP) tycho
109+
.PHONY: run-tycho
110+
81111
## LINT
82112
# -- Global linting
83113
lint: ## lint all sources
84114
lint: \
85-
lint-notebook
115+
lint-notebook \
116+
lint-tycho
86117
.PHONY: lint
87118

88119
lint-fix: ## lint and fix all sources
89120
lint-fix: \
90-
lint-notebook-fix
121+
lint-notebook-fix \
122+
lint-tycho-fix
91123
.PHONY: lint-fix
92124

93125
# -- Per-service linting
@@ -103,7 +135,41 @@ lint-notebook-fix: ## lint and fix notebook python sources
103135
$(COMPOSE_RUN_DEV_UV) ruff format src/notebook/
104136
.PHONY: lint-notebook-fix
105137

106-
### MANAGE docker services
138+
lint-tycho: ## lint tycho python sources
139+
lint-tycho: \
140+
lint-tycho-ruff \
141+
lint-tycho-mypy
142+
.PHONY: lint-tycho
143+
144+
lint-tycho-ruff: ## lint tycho python sources with ruff
145+
@echo 'lint:tycho-ruff started…'
146+
$(COMPOSE_RUN_TYCHO_UV) ruff check .
147+
$(COMPOSE_RUN_TYCHO_UV) ruff format --check .
148+
.PHONY: lint-tycho-ruff
149+
150+
lint-tycho-ruff-fix: ## lint and fix tycho python sources with ruff
151+
@echo 'lint:tycho-ruff-fix started…'
152+
$(COMPOSE_RUN_TYCHO_UV) ruff check --fix .
153+
$(COMPOSE_RUN_TYCHO_UV) ruff format .
154+
.PHONY: lint-tycho-ruff-fix
155+
156+
lint-tycho-mypy: ## lint tycho python sources with mypy
157+
@echo 'lint:tycho-mypy started…'
158+
$(COMPOSE_RUN_TYCHO_UV) mypy .
159+
.PHONY: lint-tycho-mypy
160+
161+
## TEST
162+
test: ## test all services
163+
test: \
164+
test-tycho
165+
.PHONY: test
166+
167+
test-tycho: ## test tycho python sources
168+
@echo 'test:tychostarted…'
169+
$(COMPOSE_RUN_TYCHO_UV) pytest
170+
.PHONY: test-tycho
171+
172+
## MANAGE docker services
107173
status: ## an alias for "docker compose ps"
108174
@$(COMPOSE) ps
109175
.PHONY: status

bin/_commons.inc.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# Bash library for utility scripts
3+
#
4+
# shellcheck shell=bash
5+
6+
declare DOCKER_USER
7+
declare -i DOCKER_UID
8+
declare -i DOCKER_GID
9+
10+
DOCKER_UID="$(id -u)"
11+
DOCKER_GID="$(id -g)"
12+
# Use a higher GID for MacOS users to prevent permission issues with the default
13+
# GID=20
14+
if [[ "${OSTYPE}" =~ "darwin" ]]; then
15+
DOCKER_GID=1000
16+
fi
17+
DOCKER_USER="${DOCKER_UID}:${DOCKER_GID}"
18+
19+
export DOCKER_UID
20+
export DOCKER_GID
21+
export DOCKER_USER
22+
23+
24+
function compose(){
25+
26+
docker compose "$@"
27+
}
28+
29+
30+
function compose_run(){
31+
32+
if [[ -z "${2}" ]]; then
33+
echo "usage: compose_run [--no-deps] SERVICE COMMAND"
34+
exit 1
35+
fi
36+
37+
# Arguments
38+
declare -i no_deps
39+
if [[ "$1" == "--no-deps" ]]; then
40+
no_deps=1
41+
shift
42+
fi
43+
44+
declare service="${1}"
45+
shift
46+
47+
declare user="${DOCKER_USER}"
48+
declare volume="./src/${service}:/app"
49+
declare -a args=(--rm --user "${user}" --volume "${volume}")
50+
51+
# Prevent 'the input device is not a TTY' error from `docker compose run`
52+
# by disabling TTY when standard output is not a TTY
53+
if [[ "$(tty 2>/dev/null)" == "not a tty" ]]; then
54+
args+=(--no-TTY)
55+
fi
56+
57+
# Do not run related services
58+
if [[ no_deps -eq 1 ]]; then
59+
args+=(--no-deps)
60+
fi
61+
62+
compose run \
63+
"${args[@]}" \
64+
"${service}" \
65+
"$@"
66+
}

bin/compose

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,14 @@
22

33
set -eo pipefail
44

5-
declare DOCKER_USER
6-
DOCKER_UID="$(id -u)"
7-
DOCKER_GID="$(id -g)"
5+
declare cmd
86

7+
source "$(dirname "$(readlink -f "$0")")/_commons.inc.sh"
98

10-
DOCKER_USER="${DOCKER_UID}:${DOCKER_GID}"
11-
12-
extra_args=()
13-
# Prevent 'the input device is not a TTY' error from `docker compose run`
14-
# by disabling TTY when standard output is not a TTY
15-
if [[ "$1" == run && "$(tty 2>/dev/null)" == "not a tty" ]]; then
16-
extra_args=(run --no-TTY)
9+
cmd="compose"
10+
if [[ "$1" == run ]]; then
11+
cmd="compose_run"
1712
shift
1813
fi
1914

20-
# On macOS, GID 20 is reserved for the "staff" group which may cause permission issues
21-
if [[ "$OSTYPE" == "darwin"* ]] && [[ "$DOCKER_GID" -le "20" ]]; then
22-
DOCKER_GID="1000"
23-
fi
24-
25-
26-
DOCKER_USER=${DOCKER_USER} \
27-
DOCKER_UID=${DOCKER_UID} \
28-
DOCKER_GID=${DOCKER_GID} \
29-
docker compose "${extra_args[@]}" "$@"
15+
eval $cmd "$@"

bin/cz

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/usr/bin/env bash
22

3+
set -eo pipefail
4+
35
cz --config dev/pyproject.toml "$@"

0 commit comments

Comments
 (0)