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

Dev #151

Merged
merged 3 commits into from
Sep 25, 2024
Merged

Dev #151

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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.12', '3.11']
package: ['managetemplates', 'pipenv-python', 'piptools-python', 'yunohost_django_package']
python-version: ["3.12", "3.11"]
steps:
- name: Checkout
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
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
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
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
13 changes: 13 additions & 0 deletions .pre-commit-hooks.yaml
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]
309 changes: 300 additions & 9 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli.py
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, 10), 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
5 changes: 4 additions & 1 deletion dev-cli.py
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, 10), 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 @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.13", "3.12", "3.11"]
python-version: ["3.12", "3.11"]
steps:
- name: Checkout
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update():
verbose_check_call(bin_path / 'pip-sync', 'requirements.dev.txt')

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


@cli.command()
Expand Down
2 changes: 1 addition & 1 deletion managetemplates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"""

# See https://packaging.python.org/en/latest/specifications/version-specifiers/
__version__ = '0.4.0'
__version__ = '0.5.0'
__author__ = 'Jens Diemer <[email protected]>'
27 changes: 27 additions & 0 deletions managetemplates/cli_app/update_readme_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys

import rich_click as click
from cli_base.cli_tools import git_history
from cli_base.cli_tools.verbosity import OPTION_KWARGS_VERBOSE, setup_logging
from rich import print # noqa

from managetemplates.cli_app import cli


@cli.command()
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def update_readme_history(verbosity: int):
"""
Update project history base on git commits/tags in README.md

Will be exited with 1 if the README.md was updated otherwise with 0.

Also, callable via e.g.:
python -m cli_base update-readme-history -v
"""
setup_logging(verbosity=verbosity)
updated = git_history.update_readme_history(verbosity=verbosity)
exit_code = 1 if updated else 0
if verbosity:
print(f'{exit_code=}')
sys.exit(exit_code)
2 changes: 1 addition & 1 deletion managetemplates/cli_dev/code_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,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 managetemplates source code files via darker
"""
code_style.fix(package_root=PACKAGE_ROOT, darker_color=color, darker_verbose=verbosity > 0)

Expand Down
22 changes: 7 additions & 15 deletions managetemplates/cli_dev/packaging.py
Original file line number Diff line number Diff line change
@@ -1,21 +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 managetemplates
from managetemplates.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 'managetemplates' 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 @@ -44,14 +44,7 @@ def update():
CUSTOM_COMPILE_COMMAND='./dev-cli.py update',
)

pip_compile_base = [
bin_path / 'pip-compile',
'--verbose',
'--allow-unsafe', # https://pip-tools.readthedocs.io/en/latest/#deprecations
'--resolver=backtracking', # https://pip-tools.readthedocs.io/en/latest/#deprecations
'--upgrade',
'--generate-hashes',
]
pip_compile_base = [bin_path / 'pip-compile', '--verbose', '--upgrade']

# Only "prod" dependencies:
verbose_check_call(
Expand All @@ -77,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 @@ -85,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=managetemplates, package_path=PACKAGE_ROOT)
5 changes: 3 additions & 2 deletions managetemplates/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@


BASE_PATH = Path(managetemplates.__file__).parent
PACKAGE_ROOT = BASE_PATH.parent

PACKAGE_ROOT = BASE_PATH.parent
assert_is_file(PACKAGE_ROOT / 'pyproject.toml') # Exists only in cloned git repo

README_PATH = PACKAGE_ROOT / 'README.md'
assert_is_file(README_PATH)

CLI_EPILOG = 'Project Homepage: https://github.com/jedie/cookiecutter_templates'

Expand Down Expand Up @@ -41,4 +43,3 @@


PY_BIN_PATH = Path(sys.executable).parent
BASE_PATH = Path(managetemplates.__file__).parent
13 changes: 7 additions & 6 deletions managetemplates/tests/test_project_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from bx_py_utils.path import assert_is_dir, assert_is_file
from cli_base.cli_tools.code_style import assert_code_style
from cli_base.cli_tools.subprocess_utils import ToolsExecutor
from manageprojects.test_utils.click_cli_utils import invoke_click
from manageprojects.test_utils.project_setup import check_editor_config, get_py_max_line_length
from manageprojects.test_utils.subprocess import SubprocessCallMock as SubprocessCallMockOrigin
Expand Down Expand Up @@ -130,28 +131,23 @@ def test_update(self):
[
'.../bin/pip-compile',
'--verbose',
'--allow-unsafe',
'--resolver=backtracking',
'--upgrade',
'--generate-hashes',
'pyproject.toml',
'--output-file',
'requirements.txt',
],
[
'.../bin/pip-compile',
'--verbose',
'--allow-unsafe',
'--resolver=backtracking',
'--upgrade',
'--generate-hashes',
'pyproject.toml',
'--extra=dev',
'--output-file',
'requirements.dev.txt',
],
['.../bin/pip-audit', '-v', '--strict', '--require-hashes', '-r', 'requirements.dev.txt'],
['.../bin/pip-sync', 'requirements.dev.txt'],
['.../bin/pre-commit', 'autoupdate'],
],
)

Expand Down Expand Up @@ -199,3 +195,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)
18 changes: 15 additions & 3 deletions managetemplates/tests/test_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from managetemplates import constants
from managetemplates.cli_app import cli
from managetemplates.constants import PACKAGE_ROOT
from managetemplates.cli_dev import cli as dev_cli
from managetemplates.constants import PACKAGE_ROOT, README_PATH


README_PATH = PACKAGE_ROOT / 'README.md'

ADDITIONAL_TEMPLATE = '''
Cookiecutter template tests are here: [%(tests_rel_path)s](https://github.com/jedie/cookiecutter_templates/blob/main/%(tests_rel_path)s)

Expand Down Expand Up @@ -99,3 +98,16 @@ def test_main_help(self):
),
)
assert_cli_help_in_readme(text_block=stdout, marker='main help')

def test_dev_help(self):
stdout = invoke_click(dev_cli, '--help')
self.assert_in_content(
got=stdout,
parts=(
'Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...',
' check-code-style ',
' coverage ',
constants.CLI_EPILOG,
),
)
assert_cli_help_in_readme(text_block=stdout, marker='dev help')
29 changes: 29 additions & 0 deletions managetemplates/tests/test_readme_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
from unittest import TestCase, skipIf

from bx_py_utils.auto_doc import assert_readme_block
from cli_base.cli_tools.git_history import get_git_history

import managetemplates
from managetemplates.cli_dev import PACKAGE_ROOT


class ReadmeHistoryTestCase(TestCase):
@skipIf(
# After a release the history may be "changed" because of version bump
# and we should not block merge requests because of this.
'GITHUB_ACTION' in os.environ,
reason='Skip on github actions',
)
def test_readme_history(self):
git_history = get_git_history(
current_version=managetemplates.__version__,
add_author=False,
)
history = '\n'.join(git_history)
assert_readme_block(
readme_path=PACKAGE_ROOT / 'README.md',
text_block=f'\n{history}\n',
start_marker_line='[comment]: <> (✂✂✂ auto generated history start ✂✂✂)',
end_marker_line='[comment]: <> (✂✂✂ auto generated history end ✂✂✂)',
)
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.13", "3.12", "3.11"]
python-version: ["3.12", "3.11"]
steps:
- name: Checkout
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def update():
verbose_check_call(bin_path / 'pip-sync', 'requirements.dev.txt')

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


@cli.command()
Expand Down
Loading
Loading