Skip to content

Commit

Permalink
Merge pull request #150 from jedie/dev
Browse files Browse the repository at this point in the history
Updates for "piptools-python" template:
  • Loading branch information
jedie authored Sep 25, 2024
2 parents 56c3caa + c2226ff commit a968634
Show file tree
Hide file tree
Showing 31 changed files with 449 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.12", "3.11"]
python-version: ["3.13", "3.12", "3.11"]
steps:
- name: Checkout
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ __pycache__
!.editorconfig
!.flake8
!.gitignore
!.pre-commit-config.yaml
!.pre-commit-hooks.yaml
!.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# pre-commit plugin configuration
# See https://pre-commit.com for more information
default_install_hook_types:
- pre-commit
- post-rewrite
- pre-push

repos:
- repo: https://github.com/jedie/cli-base-utilities
rev: v0.11.0
hooks:
- id: update-readme-history
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://pre-commit.com/#creating-new-hooks
- id: update-readme-history
name: cli-base-utilities
description: >-
Update history in README.md from git log.
entry: "python -m cli_base update-readme-history -v"
language: python
language_version: python3
require_serial: true
pass_filenames: false
always_run: true
verbose: true
stages: [pre-commit, post-rewrite, pre-push]
53 changes: 53 additions & 0 deletions generated_templates/piptools-python/your_cool_package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,56 @@
[![License GPL-3.0-or-later](https://img.shields.io/pypi/l/your_cool_package)](https://github.com/john-doh/your_cool_package/blob/main/LICENSE)

A minimal Python package

## CLI

[comment]: <> (✂✂✂ auto generated main help start ✂✂✂)
```
Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ update-readme-history Update project history base on git commits/tags in README.md │
│ version Print version and exit │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```
[comment]: <> (✂✂✂ auto generated main help end ✂✂✂)


## dev CLI

[comment]: <> (✂✂✂ auto generated dev help start ✂✂✂)
```
Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ check-code-style Check code style by calling darker + flake8 │
│ coverage Run tests and show coverage report. │
│ fix-code-style Fix code style of all your_cool_package source code files via darker │
│ install Run pip-sync and install 'your_cool_package' via pip as editable. │
│ mypy Run Mypy (configured in pyproject.toml) │
│ pip-audit Run pip-audit check against current requirements files │
│ publish Build and upload this project to PyPi │
│ test Run unittests │
│ tox Run tox │
│ update Update "requirements*.txt" dependencies files │
│ update-test-snapshot-files Update all test snapshot files (by remove and recreate all snapshot │
│ files) │
│ version Print version and exit │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```
[comment]: <> (✂✂✂ auto generated dev help end ✂✂✂)


## History

[comment]: <> (✂✂✂ auto generated history start ✂✂✂)



[comment]: <> (✂✂✂ auto generated history end ✂✂✂)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def print_no_pip_error():
sys.exit(-1)


assert sys.version_info >= (3, 9), f'Python version {sys.version_info} is too old!'
assert sys.version_info >= (3, 11), f'Python version {sys.version_info} is too old!'


if sys.platform == 'win32': # wtf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def print_no_pip_error():
sys.exit(-1)


assert sys.version_info >= (3, 9), f'Python version {sys.version_info} is too old!'
assert sys.version_info >= (3, 11), f'Python version {sys.version_info} is too old!'


if sys.platform == 'win32': # wtf
Expand Down Expand Up @@ -105,6 +105,9 @@ def main(argv):
verbose_check_call(PIP_PATH, 'install', '--no-deps', '-e', '.')
store_dep_hash()

# Activate git pre-commit hooks:
verbose_check_call(PYTHON_PATH, '-m', 'pre_commit', 'install')

# Call our entry point CLI:
try:
verbose_check_call(PROJECT_SHELL_SCRIPT, *argv[1:])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dev = [
"pip-audit", # https://github.com/pypa/pip-audit
"mypy", # https://github.com/python/mypy
"twine", # https://github.com/pypa/twine
"pre-commit", # https://github.com/pre-commit/pre-commit
"typeguard", # https://github.com/agronholm/typeguard/

# https://github.com/akaihola/darker
Expand Down Expand Up @@ -83,6 +84,10 @@ require_hashes=true
ignore-vuln=[]


[tool.cli_base]
version_module_name = "your_cool_package" # Used by "update-readme-history" git hook


[tool.darker]
src = ['.']
revision = "origin/main..."
Expand Down Expand Up @@ -133,7 +138,7 @@ exclude_lines = [
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = py{312,311}
envlist = py{313,312,311}
skip_missing_interpreters = True
[testenv]
Expand All @@ -143,7 +148,7 @@ commands_pre =
pip install -U pip-tools
pip-sync requirements.dev.txt
commands =
{envpython} -m coverage run --context='{envname}'
python3 -m coverage run --context='{envname}'
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ build==1.2.2 \
--hash=sha256:277ccc71619d98afdd841a0e96ac9fe1593b823af481d3b0cea748e8894e0613 \
--hash=sha256:45b7d306fed5299c934f42ead7fc470286a3a30c957e44246ad982ab285fbb43
# via pip-tools
bx-py-utils==102 \
--hash=sha256:367d2bde9c7f2bf750f55748d4832daaf9df73e753b5efb351ec1a3899cc5d80 \
--hash=sha256:6d131d40394b477de715169e80067a0ab4891c8f04afd33fbd7ca00e2faf21ae \
--hash=sha256:961a0abf31b512f72c1473a4d115096b0c5becd32d08338ac62adbf5b217b680
bx-py-utils==104 \
--hash=sha256:508cfc1d0fa6c22298f697c4efaa913337847d488d8a53eeccfae9ee106123f6 \
--hash=sha256:77fddff99aaf2cb558ce2974ef66d0e7a4d48cca1cbb99e43eca0d8b77fa07fc \
--hash=sha256:c92ebc4fb122e3e3c228d984d0a1f5c3284c3da6aab1a1c753f7eb1f71bdab3a
# via
# cli-base-utilities
# your_cool_package (pyproject.toml)
Expand Down Expand Up @@ -153,6 +153,7 @@ cffi==1.17.1 \
--hash=sha256:d016c76bdd850f3c626af19b0542c9677ba156e4ee4fccfdd7848803533ef662 \
--hash=sha256:d01b12eeeb4427d3110de311e1774046ad344f5b1a7403101878976ecd7a10f3 \
--hash=sha256:d63afe322132c194cf832bfec0dc69a99fb9bb6bbd550f161a49e9e855cc78ff \
--hash=sha256:da2e6428aa89f81b9a97c5818e7e5875f2c40bef6abbbe17e0d768199aa943f1 \
--hash=sha256:da95af8214998d77a98cc14e3a3bd00aa191526343078b530ceb0bd710fb48a5 \
--hash=sha256:dd398dbc6773384a17fe0d3e7eeb8d1a21c2200473ee6806bb5e6a8e62bb73dd \
--hash=sha256:de2ea4b5833625383e464549fec1bc395c1bdeeb5f25c4a3a82b5a8c756ec22f \
Expand All @@ -171,6 +172,11 @@ cffi==1.17.1 \
--hash=sha256:f7f5baafcc48261359e14bcd6d9bff6d4b28d9103847c9e136694cb0501aef87 \
--hash=sha256:fc48c783f9c87e60831201f2cce7f3b2e4846bf4d8728eabe54d60700b318a0b
# via cryptography
cfgv==3.4.0 \
--hash=sha256:a26cde6f2dbc2fb41e75d59fe67f9a9deb9c0257659fd357194e97f3e0891297 \
--hash=sha256:b7265b1f29fd3316bfcd2b330d63d024f2bfd8bcb8b0272f8e19a504856c48f9 \
--hash=sha256:e52591d4c5f5dead8e0f673fb16db7949d2cfb3f7da4582893288f0ded8fe560
# via pre-commit
chardet==5.2.0 \
--hash=sha256:1b3b6ff479a8c414bc3fa2c0852995695c4a026dcd6d0633b2dd092ca39c1cf7 \
--hash=sha256:5e60dfdc063399966f1864c5cfdb9dfeb45361dc57770ddf07eea37f6bea3019 \
Expand Down Expand Up @@ -487,6 +493,11 @@ html5lib==1.1 \
--hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f \
--hash=sha256:e6a6ca5b1d876bce04ea36e2dd747a45b36fe3d9ac4db0b8437f46842fbebcbf
# via pip-audit
identify==2.6.1 \
--hash=sha256:53863bcac7caf8d2ed85bd20312ea5dcfc22226800f6d6881f232d861db5a8f0 \
--hash=sha256:91478c5fb7c3aac5ff7bf9b4344f803843dc586832d5f110d672b19aa1984c98 \
--hash=sha256:fabaffe28c2f7e909ce6424a31ca8ee25b4c90beee6ca5900c5fdb77b2ef6aee
# via pre-commit
idna==3.10 \
--hash=sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9 \
--hash=sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3
Expand Down Expand Up @@ -538,10 +549,9 @@ license-expression==30.3.1 \
--hash=sha256:60d5bec1f3364c256a92b9a08583d7ea933c7aa272c8d36d04144a89a3858c01 \
--hash=sha256:97904b9185c7bbb1e98799606fa7424191c375e70ba63a524b6f7100e42ddc46
# via cyclonedx-python-lib
manageprojects==0.19.1 \
--hash=sha256:7e0dc7df3d46e21bd9fd89c026c3d2980eb70563924d9b226ec04b850942f5bd \
--hash=sha256:e251874464a2bb23e1c0508ce147e592787d88adb1df7850271a1ff6f0fe98a3 \
--hash=sha256:ed33522b96ebe3cd67a4ec0a28e4673f4351dd235cf65c77ff4226845f39101e
manageprojects==0.19.2 \
--hash=sha256:4c5649deb9791f3016c1848b34080e1564ea3bec2a8e25a09f9f0af9012086df \
--hash=sha256:5f9b7d692df1540b8787ae31acc9613270be01c7d4416aad77e5dee4ca97e363
# via your_cool_package (pyproject.toml)
markdown-it-py==3.0.0 \
--hash=sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1 \
Expand Down Expand Up @@ -756,6 +766,11 @@ nh3==0.2.18 \
--hash=sha256:de3ceed6e661954871d6cd78b410213bdcb136f79aafe22aa7182e028b8c7307 \
--hash=sha256:f0eca9ca8628dbb4e916ae2491d72957fdd35f7a5d326b7032a345f111ac07fe
# via readme-renderer
nodeenv==1.9.1 \
--hash=sha256:6ec12890a2dab7946721edbfbcd91f3319c6ccc9aec47be7c7e6b7011ee6645f \
--hash=sha256:ba11c9782d29c27c70ffbdda2d7415098754709be8a7056d79a737cd901155c9 \
--hash=sha256:e3d5a1b67a0cdf73b094aca8a68a80befbde9ca317303f18bf8af61198edc37f
# via pre-commit
packageurl-python==0.15.6 \
--hash=sha256:0d39b14186da7367ab71ca35e656cfc1e81eaf98dcd2801ded953f34232bfc92 \
--hash=sha256:a40210652c89022772a6c8340d6066f7d5dc67132141e5284a4db7a27d0a8ab0 \
Expand Down Expand Up @@ -814,6 +829,11 @@ pluggy==1.5.0 \
--hash=sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1 \
--hash=sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669
# via tox
pre-commit==3.8.0 \
--hash=sha256:03a8cc30ccb2ff639d46e6f47563a1ceffb02578ce6ab3adb5f10c38d4e47cea \
--hash=sha256:8bb6494d4a20423842e198980c9ecf9f96607a07ea29549e180eef9ae80fe7af \
--hash=sha256:9a90a53bf82fdd8778d58085faf8d83df56e40dfe18f45b19446e26bf1b3a63f
# via your_cool_package (pyproject.toml)
py-serializable==1.1.1 \
--hash=sha256:008cf879c8a227851e745e307c1a1c9b58bc22ab87f3794a3750513b6c9e8713 \
--hash=sha256:f268db3afc42c8786da6dc64a8a36e33a82cf65cdcff22d1188b0927f6d4cfa9
Expand Down Expand Up @@ -936,7 +956,9 @@ pyyaml==6.0.2 \
--hash=sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba \
--hash=sha256:f753120cb8181e736c57ef7636e83f31b9c0d1722c516f7e86cf15b7aa57ff12 \
--hash=sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4
# via cookiecutter
# via
# cookiecutter
# pre-commit
readme-renderer==44.0 \
--hash=sha256:2fbca89b81a08526aadf1357a8c2ae889ec05fb03f5da67f9769c9a592166151 \
--hash=sha256:8712034eabbfa6805cacf1402b4eeb2a73028f72d1166d6f5cb7f9c047c5d1e1 \
Expand Down Expand Up @@ -1063,7 +1085,9 @@ urllib3==2.2.3 \
virtualenv==20.26.5 \
--hash=sha256:4f3ac17b81fba3ce3bd6f4ead2749a72da5929c01774948e243db9ba41df4ff6 \
--hash=sha256:ce489cac131aa58f4b25e321d6d186171f78e6cb13fafbf32a840cee67733ff4
# via tox
# via
# pre-commit
# tox
webencodings==0.5.1 \
--hash=sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78 \
--hash=sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ async-timeout==4.0.3 \
--hash=sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028 \
--hash=sha256:fd893e4cb1d9dff66d0e0576cc6376a23eacbbcd43b6607e4d3ecfae1ab15367
# via cli-base-utilities
bx-py-utils==102 \
--hash=sha256:367d2bde9c7f2bf750f55748d4832daaf9df73e753b5efb351ec1a3899cc5d80 \
--hash=sha256:6d131d40394b477de715169e80067a0ab4891c8f04afd33fbd7ca00e2faf21ae \
--hash=sha256:961a0abf31b512f72c1473a4d115096b0c5becd32d08338ac62adbf5b217b680
bx-py-utils==104 \
--hash=sha256:508cfc1d0fa6c22298f697c4efaa913337847d488d8a53eeccfae9ee106123f6 \
--hash=sha256:77fddff99aaf2cb558ce2974ef66d0e7a4d48cca1cbb99e43eca0d8b77fa07fc \
--hash=sha256:c92ebc4fb122e3e3c228d984d0a1f5c3284c3da6aab1a1c753f7eb1f71bdab3a
# via
# cli-base-utilities
# your_cool_package (pyproject.toml)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from cli_base.cli_tools import code_style
from cli_base.cli_tools.verbosity import OPTION_KWARGS_VERBOSE
from cli_base.click_defaults import OPTION_ARGS_DEFAULT_TRUE

from your_cool_package.cli_dev import PACKAGE_ROOT, cli


Expand All @@ -10,7 +11,7 @@
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def fix_code_style(color: bool, verbosity: int):
"""
Fix code style of all cli_base source code files via darker
Fix code style of all your_cool_package source code files via darker
"""
code_style.fix(package_root=PACKAGE_ROOT, darker_color=color, darker_verbose=verbosity > 0)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import sys
from pathlib import Path

import cli_base
import click
from cli_base.cli_tools.dev_tools import run_unittest_cli
from cli_base.cli_tools.subprocess_utils import verbose_check_call
from cli_base.cli_tools.verbosity import OPTION_KWARGS_VERBOSE
from cli_base.run_pip_audit import run_pip_audit
from manageprojects.utilities.publish import publish_package

import your_cool_package
from your_cool_package.cli_dev import PACKAGE_ROOT, cli


@cli.command()
def install():
"""
Run pip-sync and install 'cli_base' via pip as editable.
Run pip-sync and install 'your_cool_package' via pip as editable.
"""
verbose_check_call('pip-sync', PACKAGE_ROOT / 'requirements.dev.txt')
verbose_check_call('pip', 'install', '--no-deps', '-e', '.')
Expand Down Expand Up @@ -69,6 +70,9 @@ def update():
# Install new dependencies in current .venv:
verbose_check_call(bin_path / 'pip-sync', 'requirements.dev.txt')

# Update git pre-commit hooks:
verbose_check_call(bin_path / 'pre_commit', 'autoupdate')


@cli.command()
def publish():
Expand All @@ -77,8 +81,4 @@ def publish():
"""
run_unittest_cli(verbose=False, exit_after_run=False) # Don't publish a broken state

publish_package(
module=cli_base,
package_path=PACKAGE_ROOT,
distribution_name='cli-base-utilities',
)
publish_package(module=your_cool_package, package_path=PACKAGE_ROOT)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bx_py_utils.path import assert_is_file
from manageprojects.test_utils.project_setup import check_editor_config, get_py_max_line_length
from cli_base.cli_tools.code_style import assert_code_style
from cli_base.cli_tools.subprocess_utils import ToolsExecutor
from packaging.version import Version

from your_cool_package import __version__
Expand Down Expand Up @@ -38,3 +39,8 @@ def test_check_editor_config(self):

max_line_length = get_py_max_line_length(package_root=PACKAGE_ROOT)
self.assertEqual(max_line_length, 119)

def test_pre_commit_hooks(self):
executor = ToolsExecutor(cwd=PACKAGE_ROOT)
for command in ('migrate-config', 'validate-config', 'validate-manifest'):
executor.verbose_check_call('pre-commit', command, exit_on_error=True)
Loading

0 comments on commit a968634

Please sign in to comment.