Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Workflow derived from https://github.com/rstudio/shiny-workflows
#
# NOTE: This Shiny team GHA workflow is overkill for most R packages.
# For most R packages it is better to use https://github.com/r-lib/actions
on:
push:
branches: [main, rc-**]
pull_request:
schedule:
- cron: "0 8 * * 1" # every monday

name: Package checks

jobs:
website:
uses: rstudio/shiny-workflows/.github/workflows/website.yaml@v1
with:
working-directory: ./r-package
routine:
uses: rstudio/shiny-workflows/.github/workflows/routine.yaml@v1
with:
format-r-code: true
working-directory: ./r-package
R-CMD-check:
uses: rstudio/shiny-workflows/.github/workflows/R-CMD-check.yaml@v1
with:
working-directory: ./r-package
58 changes: 58 additions & 0 deletions .github/workflows/py-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Python - Release

on:
release:
types: [published]

env:
PYTHON_VERSION: 3.12

jobs:
pypi-release:
name: Build and release Python package
runs-on: ubuntu-latest

if: startsWith(github.ref, 'refs/tags/py-v')

environment:
name: pypi
url: https://pypi.org/project/querychat/

permissions: # for trusted publishing
id-token: write

steps:
- uses: actions/checkout@v4

- name: 🚀 Install uv
uses: astral-sh/setup-uv@v3

- name: 🐍 Set up Python ${{ env.PYTHON_VERSION }}
working-directory: ./python-package
run: uv python install ${{ env.PYTHON_VERSION }}

- name: 📦 Install the project
working-directory: ./python-package
run: uv sync --python ${{ env.PYTHON_VERSION }} --all-extras

# - name: 🧪 Check tests
# working-directory: ./python-package
# run: make check-tests

- name: 📝 Check types
working-directory: ./python-package
run: make check-types

- name: 📐 Check formatting
working-directory: ./python-package
run: make check-format

- name: 🧳 Build package
working-directory: ./python-package
run: make build

# TODO: https://pypi.org/manage/project/querychat/settings/publishing/
- name: 🚢 Publish release on PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: ./python-package/dist
53 changes: 53 additions & 0 deletions .github/workflows/py-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test - Python

on:
workflow_dispatch:
push:
branches: ["main", "rc-*"]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
release:
types: [published]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
config:
- { python-version: "3.9", test_google: false, test_azure: false }
- { python-version: "3.10", test_google: false, test_azure: false }
- { python-version: "3.11", test_google: false, test_azure: false }
- { python-version: "3.12", test_google: true, test_azure: true }
- { python-version: "3.13", test_google: false, test_azure: false }
fail-fast: false

steps:
- uses: actions/checkout@v4

- name: 🚀 Install uv
uses: astral-sh/setup-uv@v3

- name: 🐍 Set up Python ${{ matrix.config.python-version }}
working-directory: ./python-package
run: uv python install ${{matrix.config.python-version }}

- name: 📦 Install the project
working-directory: ./python-package
run: uv sync --python ${{ matrix.config.python-version }} --all-extras

# - name: 🧪 Check tests
# working-directory: ./python-package
# run: make check-tests

- name: 📝 Check types
# if: ${{ matrix.config.python-version != '3.9' }}
working-directory: ./python-package
run: make check-types

- name: 📐 Check formatting
working-directory: ./python-package
run: make check-format
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"python.autoComplete.extraPaths": ["${workspaceFolder}/python-package"]
"python.autoComplete.extraPaths": ["${workspaceFolder}/python-package"],
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
},
"flake8.args": ["--max-line-length=120"]
}
1 change: 1 addition & 0 deletions python-package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uv.lock
62 changes: 49 additions & 13 deletions python-package/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
.PHONY: build publish create activate publish publish-test install-test
# Inspired by https://github.com/posit-dev/chatlas/blob/main/Makefile

build:
hatch build
.PHONY: setup
setup: ## [py] Setup python environment
uv sync --all-extras

.PHONY: build
build: ## [py] Build python package
@echo "🧳 Building python package"
@[ -d dist ] && rm -r dist || true
uv build

