Skip to content

Commit

Permalink
Update requirements + apply template updates
Browse files Browse the repository at this point in the history
Also add work-a-round for: jazzband/pip-tools#994
  • Loading branch information
jedie committed Aug 29, 2024
1 parent 184ad78 commit 0671a08
Show file tree
Hide file tree
Showing 11 changed files with 716 additions and 729 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
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", "3.10", "3.9"]
python-version: ["3.12", "3.11"]
steps:
- name: Checkout
run: |
Expand All @@ -26,7 +26,7 @@ jobs:
git checkout $GITHUB_SHA || (git fetch && git checkout $GITHUB_SHA)
- name: 'Set up Python ${{ matrix.python-version }}'
uses: actions/setup-python@v4
uses: actions/setup-python@v5
# https://github.com/marketplace/actions/setup-python
with:
python-version: '${{ matrix.python-version }}'
Expand All @@ -51,9 +51,9 @@ jobs:
run: |
./dev-cli.py --help
- name: 'Safety'
- name: 'Run pip-audit'
run: |
./dev-cli.py safety
./dev-cli.py pip-audit
- name: 'Run tests with Python v${{ matrix.python-version }}'
env:
Expand All @@ -63,7 +63,7 @@ jobs:
./dev-cli.py coverage
- name: 'Upload coverage report'
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
# https://github.com/marketplace/actions/codecov
with:
fail_ci_if_error: false
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ default_install_hook_types:

