diff --git a/.github/workflows/build.yaml b/.github/workflows/release-build.yaml similarity index 79% rename from .github/workflows/build.yaml rename to .github/workflows/release-build.yaml index 857bbb4..82448c4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/release-build.yaml @@ -17,13 +17,14 @@ jobs: with: poetry-version: "latest" - - name: install-poetry-plugins + - name: setup-pypi run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} poetry self add poetry-pyinstaller-plugin poetry self add poetry-plugin-taskipy - name: build - run: poetry build + run: poetry publish --build - name: Release uses: softprops/action-gh-release@v2 @@ -34,4 +35,4 @@ jobs: dist/*.whl generate_release_notes: true env: - GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index 2154e57..364d8ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "repo-template" +name = "repo-scaffold" version = "0.1.0" description = "shawn deng repo temple project" authors = ["colyerdeng "] @@ -18,11 +18,11 @@ pre-commit = "^4.0.1" commitizen = "^4.1.0" [tool.poetry.scripts] -repo-template = "repo_template.cli:cli" +repo-scaffold = "repo_scaffold.cli:cli" [tool.ruff] line-length = 120 -include = ["pyproject.toml", "{{template-python}}/{{cookiecutter.project_slug}}/*.py"] +include = ["pyproject.toml", "repo_scaffold/*.py"] [tool.ruff.lint] select = [ diff --git a/repo_scaffold/__init__.py b/repo_scaffold/__init__.py new file mode 100644 index 0000000..7097b4e --- /dev/null +++ b/repo_scaffold/__init__.py @@ -0,0 +1,18 @@ +"""Repository scaffolding package for project initialization and setup. + +This package provides tools and utilities for scaffolding new Python projects +with standardized structure and best practices. It serves as the main entry point +for the repo_scaffold package functionality. + +Typical usage example: + + import repo_scaffold + + scaffold = repo_scaffold.create_project() + scaffold.setup_structure() + +Attributes: + __author__: Package author information. +""" + +__author__ = "Shawn Deng" diff --git a/repo_scaffold/cli.py b/repo_scaffold/cli.py new file mode 100644 index 0000000..f36d598 --- /dev/null +++ b/repo_scaffold/cli.py @@ -0,0 +1,65 @@ +"""Command Line Interface module for project scaffolding. + +This module provides the CLI commands for creating new projects using cookiecutter +templates. It serves as the main entry point for the repo_scaffold tool and handles +all command-line interactions. + +Typical usage example: + + from repo_scaffold.cli import cli + + if __name__ == '__main__': + cli() + +Attributes: + cli: The main Click command group that serves as the entry point. +""" + +import os + +import click +from cookiecutter.main import cookiecutter + + +@click.group() +def cli(): + """CLI tool for project creation. + + This function serves as the main command group for the CLI application. + It groups all subcommands and provides the base entry point for the tool. + """ + ... + + +@cli.command() +@click.option( + "--template", + "-t", + default="https://github.com/ShawnDen-coder/repo-template.git", + help="Cookiecutter template URL or path", +) +@click.option("--output-dir", "-o", default=".", help="Where to output the generated project dir") +@click.option("--local", "-l", is_flag=True, help="Use local template in ./template-python") +def create(template, output_dir, local): + """Create a new project from a Cookiecutter template. + + Args: + template (str): URL or path to the cookiecutter template. + output_dir (str): Directory where the generated project will be created. + local (bool): Flag to use local template instead of remote. + + Returns: + None + + Example: + $ repo_scaffold create --template https://github.com/user/template.git + $ repo_scaffold create --local --output-dir ./projects + """ + if local: + template = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) + + cookiecutter(template=template, output_dir=output_dir, no_input=False) + + +if __name__ == "__main__": + cli() diff --git a/repo_scaffold/utils.py b/repo_scaffold/utils.py new file mode 100644 index 0000000..d7fdf4a --- /dev/null +++ b/repo_scaffold/utils.py @@ -0,0 +1,17 @@ +"""Utility functions module for common operations. + +This module contains reusable utility functions that can be used across the application. +It provides helper methods, convenience functions, and shared functionality to promote +code reuse and maintainability. + +Typical usage example: + + from repo_scaffold.utils import validate_input, format_output + + cleaned_data = validate_input(raw_data) + result = format_output(cleaned_data) + +Note: + All utility functions should be stateless and follow single responsibility principle. + New utility functions should be well documented with type hints and docstrings. +""" diff --git a/repo_template/__init__.py b/repo_template/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/repo_template/cli.py b/repo_template/cli.py deleted file mode 100644 index 872004f..0000000 --- a/repo_template/cli.py +++ /dev/null @@ -1,31 +0,0 @@ -import os - -import click -from cookiecutter.main import cookiecutter - - -@click.group() -def cli(): - """CLI tool for project creation""" - ... - - -@cli.command() -@click.option('--template', '-t', default='https://github.com/ShawnDen-coder/repo-template.git', - help='Cookiecutter template URL or path') -@click.option('--output-dir', '-o', default='.', help='Where to output the generated project dir') -@click.option('--local', '-l', is_flag=True, help='Use local template in ./template-python') -def create(template, output_dir, local): - """Create a new project from a Cookiecutter template""" - if local: - template = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) - - cookiecutter( - template=template, - output_dir=output_dir, - no_input=False - ) - - -if __name__ == '__main__': - cli() diff --git a/repo_template/utils.py b/repo_template/utils.py deleted file mode 100644 index e69de29..0000000 diff --git a/template-python/cookiecutter.json b/template-python/cookiecutter.json index d4c123a..ffe1fd5 100644 --- a/template-python/cookiecutter.json +++ b/template-python/cookiecutter.json @@ -4,18 +4,8 @@ "email": "shawndeng1109@qq.com", "project_slug": "{{ cookiecutter.repo_name.strip().lower().replace('-', '_') }}", "description": "A short description of the project.", - "include_cli": { - "__prompt__": "Include CLI interface? (y/n)", - "__choices__": [ - "y", - "n" - ] - }, - "create_github_repo": { - "__prompt__": "Create GitHub repo? Requires ~/.github/config.json with GitHub token (y/n)", - "__choices__": [ - "y", - "n" - ] - } + "include_cli": [ + "y", + "n" + ] } diff --git a/template-python/{{cookiecutter.project_slug}}/.github/workflows/bumpversion.yaml b/template-python/{{cookiecutter.project_slug}}/.github/workflows/bumpversion.yaml new file mode 100644 index 0000000..bbc9c71 --- /dev/null +++ b/template-python/{{cookiecutter.project_slug}}/.github/workflows/bumpversion.yaml @@ -0,0 +1,24 @@ +name: Bump version + +on: + pull_request: + branches: + - master + workflow_dispatch: + +jobs: + bump-version: + if: "!startsWith(github.event.head_commit.message, 'bump:')" + runs-on: ubuntu-latest + name: "Bump version and create changelog with commitizen" + steps: + - name: Check out + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: '${{ secrets.GITHUB_TOKEN }}' + - name: Create bump and changelog + uses: commitizen-tools/commitizen-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master diff --git a/template-python/{{cookiecutter.project_slug}}/.github/workflows/release-build.yaml b/template-python/{{cookiecutter.project_slug}}/.github/workflows/release-build.yaml new file mode 100644 index 0000000..82448c4 --- /dev/null +++ b/template-python/{{cookiecutter.project_slug}}/.github/workflows/release-build.yaml @@ -0,0 +1,38 @@ +name: release-build +on: + push: + tags: + - '*.*.*' + workflow_dispatch: + +jobs: + release-build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - uses: abatilo/actions-poetry@v2 + with: + poetry-version: "latest" + + - name: setup-pypi + run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }} + poetry self add poetry-pyinstaller-plugin + poetry self add poetry-plugin-taskipy + + - name: build + run: poetry publish --build + + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + dist/**/*.exe + dist/*.tar.gz + dist/*.whl + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}