Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to uv and hatch #188

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.29"
enable-cache: true
cache-dependency-glob: "./projects/pgai/uv.lock"

- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip" # caching pip dependencies
python-version-file: "./projects/pgai/.python-version"
Askir marked this conversation as resolved.
Show resolved Hide resolved

- name: Install dev/test dependencies
- name: Install dependencies
working-directory: ./projects/pgai
run: pip install -r requirements-dev.txt
run: uv sync

- name: Lint
working-directory: ./projects/pgai
Expand Down
27 changes: 17 additions & 10 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"

- name: Install pypa/build
run: python -m pip install build --user
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "0.4.29"
enable-cache: true
cache-dependency-glob: "./projects/pgai/uv.lock"

- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/ projects/pgai
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version-file: "./projects/pgai/.python-version"

- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Build the project
working-directory: ./projects/pgai
run: uv build --no-sources

- name: Publish distribution to PyPI
working-directory: ./projects/pgai
run: uv publish

release-docker:
name: Publish to Docker Hub
Expand Down
1 change: 1 addition & 0 deletions projects/pgai/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
Askir marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 19 additions & 6 deletions projects/pgai/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
FROM python:3.12-slim AS build
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_PROJECT_ENVIRONMENT=/usr/local/
WORKDIR /build
COPY --from=ghcr.io/astral-sh/uv:0.4.29 /uv /uvx /bin/

COPY pyproject.toml uv.lock ./

RUN uv sync --frozen --no-install-project --no-dev

FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
PYTHONUNBUFFERED=1
WORKDIR /app

RUN useradd -ms /bin/bash pgaiuser

COPY ./requirements.txt /app/
RUN pip3 install --no-cache-dir --disable-pip-version-check --compile --root-user-action=ignore -r requirements.txt
# Copy installed dependencies from build stage
COPY --from=build /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages

USER pgaiuser
COPY pyproject.toml /app
COPY pyproject.toml /app/
COPY pgai /app/pgai

USER pgaiuser

ENTRYPOINT ["python", "-m", "pgai", "vectorizer", "worker"]
CMD ["-c", "4"]
CMD ["-c", "4"]
23 changes: 13 additions & 10 deletions projects/pgai/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

VERSION := $(shell awk "/^__version__ = .*/ {gsub(/__version__ = |\"/, \"\"); print}" ./pgai/__init__.py)

Askir marked this conversation as resolved.
Show resolved Hide resolved
.PHONY: default
Expand Down Expand Up @@ -40,35 +39,39 @@ clean:
@rm -rf ./build
@rm -rf ./pgai.egg-info
@rm -rf ./dist
@rm -rf ./.ruff_cache
@rm -rf ./.pytest_cache
@rm -rf ./.mypy_cache
@find . -type d -name "__pycache__" -exec rm -rf {} +

