Skip to content

Commit

Permalink
build: min py 3.9 and tooling update.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschutt committed Mar 23, 2024
1 parent bd867b8 commit 1f2852a
Show file tree
Hide file tree
Showing 16 changed files with 639 additions and 497 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
timeout-minutes: 30
defaults:
run:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target/
*.iml
.DS_Store
.coverage
.dmypy.json
.python-version
.ruff_cache
/docs/_build/
Expand Down
48 changes: 13 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
default_language_version:
python: "3.11"
python: "3.9"
repos:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.4.0
rev: v3.1.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-ast
- id: check-case-conflict
Expand All @@ -16,53 +16,31 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/pdm-project/pdm
rev: 2.9.2
hooks:
- id: pdm-lock-check
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.290"
rev: "v0.3.4"
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
exclude: "tests/openapi/typescript_converter/test_converter"
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
args: [--config=./pyproject.toml]
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
hooks:
- id: prettier
exclude: "_templates|.git|.all-contributorsrc"
additional_dependencies:
- tomli
- repo: https://github.com/python-formate/flake8-dunder-all
rev: v0.3.0
rev: v0.3.1
hooks:
- id: ensure-dunder-all
exclude: "test*|examples*|tools"
exclude: "test*|tools"
args: ["--use-tuple"]
- repo: https://github.com/ariebovenberg/slotscheck
rev: v0.17.0
rev: v0.18.0
hooks:
- id: slotscheck
exclude: "test_*|docs"
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.5.1"
hooks:
- id: mypy
exclude: "tools|docs"
additional_dependencies: [pytest]
exclude: "docs|.github"
- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: "v0.6.8"
rev: "v0.9.1"
hooks:
- id: sphinx-lint
- repo: local
Expand Down
80 changes: 62 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SHELL := /bin/bash
.DEFAULT_GOAL:=help
.ONESHELL:
USING_PDM = $(shell grep "tool.pdm" pyproject.toml && echo "yes")
ENV_PREFIX = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')")
ENV_PREFIX = .venv/bin/
VENV_EXISTS = $(shell python3 -c "if __import__('pathlib').Path('.venv/bin/activate').exists(): print('yes')")
PDM_OPTS ?=
PDM ?= pdm $(PDM_OPTS)
Expand All @@ -23,7 +23,7 @@ upgrade: ## Upgrade all dependencies to the latest stable versio
@echo "=> Updating all dependencies"
@if [ "$(USING_PDM)" ]; then $(PDM) update; fi
@echo "=> Dependencies Updated"
@$(ENV_PREFIX)pre-commit autoupdate
@$(PDM) run pre-commit autoupdate
@echo "=> Updated Pre-commit"

# =============================================================================
Expand All @@ -33,17 +33,20 @@ upgrade: ## Upgrade all dependencies to the latest stable versio
install-pdm: ## Install latest version of PDM
@curl -sSLO https://pdm.fming.dev/install-pdm.py && \
curl -sSL https://pdm.fming.dev/install-pdm.py.sha256 | shasum -a 256 -c - && \
python3 install-pdm.py
python3 install-pdm.py && \
rm install-pdm.py

install: ## Install the project and
.PHONY: install
install: clean ## Install the project, dependencies, and pre-commit for local development
@if ! $(PDM) --version > /dev/null; then echo '=> Installing PDM'; $(MAKE) install-pdm; fi
@if [ "$(VENV_EXISTS)" ]; then echo "=> Removing existing virtual environment"; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) destroy; fi
if [ "$(VENV_EXISTS)" ]; then $(MAKE) clean; fi
@if [ "$(USING_PDM)" ]; then $(PDM) config venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython pip; fi
@if [ "$(USING_PDM)" ]; then $(PDM) install -G:all; fi
@if [ "$(USING_PDM)" ]; then $(PDM) config --local venv.in_project true && python3 -m venv --copies .venv && . $(ENV_PREFIX)/activate && $(ENV_PREFIX)/pip install --quiet -U wheel setuptools cython mypy pip; fi
@if [ "$(USING_PDM)" ]; then $(PDM) install -dG:all; fi
@echo "=> Install complete! Note: If you want to re-install re-run 'make install'"

.PHONY: clean
clean: ## Cleanup temporary build artifacts
@echo "=> Cleaning working directory"
@rm -rf .pytest_cache .ruff_cache .hypothesis build/ -rf dist/ .eggs/
Expand All @@ -57,42 +60,75 @@ clean: ## Cleanup temporary build artifacts
@rm -rf .coverage coverage.xml coverage.json htmlcov/ .pytest_cache tests/.pytest_cache tests/**/.pytest_cache .mypy_cache
$(MAKE) docs-clean

.PHONY: destroy
destroy: ## Destroy the virtual environment
@rm -rf .venv

.PHONY: refresh-lockfiles
refresh-lockfiles: ## Sync lockfiles with requirements files.
pdm update --update-reuse --group :all

.PHONY: lock
lock: ## Rebuild lockfiles from scratch, updating all dependencies
pdm update --update-eager --group :all

