Skip to content

Commit de7b355

Browse files
colyerdengShawnDen-coder
authored andcommitted
feat: check template var to raw string
1 parent 990eab4 commit de7b355

File tree

11 files changed

+54
-185
lines changed

11 files changed

+54
-185
lines changed

.yamlfmt.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ yaml_files:
44
- ".yamlfmt"
55
- "!**/vendor/**"
66
- "!**/node_modules/**"
7+
regex_exclude:
8+
- ".*\\Taskfile\\.yml$"
9+
- ".*\\mkdocs\\.yml$"
710
yaml_options:
811
# 文档末尾是否需要一个空行
912
end_of_document: true

mkdocs.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ site_author: ShawnDen-coder
66
edit_uri: edit/main/docs/
77
repo_name: ShawnDen-coder/repo-scaffold
88
copyright: Maintained by <a href="https://github.com/ShawnDen-coder">ShawnDen-coder</a>.
9-
109
nav:
1110
- Home: index.md
1211
- API Reference: reference/
13-
1412
plugins:
1513
- search
1614
- gen-files:
@@ -33,7 +31,6 @@ plugins:
3331
merge_init_into_class: true
3432
docstring_section_style: "spacy"
3533
show_if_no_docstring: false
36-
3734
theme:
3835
name: material
3936
palette:
@@ -60,7 +57,6 @@ theme:
6057
- search.share
6158
- search.suggest
6259
- content.code.copy
63-
6460
markdown_extensions:
6561
- admonition
6662
- pymdownx.details
@@ -76,7 +72,6 @@ markdown_extensions:
7672
- tables
7773
- toc:
7874
permalink: true
79-
8075
extra:
8176
social:
8277
- icon: fontawesome/brands/github