.PHONY: build
build:
@python3 -m build --sdist --wheel
@twine check ./dist/*
@uv build
@uv run twine check ./dist/*

.PHONY: install
install:
@pip3 install -v --compile "./dist/pgai-$(VERSION)-py3-none-any.whl"
@uv sync

.PHONY: uninstall
uninstall:
@pip3 uninstall -v -y pgai
@uv pip uninstall -y pgai

.PHONY: test
test:
@pytest
@uv run pytest

.PHONY: lint
lint:
@ruff check ./
@uv run ruff check ./

.PHONY: type-check
type-check:
@pyright ./
@uv run pyright ./

.PHONY: format
format:
@ruff format --diff ./
@uv run ruff format --diff ./

.PHONY: docker-build
docker-build:
Expand All @@ -89,4 +92,4 @@ docker-rm:
.PHONY: install-commit-hook
install-commit-hook:
@cd ../.. && curl --fail -o .git/hooks/commit-msg https://raw.githubusercontent.com/hazcod/semantic-commit-hook/master/commit-msg \
&& chmod 500 .git/hooks/commit-msg
&& chmod 500 .git/hooks/commit-msg
112 changes: 62 additions & 50 deletions projects/pgai/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"
Askir marked this conversation as resolved.
Show resolved Hide resolved

[project]
name = "pgai"
description = "AI workflows in your PostgreSQL database"
dynamic = ["version", "dependencies"]
requires-python = ">=3.10"
readme = "README.md"
keywords = ["ai", "postgres"]
dynamic = ["version"]
dependencies = [
"click>=8.0,<9.0",
"psycopg[binary]>=3.2,<4.0",
"langchain-openai>=0.1,<1.0",
"langchain-text-splitters>=0.2,<1.0",
"pydantic>=2.0,<3.0",
"openai>=1.44,<2.0",
"python-dotenv>=1.0,<2.0",
"structlog>=24.0,<25.0",
"pgvector>=0.3,<1.0",
"tiktoken>=0.7,<1.0",
"typing_extensions>=4.0,<5.0",
"datadog_lambda>=6.9,<7.0",
"pytimeparse>=1.1,<2.0",
]
classifiers = [
"License :: OSI Approved :: PostgreSQL License",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Database",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Operating System :: POSIX",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
"License :: OSI Approved :: PostgreSQL License",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Database",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Operating System :: POSIX",
"Operating System :: MacOS",
"Operating System :: POSIX :: Linux",
]

[project.urls]
Expand All @@ -32,14 +47,8 @@ Repository = "https://github.com/timescale/pgai"
"Bug Tracker" = "https://github.com/timescale/pgai/issues"
Documentation = "https://github.com/timescale/pgai/tree/main/docs"

[tool.setuptools.dynamic]
version = {attr = "pgai.__version__"}
dependencies = {file = "requirements.txt"}

[tool.setuptools.packages.find]
where = ["."] # list of folders that contain the packages (["."] by default)
include = ["pgai*"] # package names should match these glob patterns (["*"] by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default)
[tool.hatch.version]
path = "pgai/__init__.py"

[project.scripts]
pgai = "pgai.cli:cli"
Expand All @@ -48,15 +57,15 @@ pgai = "pgai.cli:cli"
addopts = [
"--import-mode=importlib",
]
python_files = ["test_*.py"]

[tool.pyright]
# this enables practically every flag given by pyright.
# there are a couple of flags that are still disabled by
# default in strict mode as they are experimental and niche.
typeCheckingMode = "strict"

exclude = [
".venv",
".venv",
]
reportImplicitOverride = true

Expand All @@ -70,29 +79,32 @@ target-version = "py310"
docstring-code-format = true
Askir marked this conversation as resolved.
Show resolved Hide resolved

[tool.ruff.lint]

select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
# unused arguments
"ARG",
# trailing whitespace
"W291",
# print statements
"PIE",
# flakes8-quote
"Q"
"E", # pycodestyle
"F", # Pyflakes
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"I", # isort
"ARG", # unused arguments
"W291", # trailing whitespace
"PIE", # print statements
"Q" # flakes8-quote
]

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.hatch.metadata]
allow-direct-references = true

[tool.uv]
dev-dependencies = [
"ruff==0.6.9",
"pytest==8.3.2",
"python-dotenv==1.0.1",
"vcrpy==6.0.1",
"pyright==1.1.385",
"psycopg[binary]==3.2.1",
"testcontainers==4.8.1",
"build==1.2.2.post1",
"twine==5.1.1",
]
2 changes: 0 additions & 2 deletions projects/pgai/pytest.ini

This file was deleted.

6 changes: 0 additions & 6 deletions projects/pgai/requirements-dev.txt

This file was deleted.

12 changes: 0 additions & 12 deletions projects/pgai/requirements-test.txt

This file was deleted.

13 changes: 0 additions & 13 deletions projects/pgai/requirements.txt

This file was deleted.

Loading