# =============================================================================
# Tests, Linting, Coverage
# =============================================================================
.PHONY: lint
lint: ## Runs pre-commit hooks; includes ruff linting, codespell, black
.PHONY: mypy
mypy: ## Run mypy
@echo "=> Running mypy"
@$(PDM) run dmypy run
@echo "=> mypy complete"

.PHONY: mypy-nocache
mypy-nocache: ## Run Mypy without cache
@echo "=> Running mypy without a cache"
@$(PDM) run dmypy run -- --cache-dir=/dev/null
@echo "=> mypy complete"

.PHONY: pyright
pyright: ## Run pyright
@echo "=> Running pyright"
@$(PDM) run pyright
@echo "=> pyright complete"

.PHONY: type-check
type-check: mypy pyright ## Run all type checking

.PHONY: pre-commit
pre-commit: ## Runs pre-commit hooks; includes ruff formatting and linting, codespell
@echo "=> Running pre-commit process"
@$(ENV_PREFIX)pre-commit run --all-files
@$(PDM) run pre-commit run --all-files
@echo "=> Pre-commit complete"

.PHONY: lint
lint: pre-commit type-check ## Run all linting

.PHONY: coverage
coverage: ## Run the tests and generate coverage report
@echo "=> Running tests with coverage"
@$(ENV_PREFIX)pytest tests --cov=type_lens
@$(ENV_PREFIX)coverage html
@$(ENV_PREFIX)coverage xml
@$(PDM) run pytest tests --cov -n auto
@$(PDM) run coverage html
@$(PDM) run coverage xml
@echo "=> Coverage report generated"

.PHONY: test
test: ## Run the tests
@echo "=> Running test cases"
@$(ENV_PREFIX)pytest tests
@$(PDM) run pytest tests
@echo "=> Tests complete"

.PHONY: test-examples
test-examples: ## Run the examples tests
pytest docs/examples
@$(PDM) run pytest docs/examples

.PHONY: test-all
test-all: test test-examples ## Run all tests


.PHONY: check-all
check-all: lint test-all coverage ## Run all linting, tests, and coverage checks
check-all: lint test-all coverage ## Run all linting, tests, and coverage checks


# =============================================================================
# Docs
Expand All @@ -110,8 +146,16 @@ docs-clean: ## Dump the existing built docs

docs-serve: docs-clean ## Serve the docs locally
@echo "=> Serving documentation"
$(ENV_PREFIX)sphinx-autobuild docs docs/_build/ -j auto --watch type_lens --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002
$(PDM) run sphinx-autobuild docs docs/_build/ -j auto --watch polyfactory --watch docs --watch tests --watch CONTRIBUTING.rst --port 8002

docs: docs-clean ## Dump the existing built docs and rebuild them
@echo "=> Building documentation"
@$(ENV_PREFIX)sphinx-build -M html docs docs/_build/ -E -a -j auto --keep-going
@$(PDM) run sphinx-build -M html docs docs/_build/ -E -a -j auto -W --keep-going

.PHONY: docs-linkcheck
docs-linkcheck: ## Run the link check on the docs
@$(PDM) run sphinx-build -b linkcheck ./docs ./docs/_build -D linkcheck_ignore='http://.*','https://.*'

.PHONY: docs-linkcheck-full
docs-linkcheck-full: ## Run the full link check on the docs
@$(PDM) run sphinx-build -b linkcheck ./docs ./docs/_build -D linkcheck_anchors=0
26 changes: 6 additions & 20 deletions docs/PYPI_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,15 @@

## About

This project is a template repository for [Jolt][jolt-org] projects. It is designed to be a starting point for
any project that is a part of the Jolt organization.
`type-lens` is a library that allows for utilizing Python types at runtime.

## Usage

- [Install copier](https://copier.readthedocs.io/en/stable/#installation)
- `$ copier copy gh:jolt-org/project-template $new-project-name`
- Answer questions.

## New project checklist

- [ ] Create the https://github.com/jolt-org/type-lens repository.
- [ ] If using docs: Create the https://github.com/jolt-org/type-lens-docs-preview repository.
- [ ] If not using docs: remove `.github/workflows/docs-preview.yaml`.
- [ ] Update the [README.md](README.md) file with the project-specific information.
- [ ] Initialize git repository: `$ git init`
- [ ] Stage the files: `$ git add ."`
- [ ] Install pre-commit hooks: `$ pre-commit install`
- [ ] Run pre-commit hooks: `$ pre-commit run --all-files`
- [ ] Stage any files that were modified by the pre-commit hooks: `$ git add .`
- [ ] Commit the changes: `$ git commit -m "Initial commit"`
- [ ] Add the remote: `$ git remote add origin [email protected]:jolt-org/type-lens.git`
- [ ] Push the changes: `$ git push -u origin main`
- Install `type-lens` with `pip` or check out [our installation guide][install-guide]

```shell
pip install type-lens
```

## Contributing

Expand Down
Loading

0 comments on commit 1f2852a

Please sign in to comment.