Skip to content

Commit e63c9e6

Browse files
committed
Merge remote-tracking branch 'origin/master' into prod
2 parents b334261 + e593ee0 commit e63c9e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2817
-1539
lines changed

.flake8

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/documentation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ assignees: ""
77
---
88

99
## Type
10-
* [ ] Conent inaccurate
10+
11+
* [ ] Content inaccurate
1112
* [ ] Content missing
1213
* [ ] Typo
1314

.github/pull_request_template.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
## Description
1414
<!--Describe what the change is**-->
1515

16-
## Checklist:
16+
## Checklist
17+
1718
- [ ] Add test cases to all the changes you introduce
18-
- [ ] Run `poetry run pytest` locally to ensure all linter checks pass
19+
- [ ] Run `make lint` and `make test` locally to ensure all linter checks and testing pass
1920
- [ ] Update the documentation if necessary
2021

2122
## Steps to Test This Pull Request

.github/workflows/python.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@ jobs:
1212
runs-on: ubuntu-latest
1313
timeout-minutes: 10
1414
steps:
15-
- uses: actions/checkout@v2
15+
- name: Check out
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
1619

17-
- name: Set up Python 3.8
18-
uses: actions/setup-python@v1
20+
- name: Install the latest version of uv
21+
uses: astral-sh/setup-uv@v5
1922
with:
20-
python-version: 3.8
23+
enable-cache: true
24+
version: "latest"
2125

2226
- name: Install dependencies
2327
run: |
24-
pip install -r requirements.txt -r requirements-dev.txt -c constraints-3.8.txt
25-
pip install black==19.10b0 click==7.1.2
28+
uv sync --group dev
2629
2730
- name: Run linters
2831
run: make lint

Dockerfile

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
11
ARG AIRFLOW_VERSION=1.10.15
22
ARG PYTHON_VERSION=3.8
3+
ARG PLATFORM=linux/amd64
34

4-
FROM apache/airflow:${AIRFLOW_VERSION}-python${PYTHON_VERSION}
5+
FROM --platform=${PLATFORM} ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS builder
6+
7+
ENV UV_COMPILE_BYTECODE=1 \
8+
UV_LINK_MODE=copy \
9+
UV_PYTHON_DOWNLOADS=0
10+
11+
RUN apt-get update && \
12+
apt-get install -y gcc libc6-dev --no-install-recommends
13+
14+
WORKDIR /app
15+
16+
COPY ./pyproject.toml .
17+
COPY ./uv.lock .
18+
19+
RUN --mount=type=cache,target=/root/.cache/uv \
20+
--mount=type=bind,source=uv.lock,target=uv.lock \
21+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
22+
uv sync --frozen --no-install-project --no-dev
23+
24+
RUN --mount=type=cache,target=/root/.cache/uv \
25+
uv sync --frozen --no-install-project --no-dev
26+
27+
28+
FROM --platform=${PLATFORM} apache/airflow:${AIRFLOW_VERSION}-python${PYTHON_VERSION}
529

630
USER root
731

@@ -21,13 +45,10 @@ RUN chmod +x /entrypoint.sh
2145

2246
USER airflow
2347

24-
COPY ./requirements.txt ${AIRFLOW_HOME}/requirements.txt
25-
COPY ./constraints-3.8.txt ${AIRFLOW_HOME}/constraints-3.8.txt
26-
27-
RUN pip install --no-cache-dir -r ${AIRFLOW_HOME}/requirements.txt --constraint constraints-3.8.txt
48+
COPY --from=builder --chown=airflow:airflow /app /app
49+
ENV PATH="/app/.venv/bin:$PATH"
2850

2951
COPY airflow.cfg ${AIRFLOW_HOME}/airflow.cfg
30-
3152
COPY --chown=airflow:root dags ${AIRFLOW_HOME}/dags
3253

3354
ENTRYPOINT ["/entrypoint.sh"]

Dockerfile.test

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
ARG AIRFLOW_VERSION=1.10.15
22
ARG PYTHON_VERSION=3.8
3+
ARG PLATFORM=linux/amd64
34

4-
FROM apache/airflow:${AIRFLOW_VERSION}-python${PYTHON_VERSION}
5+
FROM --platform=${PLATFORM} ghcr.io/astral-sh/uv:python${PYTHON_VERSION}-bookworm-slim AS builder
6+
7+
ENV UV_COMPILE_BYTECODE=1 \
8+
UV_LINK_MODE=copy \
9+
UV_PYTHON_DOWNLOADS=0
10+
11+
RUN apt-get update && \
12+
apt-get install -y gcc libc6-dev --no-install-recommends
13+
14+
WORKDIR /app
15+
16+
COPY ./pyproject.toml .
17+
COPY ./uv.lock .
18+
19+
RUN --mount=type=cache,target=/root/.cache/uv \
20+
--mount=type=bind,source=uv.lock,target=uv.lock \
21+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
22+
uv sync --frozen --no-install-project --group dev
23+
24+
RUN --mount=type=cache,target=/root/.cache/uv \
25+
uv sync --frozen --group dev
26+
27+
FROM --platform=${PLATFORM} apache/airflow:${AIRFLOW_VERSION}-python${PYTHON_VERSION}
528

629
USER root
730

@@ -21,14 +44,10 @@ RUN chmod +x /entrypoint.sh
2144

2245
USER airflow
2346