.PHONY: publish
publish:
hatch publish

create:
hatch env create
.PHONY: check
check: check-format check-types ## [py] Run python checks

activate:
hatch shell
.PHONY: check-types
check-types: ## [py] Run python type checks
@echo ""
@echo "📝 Checking types with pyright"
uv run --with pyright pyright

publish:
hatch publish
.PHONY: check-format
check-format:
@echo ""
@echo "📐 Checking format with ruff"
uv run --with ruff ruff check src/querychat --config pyproject.toml

.PHONY: format
format: ## [py] Format python code
uv run --with ruff ruff check --fix src/querychat --config pyproject.toml
uv run --with ruff ruff format src/querychat --config pyproject.toml

.PHONY: check-tox
check-tox: ## [py] Run python 3.9 - 3.12 checks with tox
@echo ""
@echo "🔄 Running tests and type checking with tox for Python 3.9--3.12"
uv run tox run-parallel

publish-test:
hatch publish -r test
.PHONY: help
help: ## Show help messages for make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; { \
printf "\033[32m%-18s\033[0m", $$1; \
if ($$2 ~ /^\[docs\]/) { \
printf "\033[34m[docs]\033[0m%s\n", substr($$2, 7); \
} else if ($$2 ~ /^\[py\]/) { \
printf " \033[33m[py]\033[0m%s\n", substr($$2, 5); \
} else if ($$2 ~ /^\[r\]/) { \
printf " \033[31m[r]\033[0m%s\n", substr($$2, 4); \
} else { \
printf " %s\n", $$2; \
} \
}'

