Skip to content
Open
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
51 changes: 21 additions & 30 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,31 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

---
name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
branches:
- master

permissions:
contents: write

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

python-version:
- "3.11"
- "3.12"
- "3.13"
- "3.14"
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v6
- name: Install uv and set Python version
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --dev
- name: Lint with Ruff
run: |
uv run ruff check . --fix
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# syntax=docker/dockerfile:1
FROM python:3.11-slim

# Install uv from official image
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# System dependencies + SQL Server ODBC driver
RUN apt-get update && \
apt-get install -y --no-install-recommends curl gnupg2 ca-certificates unixodbc-dev build-essential && \
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg && \
echo "deb [signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" > /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install -y --no-install-recommends msodbcsql18 && \
DRIVER_PATH="$(ls /opt/microsoft/msodbcsql18/lib64/libmsodbcsql-18*.so* | head -n 1)" && \
printf "[SQL Server]\nDescription=Microsoft ODBC Driver 18 for SQL Server (alias)\nDriver=%s\nUsageCount=1\n" "$DRIVER_PATH" >> /etc/odbcinst.ini && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

ENV UV_PYTHON=python3.11
ENV UV_SYSTEM_PYTHON=1

# Install dependencies first for better layer caching
COPY pyproject.toml ./
COPY uv.lock ./
RUN uv sync --frozen

# Copy project files
COPY . .

# Runtime default environment for main.py arg
ENV APP_ENV=hpc_dev

CMD ["sh", "-c", "uv run python main.py --db"]
101 changes: 101 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#* Variables
SHELL := /usr/bin/env bash
PYTHON := python
PYTHONPATH := `pwd`/src

#* INSTALL

#* Install dependencies and package
.PHONY: install
install:
uv sync --all-extras --dev --frozen

#* LINTING

#* Check formatting
.PHONY: check-codestyle
check-codestyle:
uv run isort --diff --check-only --settings-path pyproject.toml ./
uv run black --diff --check --config pyproject.toml ./
uv run ruff check .

#* Fix formatting
.PHONY: codestyle
codestyle:
uv run isort --settings-path pyproject.toml ./
uv run black --fast --config pyproject.toml ./
uv run ruff check . --fix

# .PHONY: test
# test:
# uv run pytest tests/unit --cov=data_bridges_knots --cov-report=html
# uv run coverage-badge -o assets/images/coverage.svg -f

#* Typing
.PHONY: mypy
mypy:
uv run mypy --config-file pyproject.toml ./

# .PHONY: check-safety
# check-safety:
# uv run bandit -r src

#* All in one
.PHONY: lint
lint: test check-codestyle mypy

#* DOCS

# #* Documentation
# # Test
# .PHONY: docs-test
# docs-test:
# uv run python -m doctest data_bridges_knots/client.py

#* DOCKER

# Example: make docker-build VERSION=latest
# Example: make docker-build IMAGE=some_name VERSION=0.1.0
.PHONY: docker-build
docker-build:
@echo Building docker $(IMAGE):$(VERSION) ...
docker build \
-t $(IMAGE):$(VERSION) . \
-f ./docker/Dockerfile --no-cache

# Example: make docker-remove VERSION=latest
# Example: make docker-remove IMAGE=some_name VERSION=0.1.0
.PHONY: docker-remove
docker-remove:
@echo Removing docker $(IMAGE):$(VERSION) ...
docker rmi -f $(IMAGE):$(VERSION)


#* CLEANING

.PHONY: pycache-remove
pycache-remove:
find . | grep -E "(__pycache__|\.pyc|\.pyo$$)" | xargs rm -rf

.PHONY: dsstore-remove
dsstore-remove:
find . | grep -E ".DS_Store" | xargs rm -rf

.PHONY: mypycache-remove
mypycache-remove:
find . | grep -E ".mypy_cache" | xargs rm -rf

.PHONY: ipynbcheckpoints-remove
ipynbcheckpoints-remove:
find . | grep -E ".ipynb_checkpoints" | xargs rm -rf

.PHONY: pytestcache-remove
pytestcache-remove:
find . | grep -E ".pytest_cache" | xargs rm -rf

.PHONY: build-remove
build-remove:
rm -rf build/

.PHONY: cleanup
cleanup: pycache-remove dsstore-remove mypycache-remove ipynbcheckpoints-remove pytestcache-remove
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is a Python CLI tool to query the [WFP Data Library API](https://datalib.va
- Packages listed in `requirements.txt`

## Documentation
For more details on the Data Library API endpoints, see the [API documentation](http://docs.ckan.org/en/2.9/api/).
For more details on the Data Library API endpoints, see the [API documentation](http://docs.ckan.org/en/2.11/api/).

## Contributing
Contributions to add more API querying/exporting functionality are welcome!
Expand Down
10 changes: 8 additions & 2 deletions datalibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from .extract import DataLibrary, get_survey_data, get_user_data, get_member_data, get_data
from .extract import (
DataLibrary,
get_data,
get_member_data,
get_survey_data,
get_user_data,
)

__all__ = ["DataLibrary"]
__all__ = ["DataLibrary"]
Loading
Loading