Skip to content

Commit

Permalink
Use uv instead of flit (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
yu-iskw authored Dec 25, 2024
1 parent ea3b5b2 commit dd917d0
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 149 deletions.
43 changes: 16 additions & 27 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,43 @@ jobs:
run:
shell: bash
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-publish
- name: Install Flit
if: steps.cache.outputs.cache-hit != 'true'
run: bash dev/setup.sh
- name: Install uv
run: |
pip install -r requirements.setup.txt
- name: Publish
env:
# SEE https://packaging.python.org/en/latest/specifications/pypirc/?highlight=token#using-a-pypi-token
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: bash dev/publish.sh "pypi"
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
UV_PUBLISH_TOKEN: "${{ secrets.PYPI_API_TOKEN }}"
run: |
bash dev/publish.sh "pypi"
test-published-package:
needs:
- publish
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
defaults:
run:
shell: bash
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install packages
python-version: "${{ matrix.python-version }}"
# It takes some time when the package gets available.
- name: Sleep
run: |
sleep 30
- name: Install package
run: |
python3 -m pip install -U dbt-artifacts-parser
- name: Test pacakge
- name: Test package
run: |
python -c 'import dbt_artifacts_parser; print(dbt_artifacts_parser.__version__)'
44 changes: 15 additions & 29 deletions .github/workflows/test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,38 @@ on:
description: "dbt-artifacts-parser version"
required: true


jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-publish
- name: Install Flit
if: steps.cache.outputs.cache-hit != 'true'
run: bash dev/setup.sh
- name: Install uv
run: |
pip install -r requirements.setup.txt
- name: Test publish
env:
# SEE https://packaging.python.org/en/latest/specifications/pypirc/?highlight=token#using-a-pypi-token
FLIT_USERNAME: __token__
FLIT_PASSWORD: ${{ secrets.TESTPYPI_API_TOKEN }}
run: bash dev/publish.sh "testpypi"
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
UV_PUBLISH_TOKEN: "${{ secrets.TESTPYPI_API_TOKEN }}"
run: |
bash dev/publish.sh testpypi
test-published-package:
needs:
- publish
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
defaults:
run:
shell: bash
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
Expand All @@ -68,9 +49,14 @@ jobs:
python3 -m pip install -U pip==23.1.0
python3 -m pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
--force-reinstall \
--use-feature=fast-deps \
-U dbt-artifacts-parser=="${{ github.event.inputs.dbt_artifacts_parser_version }}"
- name: Test pacakge
# It takes some time when the package gets available.
- name: Sleep
run: |
sleep 30
- name: Test package
run: |
python -c 'import dbt_artifacts_parser; print(dbt_artifacts_parser.__version__)'
15 changes: 7 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v4
id: cache
with:
path: ${{ env.pythonLocation }}
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test
- name: Install Flit
if: steps.cache.outputs.cache-hit != 'true'
run: bash dev/setup.sh
- name: Install dependencies
run: |
python -m pip install -r requirements.setup.txt
bash dev/setup.sh --deps "development"
- name: Run tests
run: bash dev/test_python.sh
- name: Test build
run: |
bash dev/build.sh
- name: Test installation
run: |
pip install -e .
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ setup: setup-python setup-pre-commit
# Set up the python environment.
.PHONY: setup-python
setup-python:
bash ./dev/setup.sh --deps "develop"
bash ./dev/setup.sh --deps "development"

# Set up the pre-commit hooks.
.PHONY: setup-pre-commit
Expand Down Expand Up @@ -53,7 +53,7 @@ test:
# Build the package
.PHONY: build
build: clean lint test
flit build
bash -x ./dev/build.sh

# Clean the environment
.PHONY: clean
Expand Down
3 changes: 2 additions & 1 deletion dbt_artifacts_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
"""
A dbt artifacts parser in python
"""
__version__ = "0.8.0"

__version__ = "0.8.1"
19 changes: 19 additions & 0 deletions dev/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Copyright 2024 yu-iskw
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -Eo pipefail

python -m build
24 changes: 14 additions & 10 deletions dev/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -Eo pipefail
set -x

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
SCRIPT_FILE="$(readlink -f "$0")"
SCRIPT_DIR="$(dirname "$SCRIPT_FILE")"
MODULE_DIR="$(dirname "$SCRIPT_DIR")"

cd "$MODULE_DIR"
cd "$MODULE_DIR" || exit

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

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

if [[ "$target" == "pypi" ]] ; then
flit publish --repository "${target}" --pypirc "${MODULE_DIR}/.pypirc" --setup-py
elif [[ "$target" == "testpypi" ]] ; then
flit publish --repository "${target}" --pypirc "${MODULE_DIR}/.pypirc" --setup-py
# Build the package first
uv build

# Publish to the specified target
if [[ "$target" == "pypi" ]]; then
uv publish
elif [[ "$target" == "testpypi" ]]; then
uv publish --publish-url "https://test.pypi.org/legacy/"
else
echo "No such target ${target}"
exit 1
Expand Down
55 changes: 49 additions & 6 deletions dev/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,57 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
set -Eeuo pipefail

# Constants
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
MODULE_DIR="$(dirname "$SCRIPT_DIR")"
MODULE_DIR="$(dirname "${SCRIPT_DIR}")"

cd "$MODULE_DIR"
# Arguments
deps="production"
use_venv=false
while (($# > 0)); do
if [[ "$1" == "--use-venv" ]]; then
use_venv=true
shift 1
elif [[ "$1" == "--deps" ]]; then
if [[ "$2" != "production" && "$2" != "development" ]]; then
echo "Error: deps must be one of 'production' or 'development'"
exit 1
fi
deps="$2"
shift 2
else
echo "Unknown argument: $1"
exit 1
fi
done

FLIT_VERSION="3.9.0"
pip install -U flit=="$FLIT_VERSION"
flit install --deps develop --symlink
# Change to the module directory
cd "${MODULE_DIR}"

# Install uv and dependencies
pip install --force-reinstall -r "${MODULE_DIR}/requirements.setup.txt"

UV_PIP_OPTIONS=("--force-reinstall")
if [[ "${use_venv}" == true ]]; then
# Create virtual environment
uv venv
# Activate virtual environment
if [[ -f .venv/bin/activate ]]; then
# shellcheck disable=SC1091
source .venv/bin/activate
else
echo "Error: .venv/bin/activate not found"
exit 1
fi
else
UV_PIP_OPTIONS+=("--system")
fi

# Install package and dependencies
if [[ "${deps}" == "production" ]]; then
uv pip install "${UV_PIP_OPTIONS[@]}" -e "."
else
uv pip install "${UV_PIP_OPTIONS[@]}" -e ".[dev,test]"
fi
Loading

0 comments on commit dd917d0

Please sign in to comment.