24-
COPY ./requirements.txt ${AIRFLOW_HOME}/requirements.txt
25-
COPY ./requirements-dev.txt ${AIRFLOW_HOME}/requirements-dev.txt
26-
COPY ./constraints-3.8.txt ${AIRFLOW_HOME}/constraints-3.8.txt
27-
28-
RUN pip install --no-cache-dir -r ${AIRFLOW_HOME}/requirements.txt -r ${AIRFLOW_HOME}/requirements-dev.txt --constraint constraints-3.8.txt
47+
COPY --from=builder --chown=airflow:airflow /app /app
48+
ENV PATH="/app/.venv/bin:$PATH"
2949

3050
COPY airflow.cfg ${AIRFLOW_HOME}/airflow.cfg
31-
3251
COPY --chown=airflow:root dags ${AIRFLOW_HOME}/dags
3352

3453
ENV AIRFLOW_TEST_MODE=True

Makefile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
lint:
2-
black . --check
3-
isort --check-only .
4-
flake8 .
5-
mypy dags/ tests/
2+
uv run ruff check .
3+
uv run ruff format .
4+
uv run mypy dags/ tests/
65

76
format:
8-
black .
9-
isort .
7+
uv run ruff check . --fix
8+
uv run ruff format .
109

1110
test:
12-
PYTHONPATH=./dags pytest
11+
PYTHONPATH=./dags uv run pytest
1312

1413
coverage:
15-
PYTHONPATH=./dags pytest --cov=dags tests
14+
PYTHONPATH=./dags uv run pytest --cov=dags tests
1615

1716
build-dev:
1817
docker-compose -f ./docker-compose-dev.yml build

README.md

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,33 @@ Using Airflow to implement our ETL pipelines.
2121
- [Python 3.8+](https://www.python.org/downloads/release/python-3811/)
2222
- [Docker](https://docs.docker.com/get-docker/)
2323
- [Git](https://git-scm.com/book/zh-tw/v2/%E9%96%8B%E5%A7%8B-Git-%E5%AE%89%E8%A3%9D%E6%95%99%E5%AD%B8)
24-
- [venv](https://docs.python.org/3/library/venv.html)
24+
- [uv]
2525

2626
## Installation
2727

28-
There are several tools available to create a virtual environment in Python.
28+
We use [uv] to manage dependencies and virtual environment.
2929

30-
Below are the steps to manage a virtual environment using `venv`:
30+
Below are the steps to create a virtual environment using [uv]:
3131

32-
1. Create a Virtual Environment
32+
1. Create a Virtual Environment with Dependencies Installed
3333

3434
To create a virtual environment, run the following command:
3535

3636
```bash
37-
python -m venv venv
37+
uv sync
3838
```
3939

40-
In this example, `venv` is the name of the virtual environment directory, but you can replace it with any name you prefer.
40+
By default, [uv] sets up the virtual environment in `.venv`
4141

4242
2. Activate the Virtual Environment
4343

4444
After creating the virtual environment, activate it using the following command:
4545

4646
```bash
47-
source venv/bin/activate
47+
source .venv/bin/activate
4848
```
4949

50-
3. Install Dependencies
51-
52-
After activating the virtual environment, you can install the required dependencies:
53-
54-
```bash
55-
# Install airflow and dev dependencies
56-
pip install -r requirements.txt -r requirements-dev.txt -c constraints-3.8.txt
57-
58-
# black is conflict with click, so install it separately
59-
pip install black==19.10b0 click==7.1.2
60-
```
61-
62-
4. Deactivate the Virtual Environment
50+
3. Deactivate the Virtual Environment
6351

6452
When you're done working in the virtual environment, you can deactivate it with:
6553
@@ -82,8 +70,9 @@ Below are the steps to manage a virtual environment using `venv`:
8270
### BigQuery (Optional)
8371

8472
Set up the Authentication for GCP: <https://googleapis.dev/python/google-api-core/latest/auth.html>
85-
*After running `gcloud auth application-default login`, you will get a credentials.json file located at `$HOME/.config/gcloud/application_default_credentials.json`. Run `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"` if you have it.
86-
* service-account.json: Please contact @david30907d via email or Discord. You do not need this json file if you are running the sandbox staging instance for development.
73+
74+
- After running `gcloud auth application-default login`, you will get a credentials.json file located at `$HOME/.config/gcloud/application_default_credentials.json`. Run `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/keyfile.json"` if you have it.
75+
- service-account.json: Please contact @david30907d via email or Discord. You do not need this json file if you are running the sandbox staging instance for development.
8776

8877
## Running the Project
8978

@@ -108,7 +97,7 @@ make down-dev
10897

10998
> The difference between production and dev/test compose files is that the dev/test compose file uses a locally built image, while the production compose file uses the image from Docker Hub.
11099

111-
If you are a authorized maintainer, you can pull the image from the GCP Artifact Registry.
100+
If you are an authorized maintainer, you can pull the image from the GCP Artifact Registry.
112101

113102
Docker client must be configured to use the GCP Artifact Registry.
114103

@@ -136,3 +125,5 @@ Please check the [Production Deployment Guide](./docs/DEPLOYMENT.md).
136125
## Contact
137126

138127
[PyCon TW Volunteer Data Team - Discord](https://discord.com/channels/752904426057892052/900721883383758879)
128+
129+
[uv]: https://docs.astral.sh/uv/

0 commit comments

Comments
 (0)