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

Release #8

Merged
merged 7 commits into from
Aug 24, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x

Expand All @@ -23,8 +23,8 @@ jobs:

- name: "Install dependencies"
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.6.1
poetry install
make init-uv
make install

- name: "Build mkdocs"
run: make doc-deploy
58 changes: 38 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,74 +14,92 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.6.1
poetry install
make init-uv
make install

- name: Format checking with Ruff Format
run: poetry run ruff format --check .
run: make format

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.6.1
poetry install
make init-uv
make install

- name: Lint with Ruff
run: poetry run ruff --output-format=github .
run: make lint-python

- name: Lint with Sqlfluff
run: poetry run sqlfluff lint .
run: make lint-sql

type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.6.1
poetry install
make init-uv
make install

- name: Type checking with Mypy
run: poetry run mypy .
run: make type

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 - --version 1.6.1
poetry install
make init-uv
make install

- name: Test with pytest
run: poetry run coverage run -m pytest -vv tests && poetry run coverage report
run: make test

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies
run: |
make init-uv
make install

- name: Verify build
run: make build

# nox:
# runs-on: ubuntu-latest
Expand All @@ -99,8 +117,8 @@ jobs:

# - name: Install dependencies
# run: |
# curl -sSL https://install.python-poetry.org | python3 - --version 1.6.1
# poetry install
# make init-uv
# make install

# - name: Test with nox
# run: poetry run nox --reuse-existing-virtualenvs --no-install
# run: make test-all
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default_install_hook_types: [pre-commit, commit-msg]
repos:
# misc pre-commit helpers
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
args:
Expand All @@ -20,39 +20,37 @@ repos:

# ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.6.2
hooks:
- id: ruff-format
- id: ruff

# mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.11.1
hooks:
- id: mypy
additional_dependencies: ['pydantic', 'types-requests']

# poetry
- repo: https://github.com/python-poetry/poetry
rev: 1.6.0
hooks:
- id: poetry-check # make sure the poetry configuration does not get committed in a broken state
- id: poetry-lock # make sure the lock file is up-to-date when committing changes
args:
- --check
# - id: poetry-export # sync your requirements.txt file with your current dependencies

# sqlfluff
- repo: https://github.com/sqlfluff/sqlfluff
rev: 2.3.3
rev: 3.1.1
hooks:
- id: sqlfluff-fix
- id: sqlfluff-lint

# uv
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.3.2
hooks:
- id: uv-lock
args:
- --locked # Requires that the lockfile is up-to-date. If the lockfile is missing or needs to be updated, uv will exit with an error.

# commitlint
# (configuration in commitlint.config.js)
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.11.0
rev: v9.16.0
hooks:
- id: commitlint
additional_dependencies: ['@commitlint/config-conventional']
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.4
1 change: 1 addition & 0 deletions .uv-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.2
45 changes: 40 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
TEST_DIR="tests"

# Build
build:
uvx --from build pyproject-build --installer uv

# Docs
doc-build:
poetry run mkdocs build
uv run mkdocs build

doc-serve: doc-build
poetry run mkdocs serve
uv run mkdocs serve

doc-deploy:
poetry run mkdocs gh-deploy --force
uv run mkdocs gh-deploy --force

# Setup
init: init-uv init-python

init-uv:
curl -LsSf https://astral.sh/uv/$(shell cat .uv-version)/install.sh | sh

init-python:
uv python install $(cat .python-version)

install:
uv sync

lock:
uv lock

# Validations
format:
uv run ruff format --check .

lint: lint-python lint-sql

lint-python:
uv run ruff check --output-format=github .

lint-sql:
uv run sqlfluff lint .

type:
uv run mypy .

test:
poetry run coverage run -m pytest -vv $(TEST_DIR) && poetry run coverage report -m
uv run coverage run -m pytest -vv $(TEST_DIR) && uv run coverage report -m

test-all:
poetry run nox --reuse-existing-virtualenvs --no-install
uv run nox --reuse-venv=yes --no-install
55 changes: 27 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,35 @@ Sample structure and setup for a Python project which includes:

## Installation
```shell
# install poetry
curl -sSL https://install.python-poetry.org | python3 -
# update poetry
poetry self update
# install requirements
make init
make install

# ensure venv is created within project
poetry config virtualenvs.in-project true

# install project dependencies into venv
poetry install
# install pre-commit configuration
poetry run pre-commit install
```


## Usage

### Run Pre-Commmit Hooks
### Run Pre-Commit Hooks
```shell
# To run the pre-commit hooks against staged files before committing:
poetry run pre-commit run
uv run pre-commit run

# To run a particular pre-commit hook against staged files before committing:
# poetry run pre-commit run <hook>
poetry run pre-commit run ruff-format
poetry run pre-commit run ruff
poetry run pre-commit run mypy
# uv run pre-commit run <hook>
uv run pre-commit run ruff-format
uv run pre-commit run ruff
uv run pre-commit run mypy

# To run a particular pre-commit hook against all files (staged and unstaged, before committing):
poetry run pre-commit run ruff --all-files
uv run pre-commit run ruff --all-files

# run checks regardless of git status
poetry run ruff format --check src
poetry run mypy src
poetry run ruff src
uv run ruff format --check src
uv run mypy src
uv run ruff src
```

### Run Unittests
Expand All @@ -54,7 +48,7 @@ poetry run ruff src
make test

# Run specific tests
poetry run pytest -vv tests/test_placeholder.py::test_Sample_init
uv run pytest -vv tests/test_placeholder.py::test_Sample_init
```

### Run All Checks
Expand All @@ -63,7 +57,7 @@ poetry run pytest -vv tests/test_placeholder.py::test_Sample_init
make test-all

# run all nox lints
poetry run nox -R -s lint
uv run nox -R -s lint
```

### Build Docs
Expand All @@ -76,17 +70,22 @@ make doc-serve


## Distribution
> As of 2024-08-22, uv does not yet have dedicated commands for building and publishing a package.
> Their [documentation recommends](https://docs.astral.sh/uv/guides/publish/) using the PyPA tools `build` and `twine`.
```shell
# Build sdist and wheel
poetry build
uvx --from build pyproject-build --installer uv

# Only build wheel
poetry build --format wheel
uvx --from build pyproject-build --installer uv --wheel

# Publish to TEST PyPI
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="<my-pypi-token>"
uvx twine upload --repository testpypi dist/*

# Publish to PYPI
# https://python-poetry.org/docs/repositories/#configuring-credentials
poetry config pypi-token.pypi <my-token>
poetry publish
# Publish to PyPI
uvx twine upload dist/*
```


Expand All @@ -98,8 +97,8 @@ The checks contained in this repo include (in the order in which they run):
* `ruff format` applies standard code style formatting (just like `black`, but faster)
* `ruff` checks code for "lint"
* `mypy` is used for static type checking
* `poetry` checks on valid and aligned pyproject.toml and poetry.lock files
* `sqlfluff` checks and fixes sql formatting and linting
* (COMING SOON) `uv` checks on valid and aligned pyproject.toml and uv.lock files
* `commitlint` enforces commit message conforms to [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/) format

If you want `ruff format` to ignore a particular section of code, you can add the comments `# fmt: off` and `# fmt: on` before and after the respective block of code (same as you would if using `black`).
Expand Down
Loading