From 62388f9e213fbe15d241ff42d16d06ef32421bbf Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Sat, 10 Aug 2024 21:26:31 +0200 Subject: [PATCH 1/4] Set origin when creating git repo --- CHANGELOG.md | 6 +++++ README.md | 2 +- hooks/post_gen_project.py | 1 + .../.pre-commit-config.yaml | 6 ++--- {{cookiecutter.project_slug}}/mkdocs.yml | 6 ++--- {{cookiecutter.project_slug}}/pyproject.toml | 22 +++++++++---------- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dca3a6c..dbbe06e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Version 0.7 + +- Add: Let `git` set remote to the project repository during setup +- Fix: Setting `pymdownx.magiclink` in `mkdocs` correctly. +- Upd: Updated dependencies of environemnts + ## Version 0.6 - Fix: `PIP_COMPILE_UPGRADE_PACKAGE` instead of `PIP_COMPILE_UPGRADE` in `upgrade-pkg` hatch command diff --git a/README.md b/README.md index 4a946de..38c6463 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ The Hatchlor integrates the following features: * [pyproject.toml]: all package, build and tool configuration in one file, * [pytest]: full-featured Python testing tool that helps you write better programs, * [coverage]: tool for measuring code coverage of Python programs with pytest integration, -* [GitHub Actions]: workflows with [dependabot], [release-drafter], [labeler], build docs, test & publish to PYPI, +* [GitHub Actions]: workflows with [dependabot], [release-drafter], [labeler], build docs, test & publish to PyPI, * [ruff]: extremely fast Python linter/formatter, which replaces [isort], [flake8], [black], etc., * [mypy]: optional static type checker for Python, * [mkdocs]: a fast, simple and downright gorgeous static site generator, diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 3ae0904..ba8b457 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -4,6 +4,7 @@ subprocess.call(['git', 'init']) subprocess.call(['git', 'add', '*']) subprocess.call(['git', 'commit', '-m', 'Initial commit']) + subprocess.call(['git', 'remote', 'add', 'origin', '{{ project_repo }}']) except Exception as e: print(f"An error occurred during initializing the git repo: {e}") print("Makre sure to manually set up a git repository which is necessary for `hatch-vcs`") diff --git a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index 39a5ad4..87df95f 100644 --- a/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: check-added-large-files @@ -20,14 +20,14 @@ repos: # Ruff replaces black, flake8, autoflake, isort and more - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.4.4' # make sure this is always consistent with hatch configs + rev: 'v0.5.7' # make sure this is always consistent with hatch configs hooks: - id: ruff - id: ruff-format args: [--check, --config, ./pyproject.toml] - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v1.9.0' # make sure this is always consistent with hatch configs + rev: 'v1.11.1' # make sure this is always consistent with hatch configs hooks: - id: mypy args: ["--install-types", "--non-interactive"] diff --git a/{{cookiecutter.project_slug}}/mkdocs.yml b/{{cookiecutter.project_slug}}/mkdocs.yml index 00bec51..a73e1ad 100644 --- a/{{cookiecutter.project_slug}}/mkdocs.yml +++ b/{{cookiecutter.project_slug}}/mkdocs.yml @@ -132,9 +132,9 @@ markdown_extensions: social_url_shortener: true social_url_shorthand: true normalize_issue_symbols: true - provider: github - user: pypa - repo: hatch + provider: {{ cookiecutter.project_repo.split('/')[2].split('.')[-2] }} + user: {{ cookiecutter.project_repo.split('/')[-2] }} + repo: {{ cookiecutter.project_repo.split('/')[-1] }} - pymdownx.mark: - pymdownx.progressbar: - pymdownx.saneheaders: diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index ffa1a24..acf387c 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -217,7 +217,7 @@ ban-relative-imports = "all" {%- if cookiecutter.lock_file_support %} [tool.hatch.env] -requires = ["hatch-pip-compile~=1.11.1"] +requires = ["hatch-pip-compile~=1.11.2"] {%- endif %} # Default environment with production dependencies @@ -263,25 +263,25 @@ debug = "cov --no-cov -s --pdb --pdbcls=IPython.core.debugger:Pdb {args}" # Docs environment [tool.hatch.envs.docs] dependencies = [ - "mkdocs~=1.5", + "mkdocs~=1.6", "mkdocs-material[imaging]~=9.4", # Plugins "mkdocs-include-markdown-plugin", "mkdocs-gen-files", "mkdocs-literate-nav", - "mkdocs-minify-plugin~=0.5", + "mkdocs-minify-plugin~=0.8", "mkdocs-section-index", - "mkdocs-git-revision-date-localized-plugin~=1.1", + "mkdocs-git-revision-date-localized-plugin~=1.2", "mkdocstrings[python]", "mkdocs-redirects~=1.2", - "mkdocs-glightbox~=0.3.0", - "mike~=2.0.0", + "mkdocs-glightbox~=0.4.0", + "mike~=2.1", # Extensions - "pymdown-extensions~=10.5", + "pymdown-extensions~=10.9", # Necessary for syntax highlighting in code blocks - "pygments~=2.13", + "pygments~=2.18", # Validation - "linkchecker~=10.3", + "linkchecker~=10.4", ] [tool.hatch.envs.docs.env-vars] SOURCE_DATE_EPOCH = "1580601600" @@ -303,8 +303,8 @@ build-check = [ [tool.hatch.envs.lint] template = "lint" # don't inherit from default! dependencies = [ - "mypy==1.10.0", - "ruff==0.4.4", + "mypy==1.11.1", + "ruff==0.5.7", ] [tool.hatch.envs.lint.scripts] typing = [ From b55574f6f19bdae1027309c51ae29d6f0a70b6fd Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Sat, 10 Aug 2024 21:32:12 +0200 Subject: [PATCH 2/4] Fix cookiecutter post_gen_project.py --- .pre-commit-config.yaml | 16 ++++++++++++++++ hooks/post_gen_project.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..dd15b37 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,16 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: check-added-large-files + - id: check-ast + - id: check-json + - id: check-merge-conflict + - id: check-xml + - id: check-yaml + args: ['--unsafe'] # needed for !! tags in mkdocs.yml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index ba8b457..2cb1907 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -4,7 +4,7 @@ subprocess.call(['git', 'init']) subprocess.call(['git', 'add', '*']) subprocess.call(['git', 'commit', '-m', 'Initial commit']) - subprocess.call(['git', 'remote', 'add', 'origin', '{{ project_repo }}']) + subprocess.call(['git', 'remote', 'add', 'origin', '{{ cookiecutter.project_repo }}']) except Exception as e: print(f"An error occurred during initializing the git repo: {e}") print("Makre sure to manually set up a git repository which is necessary for `hatch-vcs`") From b25813eb5119e250fc8041b2766aee5140451bfd Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Sat, 10 Aug 2024 21:46:33 +0200 Subject: [PATCH 3/4] Make settings mkdocs magiclink more robust --- {{cookiecutter.project_slug}}/mkdocs.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/mkdocs.yml b/{{cookiecutter.project_slug}}/mkdocs.yml index a73e1ad..7ea1097 100644 --- a/{{cookiecutter.project_slug}}/mkdocs.yml +++ b/{{cookiecutter.project_slug}}/mkdocs.yml @@ -132,9 +132,11 @@ markdown_extensions: social_url_shortener: true social_url_shorthand: true normalize_issue_symbols: true - provider: {{ cookiecutter.project_repo.split('/')[2].split('.')[-2] }} - user: {{ cookiecutter.project_repo.split('/')[-2] }} - repo: {{ cookiecutter.project_repo.split('/')[-1] }} + {% set parts = cookiecutter.project_repo.split('/') -%} + {% set domain_parts = parts.split('.') if parts|length > 2 else [] -%} + provider: {{ domain_parts[-2] if domain_parts|length > 2 else 'github' }} + user: {{ parts[-2] if parts|length > 2 else cookiecutter.github_username }} + repo: {{ parts[-1] if parts|length > 2 else cookiecutter.project_slug }} - pymdownx.mark: - pymdownx.progressbar: - pymdownx.saneheaders: From 6d5dc4f1da4d2e7f206a328d8a005df8d49443f3 Mon Sep 17 00:00:00 2001 From: Florian Wilhelm Date: Sat, 10 Aug 2024 21:54:16 +0200 Subject: [PATCH 4/4] Fix mkdocs jinja2 script again --- {{cookiecutter.project_slug}}/mkdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/mkdocs.yml b/{{cookiecutter.project_slug}}/mkdocs.yml index 7ea1097..0379659 100644 --- a/{{cookiecutter.project_slug}}/mkdocs.yml +++ b/{{cookiecutter.project_slug}}/mkdocs.yml @@ -133,7 +133,7 @@ markdown_extensions: social_url_shorthand: true normalize_issue_symbols: true {% set parts = cookiecutter.project_repo.split('/') -%} - {% set domain_parts = parts.split('.') if parts|length > 2 else [] -%} + {% set domain_parts = parts[-3].split('.') if parts|length > 2 else [] -%} provider: {{ domain_parts[-2] if domain_parts|length > 2 else 'github' }} user: {{ parts[-2] if parts|length > 2 else cookiecutter.github_username }} repo: {{ parts[-1] if parts|length > 2 else cookiecutter.project_slug }}