Skip to content

Commit

Permalink
Added basic git pre-commit hook setup for auto-formatting.
Browse files Browse the repository at this point in the history
Also:
- Added a simple Makefile for easily installing and using a uv-based local dev setup
- Refactored pyproject.toml to use the recommended dependency-groups and minimum versions for all dependencies
  • Loading branch information
tleonhardt committed Jan 17, 2025
1 parent c5ccd25 commit dec23d0
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 58 deletions.
10 changes: 8 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ $ pip freeze | grep pyperclip

If your versions are lower than the prerequisite versions, you should update.

If you do not already have Python installed on your machine, we recommend using [uv](https://github.com/astral-sh/uv)
If you do not already have Python installed on your machine, we recommend using [uv](https://github.com/astral-sh/uv)
for all of your Python needs because it is extremely fast, meets all Python installation and packaging needs, and works
on all platforms (Windows, Mac, and Linux). You can install `uv` using instructions at the link above.

Expand Down Expand Up @@ -221,7 +221,13 @@ To create a virtual environment and install everything needed for `cmd2` develop
from a GitHub checkout:

```sh
uv venv
make install
```

To install the recommended Git pre-commit hooks for auto-formatting locally, do the following:

```sh
uv run pre-commit run -a
```

To create a new virtualenv, using a specific version of Python you have installed, use the
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ uv.lock
# Node/npm used for installing Prettier locally to override the outdated version that is bundled with the VSCode extension
node_modules/
package-lock.json
package.json
package.json
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v5.0.0"
hooks:
- id: check-case-conflict
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.9.2"
hooks:
- id: ruff-format
args: [--config=pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0"
hooks:
- id: prettier
additional_dependencies:
- [email protected]
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Markdown documentation files with non-standards syntax for mkdocstrings that Prettier should not auto-format
docs/features/initialization.md
docs/features/initialization.md
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Simple Makefile for use with a uv-based development environment
.PHONY: install
install: ## Install the virtual environment
@echo "🚀 Creating virtual environment"
@uv sync

.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking lock file consistency with 'pyproject.toml'"
@uv lock --locked
@echo "🚀 Linting code: Running pre-commit"
@uv run pre-commit run -a
@echo "🚀 Static type checking: Running mypy"
@uv run mypy

.PHONY: test
test: ## Test the code with pytest.
@echo "🚀 Testing code: Running pytest"
@uv run python -m pytest --cov --cov-config=pyproject.toml --cov-report=xml tests

.PHONY: build
build: clean-build ## Build wheel file
@echo "🚀 Creating wheel file"
@uvx --from build pyproject-build --installer uv

.PHONY: clean-build
clean-build: ## Clean build artifacts
@echo "🚀 Removing build artifacts"
@uv run python -c "import shutil; import os; shutil.rmtree('dist') if os.path.exists('dist') else None"

.PHONY: publish
publish: ## Publish a release to PyPI.
@echo "🚀 Publishing: Dry run."
@uvx --from build pyproject-build --installer uv
@echo "🚀 Publishing."
@uvx twine upload --repository-url https://upload.pypi.org/legacy/ dist/*

.PHONY: build-and-publish
build-and-publish: build publish ## Build and publish.

.PHONY: docs-test
docs-test: ## Test if documentation can be built without warnings or errors
@uv run mkdocs build -s

.PHONY: docs
docs: ## Build and serve the documentation
@uv run mkdocs serve

.PHONY: help
help:
@uv run python -c "import re; \
[[print(f'\033[36m{m[0]:<20}\033[0m {m[1]}') for m in re.findall(r'^([a-zA-Z_-]+):.*?## (.*)$$', open(makefile).read(), re.M)] for makefile in ('$(MAKEFILE_LIST)').strip().split()]"

.DEFAULT_GOAL := help
1 change: 0 additions & 1 deletion examples/scripts/nested.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
!echo "Doing a relative run script"
_relative_run_script script.txt

2 changes: 1 addition & 1 deletion examples/tmux_launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ if [ $# -eq 1 ]
fi

tmux new-session -s "tmux window demo" -n "$FIRST_COMMAND" "$FIRST_COMMAND ;read" \; \
new-window -n "$SECOND_COMMAND" "$SECOND_COMMAND ; read" \; previous-window
new-window -n "$SECOND_COMMAND" "$SECOND_COMMAND ; read" \; previous-window
2 changes: 1 addition & 1 deletion examples/tmux_split.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ fi

tmux new-session -s "tmux split pane demo" "$FIRST_COMMAND ; read" \; \
split-window "$SECOND_COMMAND ; read" \; \
select-layout even-vertical
select-layout even-vertical
94 changes: 44 additions & 50 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["build", "setuptools>=64", "setuptools-scm>=8"]
requires = ["build>=1.2.1", "setuptools>=64", "setuptools-scm>=8"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -28,58 +28,70 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"gnureadline; platform_system == 'Darwin'",
"pyperclip",
"pyreadline3; platform_system == 'Windows'",
"wcwidth",
"gnureadline>=8; platform_system == 'Darwin'",
"pyperclip>=1.8",
"pyreadline3>=3.4; platform_system == 'Windows'",
"wcwidth>=0.2.10",
]

[project.optional-dependencies]
build = ["build", "setuptools", "setuptools-scm"]
[dependency-groups]
build = ["build>=1.2.1", "setuptools>=64", "setuptools-scm>=8"]
dev = [
"black",
"codecov",
"griffe-typingdoc",
"invoke",
"mkdocs-include-markdown-plugin",
"mkdocs-macros-plugin",
"mkdocs-material",
"mkdocstrings[python]",
"mypy",
"pytest",
"pytest-cov",
"pytest-mock",
"ruff",
"twine",
"black>=24",
"codecov>=2",
"griffe-typingdoc>=0.2",
"invoke>=2",
"mkdocs-include-markdown-plugin>=6",
"mkdocs-macros-plugin>=1",
"mkdocs-material>=8",
"mkdocstrings[python]>=0.26",
"mypy>=1.12",
"pre-commit>=2.20.0",
"pytest>=7",
"pytest-cov>=4",
"pytest-mock>=3.14",
"ruff>=0.9",
"twine>=6",
]
docs = [
"black",
"griffe-typingdoc",
"mkdocs-include-markdown-plugin",
"mkdocs-macros-plugin",
"mkdocs-material",
"mkdocstrings[python]",
"setuptools",
"setuptools_scm",
"black>=24",
"griffe-typingdoc>=0.2",
"mkdocs-include-markdown-plugin>=6",
"mkdocs-macros-plugin>=1",
"mkdocs-material>=8",
"mkdocstrings[python]>=0.26",
"setuptools>=64",
"setuptools_scm>=8",
]
test = ["codecov", "coverage", "pytest", "pytest-cov", "pytest-mock"]
validate = ["mypy", "ruff", "types-setuptools"]
test = [
"codecov>=2",
"coverage>=7",
"pytest>=7",
"pytest-cov>=4",
"pytest-mock>=3.14",
]
validate = ["mypy>=1.12", "ruff>=0.9", "types-setuptools>=69"]

[tool.mypy]
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_defs = true
exclude = [
"^.git/",
"^.venv/",
"^build/", # .build directory
"^docs/", # docs directory
"^dist/",
"^examples/", # examples directory
"^plugins/*", # plugins directory
"^noxfile\\.py$", # nox config file
"setup\\.py$", # any files named setup.py
"^site/",
"^tasks\\.py$", # tasks.py invoke config file
"^tests/", # tests directory
"^tests_isolated/", # tests_isolated directory
]
files = ['.']
show_column_numbers = true
show_error_codes = true
show_error_context = true
Expand Down Expand Up @@ -276,25 +288,7 @@ packages = ["cmd2"]
[tool.setuptools_scm]

[tool.uv]
dev-dependencies = [
"black",
"build",
"cmd2-ext-test",
"codecov",
"griffe-typingdoc",
"invoke",
"mkdocs-include-markdown-plugin",
"mkdocs-macros-plugin",
"mkdocs-material",
"mkdocstrings[python]",
"mypy",
"pytest",
"pytest-cov",
"pytest-mock",
"ruff",
"ruff",
"twine",
]
default-groups = ["dev"]

[tool.uv.sources]
cmd2-ext-test = { path = "plugins/ext_test", editable = true }
2 changes: 1 addition & 1 deletion readme_files/shout_out.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Application Name, Description

Oldies but goodie,,
[JSShell](https://github.com/Den1al/JSShell),An interactive multi-user web JavaScript shell.
[FLASHMINGO](https://github.com/fireeye/flashmingo),Automatic analysis of SWF files based on some heuristics. Extensible via plugins.
[FLASHMINGO](https://github.com/fireeye/flashmingo),Automatic analysis of SWF files based on some heuristics. Extensible via plugins.

0 comments on commit dec23d0

Please sign in to comment.