Skip to content

Commit dd917d0

Browse files
authored
Use uv instead of flit (#137)
1 parent ea3b5b2 commit dd917d0

12 files changed

+160
-149
lines changed

.github/workflows/publish.yml

+16-27
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,43 @@ jobs:
1212
run:
1313
shell: bash
1414
steps:
15-
- name: Dump GitHub context
16-
env:
17-
GITHUB_CONTEXT: ${{ toJson(github) }}
18-
run: echo "$GITHUB_CONTEXT"
1915
- uses: actions/checkout@v4
2016
- name: Set up Python
2117
uses: actions/setup-python@v5
2218
with:
2319
python-version: "3.9"
24-
- uses: actions/cache@v4
25-
id: cache
26-
with:
27-
path: ${{ env.pythonLocation }}
28-
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-publish
29-
- name: Install Flit
30-
if: steps.cache.outputs.cache-hit != 'true'
31-
run: bash dev/setup.sh
20+
- name: Install uv
21+
run: |
22+
pip install -r requirements.setup.txt
3223
- name: Publish
3324
env:
34-
# SEE https://packaging.python.org/en/latest/specifications/pypirc/?highlight=token#using-a-pypi-token
35-
FLIT_USERNAME: __token__
36-
FLIT_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
37-
run: bash dev/publish.sh "pypi"
38-
- name: Dump GitHub context
39-
env:
40-
GITHUB_CONTEXT: ${{ toJson(github) }}
41-
run: echo "$GITHUB_CONTEXT"
25+
UV_PUBLISH_TOKEN: "${{ secrets.PYPI_API_TOKEN }}"
26+
run: |
27+
bash dev/publish.sh "pypi"
4228
4329
test-published-package:
4430
needs:
4531
- publish
4632
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
4736
defaults:
4837
run:
4938
shell: bash
5039
steps:
51-
- name: Dump GitHub context
52-
env:
53-
GITHUB_CONTEXT: ${{ toJson(github) }}
54-
run: echo "$GITHUB_CONTEXT"
5540
- uses: actions/checkout@v4
5641
- name: Set up Python
5742
uses: actions/setup-python@v5
5843
with:
59-
python-version: "3.9"
60-
- name: Install packages
44+
python-version: "${{ matrix.python-version }}"
45+
# It takes some time when the package gets available.
46+
- name: Sleep
47+
run: |
48+
sleep 30
49+
- name: Install package
6150
run: |
6251
python3 -m pip install -U dbt-artifacts-parser
63-
- name: Test pacakge
52+
- name: Test package
6453
run: |
6554
python -c 'import dbt_artifacts_parser; print(dbt_artifacts_parser.__version__)'

.github/workflows/test-publish.yml

+15-29
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,38 @@ on:
77
description: "dbt-artifacts-parser version"
88
required: true
99

10-
1110
jobs:
1211
publish:
1312
runs-on: ubuntu-latest
1413
defaults:
1514
run:
1615
shell: bash
1716
steps:
18-
- name: Dump GitHub context
19-
env:
20-
GITHUB_CONTEXT: ${{ toJson(github) }}
21-
run: echo "$GITHUB_CONTEXT"
2217
- uses: actions/checkout@v4
2318
- name: Set up Python
2419
uses: actions/setup-python@v5
2520
with:
2621
python-version: "3.9"
27-
- uses: actions/cache@v4
28-
id: cache
29-
with:
30-
path: ${{ env.pythonLocation }}
31-
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-publish
32-
- name: Install Flit
33-
if: steps.cache.outputs.cache-hit != 'true'
34-
run: bash dev/setup.sh
22+
- name: Install uv
23+
run: |
24+
pip install -r requirements.setup.txt
3525
- name: Test publish
3626
env:
37-
# SEE https://packaging.python.org/en/latest/specifications/pypirc/?highlight=token#using-a-pypi-token
38-
FLIT_USERNAME: __token__
39-
FLIT_PASSWORD: ${{ secrets.TESTPYPI_API_TOKEN }}
40-
run: bash dev/publish.sh "testpypi"
41-
- name: Dump GitHub context
42-
env:
43-
GITHUB_CONTEXT: ${{ toJson(github) }}
44-
run: echo "$GITHUB_CONTEXT"
27+
UV_PUBLISH_TOKEN: "${{ secrets.TESTPYPI_API_TOKEN }}"
28+
run: |
29+
bash dev/publish.sh testpypi
4530
4631
test-published-package:
4732
needs:
4833
- publish
4934
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
5038
defaults:
5139
run:
5240
shell: bash
53-
strategy:
54-
matrix:
55-
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
5641
steps:
57-
- name: Dump GitHub context
58-
env:
59-
GITHUB_CONTEXT: ${{ toJson(github) }}
60-
run: echo "$GITHUB_CONTEXT"
6142
- uses: actions/checkout@v4
6243
- name: Set up Python
6344
uses: actions/setup-python@v5
@@ -68,9 +49,14 @@ jobs:
6849
python3 -m pip install -U pip==23.1.0
6950
python3 -m pip install \
7051
--index-url https://test.pypi.org/simple/ \
52+
--extra-index-url https://pypi.org/simple/ \
7153
--force-reinstall \
7254
--use-feature=fast-deps \
7355
-U dbt-artifacts-parser=="${{ github.event.inputs.dbt_artifacts_parser_version }}"
74-
- name: Test pacakge
56+
# It takes some time when the package gets available.
57+
- name: Sleep
58+
run: |
59+
sleep 30
60+
- name: Test package
7561
run: |
7662
python -c 'import dbt_artifacts_parser; print(dbt_artifacts_parser.__version__)'

.github/workflows/test.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,15 @@ jobs:
3030
uses: actions/setup-python@v5
3131
with:
3232
python-version: ${{ matrix.python-version }}
33-
- uses: actions/cache@v4
34-
id: cache
35-
with:
36-
path: ${{ env.pythonLocation }}
37-
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test
38-
- name: Install Flit
39-
if: steps.cache.outputs.cache-hit != 'true'
40-
run: bash dev/setup.sh
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install -r requirements.setup.txt
36+
bash dev/setup.sh --deps "development"
4137
- name: Run tests
4238
run: bash dev/test_python.sh
39+
- name: Test build
40+
run: |
41+
bash dev/build.sh
4342
- name: Test installation
4443
run: |
4544
pip install -e .

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ setup: setup-python setup-pre-commit
55
# Set up the python environment.
66
.PHONY: setup-python
77
setup-python:
8-
bash ./dev/setup.sh --deps "develop"
8+
bash ./dev/setup.sh --deps "development"
99

1010
# Set up the pre-commit hooks.
1111
.PHONY: setup-pre-commit
@@ -53,7 +53,7 @@ test:
5353
# Build the package
5454
.PHONY: build
5555
build: clean lint test
56-
flit build
56+
bash -x ./dev/build.sh
5757

5858
# Clean the environment
5959
.PHONY: clean

dbt_artifacts_parser/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
"""
1818
A dbt artifacts parser in python
1919
"""
20-
__version__ = "0.8.0"
20+
21+
__version__ = "0.8.1"

dev/build.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# Copyright 2024 yu-iskw
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -Eo pipefail
18+
19+
python -m build

dev/publish.sh

+14-10
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,29 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
set -e
16+
set -Eo pipefail
1717
set -x
1818

19-
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
19+
SCRIPT_FILE="$(readlink -f "$0")"
20+
SCRIPT_DIR="$(dirname "$SCRIPT_FILE")"
2021
MODULE_DIR="$(dirname "$SCRIPT_DIR")"
2122

22-
cd "$MODULE_DIR"
23+
cd "$MODULE_DIR" || exit
2324

2425
# Arguments
2526
target=${1:?"target is not set"}
2627

27-
# SEE https://flit.readthedocs.io/en/latest/reproducible.html
28-
SOURCE_DATE_EPOCH=$(date +%s)
29-
export SOURCE_DATE_EPOCH
28+
# Ensure uv is installed
29+
pip install uv
3030

31-
if [[ "$target" == "pypi" ]] ; then
32-
flit publish --repository "${target}" --pypirc "${MODULE_DIR}/.pypirc" --setup-py
33-
elif [[ "$target" == "testpypi" ]] ; then
34-
flit publish --repository "${target}" --pypirc "${MODULE_DIR}/.pypirc" --setup-py
31+
# Build the package first
32+
uv build
33+
34+
# Publish to the specified target
35+
if [[ "$target" == "pypi" ]]; then
36+
uv publish
37+
elif [[ "$target" == "testpypi" ]]; then
38+
uv publish --publish-url "https://test.pypi.org/legacy/"
3539
else
3640
echo "No such target ${target}"
3741
exit 1

dev/setup.sh

+49-6
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,57 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
set -e
16+
set -Eeuo pipefail
1717

1818
# Constants
1919
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
20-
MODULE_DIR="$(dirname "$SCRIPT_DIR")"
20+
MODULE_DIR="$(dirname "${SCRIPT_DIR}")"
2121

22-
cd "$MODULE_DIR"
22+
# Arguments
23+
deps="production"
24+
use_venv=false
25+
while (($# > 0)); do
26+
if [[ "$1" == "--use-venv" ]]; then
27+
use_venv=true
28+
shift 1
29+
elif [[ "$1" == "--deps" ]]; then
30+
if [[ "$2" != "production" && "$2" != "development" ]]; then
31+
echo "Error: deps must be one of 'production' or 'development'"
32+
exit 1
33+
fi
34+
deps="$2"
35+
shift 2
36+
else
37+
echo "Unknown argument: $1"
38+
exit 1
39+
fi
40+
done
2341

24-
FLIT_VERSION="3.9.0"
25-
pip install -U flit=="$FLIT_VERSION"
26-
flit install --deps develop --symlink
42+
# Change to the module directory
43+
cd "${MODULE_DIR}"
44+
45+
# Install uv and dependencies
46+
pip install --force-reinstall -r "${MODULE_DIR}/requirements.setup.txt"
47+
48+
UV_PIP_OPTIONS=("--force-reinstall")
49+
if [[ "${use_venv}" == true ]]; then
50+
# Create virtual environment
51+
uv venv
52+
# Activate virtual environment
53+
if [[ -f .venv/bin/activate ]]; then
54+
# shellcheck disable=SC1091
55+
source .venv/bin/activate
56+
else
57+
echo "Error: .venv/bin/activate not found"
58+
exit 1
59+
fi
60+
else
61+
UV_PIP_OPTIONS+=("--system")
62+
fi
63+
64+
# Install package and dependencies
65+
if [[ "${deps}" == "production" ]]; then
66+
uv pip install "${UV_PIP_OPTIONS[@]}" -e "."
67+
else
68+
uv pip install "${UV_PIP_OPTIONS[@]}" -e ".[dev,test]"
69+
fi

0 commit comments

Comments
 (0)