install-test:
python3 -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ querychat
.DEFAULT_GOAL := help
152 changes: 143 additions & 9 deletions python-package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ name = "querychat"
version = "0.1.0"
description = "Chat with your data using natural language"
readme = "README.md"
requires-python = ">=3.8"
license = {file = "LICENSE"}
authors = [
{name = "Posit", email = "[email protected]"},
]
requires-python = ">=3.9"
license = { file = "LICENSE" }
authors = [{ name = "Posit", email = "[email protected]" }]
dependencies = [
"duckdb",
"pandas",
Expand Down Expand Up @@ -41,8 +39,144 @@ Source = "https://github.com/posit-dev/querychat/tree/main/python-package"
packages = ["querychat"]

[tool.hatch.build.targets.sdist]
include = [
"querychat",
"LICENSE",
"README.md",
include = ["src/querychat", "LICENSE", "README.md"]

[tool.uv]
dev-dependencies = ["ruff>=0.6.5", "pyright>=1.1.401", "tox-uv>=1.11.4"]

[tool.ruff]
src = ["src/querychat"]
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
"app.py", # ignore examples for now
]

line-length = 88
indent-width = 4

target-version = "py39"

# [tool.ruff.lint]
# select = ['E', 'F', 'W', 'A', 'PLC', 'PLE', 'PLW', 'I']
[tool.ruff.lint]
extend-ignore = [
"A002", # Shadowing a built-in
"ARG001", # Unused argument
"D200", # One-line docstring should fit on one line with quotes
"D203", # 1 blank line required before class docstring
"D212", # Multi-line docstring summary should start at the first line
"E501", # Line too long
"ISC001", # single-line-implicit-string-concatenation
"ISC002", # multi-line-implicit-string-concatenation
"PD901", # Avoid using the generic variable name `df` for DataFrames
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements in function
"RET504", # Unnecessary assignment to `{name}` before `return` statement
"RET505", # Unnecessary branch after `return` statement
"UP007", # Use `X | Y` for type annotations (or Optional[X])
# TODO: Remove in the future, when we have docstrings.
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D104", # Missing docstring in public package
"D107", # Missing docstring in __init__
"D205", # 1 blank line required between summary line and description
]
extend-select = [
# "C90", # C90; mccabe: https://docs.astral.sh/ruff/rules/complex-structure/
"ASYNC", # ASYNC; flake8-async: https://docs.astral.sh/ruff/rules/#flake8-async-async
"S", # S; flake8-bandit: https://docs.astral.sh/ruff/rules/#flake8-bandit-s
"FBT", # FBT; flake8-boolean-trap: https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
"B", # B; flake8-bugbear: https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
"A", # A; flake8-builtins: https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"COM", # COM; Commas: https://docs.astral.sh/ruff/rules/#flake8-commas-com
"C4", # C4; flake8-comprehensions: https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"DTZ", # DTZ; flake8-datetimez: https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
"T10", # T10; flake8-dbugger: https://docs.astral.sh/ruff/rules/#flake8-debugger-t10
"FA", # FA; flake8-future-annotations: https://docs.astral.sh/ruff/rules/#flake8-future-annotations-fa
"ISC", # ISC; flake8-implicit-str-concat: https://docs.astral.sh/ruff/rules/#flake8-implicit-str-concat-isc
"ICN", # ICN; flake8-import-conventions: https://docs.astral.sh/ruff/rules/#flake8-import-conventions-icn
"PIE", # PIE; flake8-pie: https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"PYI", # PYI; flake8-pyi : https://docs.astral.sh/ruff/rules/#flake8-pyi-pyi
"PT", # PT; flake8-pytest-style: https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"Q", # Q; flake8-quotes: https://docs.astral.sh/ruff/rules/#flake8-quotes-q
"RET", # RET; flake8-return: https://docs.astral.sh/ruff/rules/#flake8-return-ret
"SIM", # SIM; flake8-simplify: https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"TID253", # banned-module-level-imports: https://docs.astral.sh/ruff/rules/banned-module-level-imports/#banned-module-level-imports-tid253
"TC", # TC; flake8-type-checking: https://docs.astral.sh/ruff/rules/#flake8-type-checking-tch
"TD", # TD; flake8-todos: https://docs.astral.sh/ruff/rules/#flake8-todosimports-td
"ARG", # ARG; flake8-argparse: https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
"PTH", # PTH; flake8-use-pathlib: https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"I", # I; isort: https://docs.astral.sh/ruff/rules/#isort-i
"NPY", # NPY; NumPy-specific rules: https://docs.astral.sh/ruff/rules/#numpy-specific-rules-npy
"PD", # PD; pandas-vet: https://docs.astral.sh/ruff/rules/#pandas-vet-pd
"N", # N; pep8-naming: https://docs.astral.sh/ruff/rules/#pep8-naming-n
"PERF", # PERF; flake8-performance: https://docs.astral.sh/ruff/rules/#flake8-performance-perf
"E", # E; pycodestyle: https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"W", # W; pycodestyle: https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"D", # D; pydocstyle: https://docs.astral.sh/ruff/rules/#pydocstyle-d
"F", # F; Pyflakes: https://docs.astral.sh/ruff/rules/#pyflakes-f
"PGH", # PGH; pygrep-hooks: https://docs.astral.sh/ruff/rules/#pygrep-hooks-pgh
"PL", # PL; pylint: https://docs.astral.sh/ruff/rules/#pylint-pl
"UP", # UP; pyupgrade: https://docs.astral.sh/ruff/rules/#pyupgrade-up
"FURB", # FURB; refurb: https://docs.astral.sh/ruff/rules/#refurb-furb
"RUF", # RUF; Ruff specific rules: https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

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

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true
docstring-code-line-length = "dynamic"

[tool.pyright]
include = ["src/querychat"]


# For more tox testing usage (in addition to typing), see:
# https://github.com/posit-dev/chatlas/blob/b91c020a555917c1be5ae2462496de25d82c529d/pyproject.toml#L122-L139
[tool.tox]
legacy_tox_ini = """
[tox]
env_list = py3{9,10,11,12}
isolated_build = True

[testenv]
package = wheel
wheel_build_env = .pkg
commands = pyright
"""
4 changes: 2 additions & 2 deletions python-package/src/querychat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from querychat.querychat import init, ui, sidebar, server
from querychat.querychat import init, server, sidebar, ui

__all__ = ["init", "ui", "sidebar", "server"]
__all__ = ["init", "server", "sidebar", "ui"]
Loading