repos:
- repo: https://github.com/jedie/cli-base-utilities
rev: v0.7.0rc3
rev: v0.10.3
hooks:
- id: update-readme-history
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ Usage: ./cli.py [OPTIONS] COMMAND [ARGS]...
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ clone-project Clone existing project by replay the cookiecutter template in a new directory. │
│ format-file Format and check the given python source code file with │
│ darker/autoflake/isort/pyupgrade/autopep8/mypy etc. │
│ reverse Create a cookiecutter template from a managed project. │
│ start-project Start a new "managed" project via a CookieCutter Template. Note: The │
│ CookieCutter Template *must* be use git! │
│ update-project Update a existing project. │
│ version Print version and exit │
│ wiggle Run wiggle to merge *.rej in given directory. │
│ https://github.com/neilbrown/wiggle │
│ clone-project Clone existing project by replay the cookiecutter template in a new │
│ directory. │
│ format-file Format and check the given python source code file with │
│ darker/autoflake/isort/pyupgrade/autopep8/mypy etc. │
│ reverse Create a cookiecutter template from a managed project. │
│ start-project Start a new "managed" project via a CookieCutter Template. Note: The │
│ CookieCutter Template *must* be use git! │
│ update-project Update a existing project. │
│ update-readme-history Update project history base on git commits/tags in README.md │
│ version Print version and exit │
│ wiggle Run wiggle to merge *.rej in given directory. │
│ https://github.com/neilbrown/wiggle │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
```
[comment]: <> (✂✂✂ auto generated main help end ✂✂✂)
Expand Down Expand Up @@ -304,9 +306,9 @@ Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...
│ git-hooks Setup our "pre-commit" git hooks │
│ install Run pip-sync and install 'manageprojects' 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 │
│ run-git-hooks Run the installed "pre-commit" git hooks │
│ safety Run safety check against current requirements files │
│ test Run unittests │
│ tox Run tox │
│ update Update "requirements*.txt" dependencies files │
Expand Down Expand Up @@ -334,6 +336,7 @@ See also git tags: https://github.com/jedie/manageprojects/tags
[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [v0.17.2](https://github.com/jedie/manageprojects/compare/v0.17.1...v0.17.2)
* 2024-08-29 - Update requirements + apply template updates
* 2024-03-08 - Run "refurb", too.
* 2024-01-16 - add and use typeguard in tests
* 2024-07-09 - Split CLI
Expand Down
4 changes: 2 additions & 2 deletions 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, 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 All @@ -48,7 +48,7 @@ def print_no_pip_error():
BASE_PATH = Path(__file__).parent
VENV_PATH = BASE_PATH / '.venv-app'
BIN_PATH = VENV_PATH / BIN_NAME
PYTHON_PATH = BIN_PATH / f'python{FILE_EXT}'
PYTHON_PATH = BIN_PATH / f'python3{FILE_EXT}'
PIP_PATH = BIN_PATH / f'pip{FILE_EXT}'
PIP_SYNC_PATH = BIN_PATH / f'pip-sync{FILE_EXT}'

Expand Down
8 changes: 6 additions & 2 deletions 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, 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 All @@ -48,7 +48,7 @@ def print_no_pip_error():
BASE_PATH = Path(__file__).parent
VENV_PATH = BASE_PATH / '.venv'
BIN_PATH = VENV_PATH / BIN_NAME
PYTHON_PATH = BIN_PATH / f'python{FILE_EXT}'
PYTHON_PATH = BIN_PATH / f'python3{FILE_EXT}'
PIP_PATH = BIN_PATH / f'pip{FILE_EXT}'
PIP_SYNC_PATH = BIN_PATH / f'pip-sync{FILE_EXT}'

Expand Down Expand Up @@ -105,6 +105,10 @@ 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')
verbose_check_call(PYTHON_PATH, '-m', 'pre_commit', 'autoupdate')

# Call our entry point CLI:
try:
verbose_check_call(PROJECT_SHELL_SCRIPT, *argv[1:])
Expand Down
27 changes: 27 additions & 0 deletions manageprojects/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 manageprojects.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)
23 changes: 8 additions & 15 deletions manageprojects/cli_dev/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
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.cli_dev import PACKAGE_ROOT, cli
from manageprojects.utilities.publish import publish_package
Expand All @@ -18,23 +21,13 @@ def install():
verbose_check_call('pip', 'install', '--no-deps', '-e', '.')


def _run_safety():
verbose_check_call(
'safety',
'check',
'-r',
'requirements.dev.txt',
'--ignore',
'70612', # Ignore CVE-2019-8341: Jinja2 Server Side Template Injection (SSTI)
)


@cli.command()
def safety():
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def pip_audit(verbosity: int):
"""
Run safety check against current requirements files
Run pip-audit check against current requirements files
"""
_run_safety()
run_pip_audit(base_path=PACKAGE_ROOT, verbosity=verbosity)


@cli.command()
Expand Down Expand Up @@ -79,7 +72,7 @@ def update():
extra_env=extra_env,
)

_run_safety()
run_pip_audit(base_path=PACKAGE_ROOT)

# Install new dependencies in current .venv:
verbose_check_call(bin_path / 'pip-sync', 'requirements.dev.txt')
Expand Down
20 changes: 11 additions & 9 deletions manageprojects/tests/test_format_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@


class FormatFileTestCase(TestCase):
maxDiff = None

def test_get_git_info(self):
with AssertLogs(self, loggers=('cli_base',)):
git_info = get_git_info(file_path=Path(__file__))
Expand Down Expand Up @@ -113,8 +115,8 @@ def test_get_pyproject_info(self):
get_pyproject_info(file_path=Path(__file__), default_min_py_version='3.7'),
PyProjectInfo(
pyproject_toml_path=PACKAGE_ROOT / 'pyproject.toml',
py_min_ver=Version('3.9'),
raw_py_ver_req='>=3.9',
py_min_ver=Version('3.11'),
raw_py_ver_req='>=3.11',
),
)

Expand All @@ -133,8 +135,8 @@ def test_get_config(self):
git_info=GitInfo(cwd=PACKAGE_ROOT, main_branch_name='main'),
pyproject_info=PyProjectInfo(
pyproject_toml_path=PACKAGE_ROOT / 'pyproject.toml',
py_min_ver=Version('3.9'),
raw_py_ver_req='>=3.9',
py_min_ver=Version('3.11'),
raw_py_ver_req='>=3.11',
),
max_line_length=119,
),
Expand Down Expand Up @@ -174,7 +176,7 @@ def test_format_one_file(self):
[
'.../pyupgrade',
'--exit-zero-even-if-changed',
'--py39-plus',
'--py311-plus',
'manageprojects/tests/test_format_file.py',
],
[
Expand Down Expand Up @@ -202,7 +204,7 @@ def test_format_one_file(self):
'--line-length',
'119',
'--target-version',
'py39',
'py311',
'manageprojects/tests/test_format_file.py',
],
['.../flake8', '--max-line-length', '119', 'manageprojects/tests/test_format_file.py'],
Expand All @@ -216,7 +218,7 @@ def test_format_one_file(self):
'--allow-redefinition',
'manageprojects/tests/test_format_file.py',
],
['.../refurb', '--python-version', '3.9', 'manageprojects/tests/test_format_file.py'],
['.../refurb', '--python-version', '3.11', 'manageprojects/tests/test_format_file.py'],
],
)

Expand All @@ -240,7 +242,7 @@ def test_format_one_file(self):
[
'.../pyupgrade',
'--exit-zero-even-if-changed',
'--py39-plus',
'--py311-plus',
'manageprojects/tests/test_format_file.py',
],
['.../autoflake', '--in-place', 'manageprojects/tests/test_format_file.py'],
Expand All @@ -265,6 +267,6 @@ def test_format_one_file(self):
'--allow-redefinition',
'manageprojects/tests/test_format_file.py',
],
['.../refurb', '--python-version', '3.9', 'manageprojects/tests/test_format_file.py'],
['.../refurb', '--python-version', '3.11', 'manageprojects/tests/test_format_file.py'],
],
)
21 changes: 14 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "README.md"
authors = [
{name = 'Jens Diemer', email = 'mamageprojects@jensdiemer.de'}
]
requires-python = ">=3.9"
requires-python = ">=3.11"
dependencies = [
"cookiecutter>=2.4.0", # https://github.com/cookiecutter/cookiecutter
"tomlkit",
Expand Down Expand Up @@ -47,7 +47,7 @@ dev = [
"pyflakes", # https://github.com/PyCQA/pyflakes
"codespell", # https://github.com/codespell-project/codespell
"EditorConfig", # https://github.com/editorconfig/editorconfig-core-py
"safety", # https://github.com/pyupio/safety
"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
Expand All @@ -59,11 +59,9 @@ dev = [
# https://github.com/pygments/pygments
"darker[flynt, isort, color]",

"tomli", # https://github.com/hukkin/tomli
#
# tomli only needed for Python <3.11, but see pip bug:
# https://github.com/pypa/pip/issues/9644 / https://github.com/jazzband/pip-tools/issues/1866
#'tomli;python_version<"3.11"', # https://github.com/hukkin/tomli
# Work-a-round for:
# https://github.com/jazzband/pip-tools/issues/994
"backports.tarfile",
]

[project.urls]
Expand All @@ -86,6 +84,14 @@ include = ["manageprojects*"]
version = {attr = "manageprojects.__version__"}


[tool.cli_base.pip_audit]
# https://github.com/jedie/cli-base-utilities/blob/main/docs/pip_audit.md
requirements=["requirements.dev.txt"]
strict=true
require_hashes=true
ignore-vuln=[]


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

Expand Down Expand Up @@ -186,6 +192,7 @@ applied_migrations = [
"c538ae7", # 2023-12-21T20:21:58+01:00
"7271d4c", # 2023-12-29T21:57:47+01:00
"f8be3e0", # 2024-07-16T19:35:26+02:00
"2cdc1d8", # 2024-08-25T19:00:41+02:00
]

[manageprojects.cookiecutter_context.cookiecutter]
Expand Down
Loading

0 comments on commit 0671a08

Please sign in to comment.