pyproject.toml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ dependencies = [
1717
[project.optional-dependencies]
1818
dev = [
1919
"ruff>=0.9.7",
20-
"nox>=2024.10.9",
2120
"pytest>=8.3.4",
2221
"pytest-mock>=3.14.0",
2322
"pytest-cov>=6.0.0",
@@ -43,45 +42,3 @@ repo_scaffold = ["templates/**/*", "cookiecutter.json"]
4342
[build-system]
4443
requires = ["hatchling"]
4544
build-backend = "hatchling.build"
46-
47-
[tool.ruff]
48-
line-length = 120
49-
include = ["pyproject.toml", "repo_scaffold/*.py"]
50-
exclude = ["repo_scaffold/templates/**/*"]
51-
52-
[tool.ruff.lint]
53-
select = [
54-
"E", # pycodestyle errors
55-
"W", # pycodestyle warnings
56-
"F", # pyflakes
57-
"I", # isort
58-
"B", # flake8-bugbear
59-
"C4", # flake8-comprehensions
60-
"D" # pydocstyle
61-
]
62-
63-
ignore = [
64-
"W191", # indentation contains tabs
65-
"D401" # imperative mood
66-
]
67-
68-
extend-ignore = [
69-
"D100", # Missing docstring in public module
70-
"D104", # Missing docstring in public package
71-
]
72-
73-
[tool.ruff.lint.isort]
74-
force-single-line = true
75-
lines-after-imports = 2
76-
77-
[tool.ruff.lint.pydocstyle]
78-
convention = "google"
79-
80-
81-
[tool.commitizen]
82-
name = "cz_conventional_commits"
83-
tag_format = "$version"
84-
version_scheme = "semver2"
85-
version_provider = "pep621"
86-
update_changelog_on_bump = true
87-
major_version_zero = true

repo_scaffold/cli.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import os
3030
from pathlib import Path
3131
from typing import Any
32-
from typing import Dict
3332

3433
import click
3534
from cookiecutter.main import cookiecutter
@@ -43,7 +42,7 @@ def get_package_path(relative_path: str) -> str:
4342
4443
Returns:
4544
str: Absolute path to the resource
46-
""" # noqa: W293
45+
"""
4746
# 使用 files() 获取包资源
4847
package_files = importlib.resources.files("repo_scaffold")
4948
resource_path = package_files.joinpath(relative_path)
@@ -52,7 +51,7 @@ def get_package_path(relative_path: str) -> str:
5251
return str(resource_path)
5352

5453

55-
def load_templates() -> Dict[str, Any]:
54+
def load_templates() -> dict[str, Any]:
5655
"""Load available project templates configuration.
5756
5857
Reads template configurations from the cookiecutter.json file in the templates directory.
@@ -74,7 +73,7 @@ def load_templates() -> Dict[str, Any]:
7473
json.JSONDecodeError: If the configuration file is not valid JSON
7574
"""
7675
config_path = get_package_path("templates/cookiecutter.json")
77-
with open(config_path, "r", encoding="utf-8") as f:
76+
with open(config_path, encoding="utf-8") as f:
7877
config = json.load(f)
7978
return config["templates"]
8079

@@ -104,7 +103,7 @@ def list():
104103
python - template-python
105104
Description: template for python project
106105
```
107-
""" # noqa: W293
106+
"""
108107
templates = load_templates()
109108
click.echo("\nAvailable templates:")
110109
for name, info in templates.items():
@@ -147,10 +146,10 @@ def create(template: str, output_dir: Path):
147146
```bash
148147
$ repo-scaffold list
149148
```
150-
""" # noqa: W293
149+
"""
151150
templates = load_templates()
152151

153-
# 如果没有指定模板让 cookiecutter 处理模板选择
152+
# 如果没有指定模板,让 cookiecutter 处理模板选择
154153
if not template:
155154
click.echo("Please select a template to use:")
156155
for name, info in templates.items():
@@ -177,7 +176,7 @@ def create(template: str, output_dir: Path):
177176
cookiecutter(
178177
template=template_path,
179178
output_dir=str(output_dir),
180-
no_input=False, # 启用交互式输入让 cookiecutter 处理所有选项
179+
no_input=False, # 启用交互式输入,让 cookiecutter 处理所有选项
181180
)
182181

183182

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/bump_version.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ permissions:
99
pull-requests: write # 用于创建 PR
1010
jobs:
1111
bump-version:
12-
if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }}
12+
if: {% raw %}${{ !startsWith(github.event.head_commit.message, 'bump:') }}{% endraw %}
1313
runs-on: ubuntu-latest
1414
name: Bump version and create changelog with commitizen
1515
steps:
1616
- name: Check out
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20-
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
20+
token: {% raw %}${{ secrets.PERSONAL_ACCESS_TOKEN }}{% endraw %}
2121
- name: Create bump and changelog
2222
uses: commitizen-tools/commitizen-action@master
2323
with:
24-
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
24+
github_token: {% raw %}${{ secrets.PERSONAL_ACCESS_TOKEN }}{% endraw %}
2525
branch: master

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/deploy_docs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
- name: Build and deploy documentation
2020
run: task deploy:gh-pages
2121
env:
22-
GITHUB_TOKEN: ${{ github.token }}
22+
GITHUB_TOKEN: {% raw %}${{ github.token }}{% endraw %}

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/docker_release.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
- name: Login to Docker Hub
1717
uses: docker/login-action@v3
1818
with:
19-
username: ${{ secrets.DOCKERHUB_USERNAME }}
20-
password: ${{ secrets.DOCKERHUB_TOKEN }}
19+
username: {% raw %}${{ secrets.DOCKERHUB_USERNAME }}{% endraw %}
20+
password: {% raw %}${{ secrets.DOCKERHUB_TOKEN }}{% endraw %}
2121
- name: Login to GitHub Container Registry
2222
uses: docker/login-action@v3
2323
with:
2424
registry: ghcr.io
25-
username: ${{ github.actor }}
26-
password: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
25+
username: {% raw %}${{ github.actor }}{% endraw %}
26+
password: {% raw %}${{ secrets.PERSONAL_ACCESS_TOKEN }}{% endraw %}
2727
- name: Set up QEMU
2828
uses: docker/setup-qemu-action@v3
2929
- name: Set up Docker Buildx
@@ -33,10 +33,10 @@ jobs:
3333
uses: docker/metadata-action@v5
3434
with:
3535
images: |
36-
${{ env.DOCKERHUB_IMAGE_NAME }}
37-
${{ env.GITHUB_IMAGE_NAME }}
36+
{% raw %}${{ env.DOCKERHUB_IMAGE_NAME }}{% endraw %}
37+
{% raw %}${{ env.GITHUB_IMAGE_NAME }}{% endraw %}
3838
tags: |
39-
type=raw,value=latest,enable={{is_default_branch}}
39+
{% raw %}type=raw,value=latest,enable={{is_default_branch}}{% endraw %}
4040
type=ref,event=tag
4141
type=ref,event=pr
4242
type=sha,format=short
@@ -47,5 +47,5 @@ jobs:
4747
file: ./docker/Dockerfile
4848
platforms: linux/amd64,linux/arm64
4949
push: true
50-
tags: ${{ steps.meta.outputs.tags }}
51-
labels: ${{ steps.meta.outputs.labels }}
50+
tags: {% raw %}${{ steps.meta.outputs.tags }}{% endraw %}
51+
labels: {% raw %}${{ steps.meta.outputs.labels }}{% endraw %}

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/.github/workflows/release_build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
task test:all # 运行所有测试
2525
- name: Publish to PyPI
2626
env:
27-
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
27+
UV_PUBLISH_TOKEN: {% raw %}${{ secrets.PYPI_TOKEN }}{% endraw %}
2828
run: task deploy:pypi
2929
- name: Release
3030
uses: softprops/action-gh-release@v2
@@ -34,4 +34,4 @@ jobs:
3434
dist/*.whl
3535
generate_release_notes: true
3636
env:
37-
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
37+
GITHUB_TOKEN: {% raw %}${{ secrets.PERSONAL_ACCESS_TOKEN }}{% endraw %}

repo_scaffold/templates/template-python/{{cookiecutter.project_slug}}/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
site_name: {{cookiecutter.project_slug}}
1+
site_name: '{{cookiecutter.project_slug}}'
22
repo_url: https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}
33
site_url: https://{{cookiecutter.github_username}}.github.io/{{cookiecutter.project_slug}}
44
site_description: {{cookiecutter.description}}

tests/test_import.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
import repo_scaffold
77

8+
89
def test_imports():
910
"""Test import modules."""
10-
prefix = "{}.".format(repo_scaffold.__name__) # noqa
11+
prefix = "{}.".format(repo_scaffold.__name__) # noqa
1112
iter_packages = pkgutil.walk_packages(
12-
repo_scaffold.__path__, # noqa
13+
repo_scaffold.__path__,
1314
prefix,
1415
)
1516
for _, name, _ in iter_packages:
1617
module_name = name if name.startswith(prefix) else prefix + name
17-
importlib.import_module(module_name)
18+
importlib.import_module(module_name)

0 commit comments

Comments
 (0)