diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..9593491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Report a bug or unexpected behavior +title: '[BUG] ' +labels: bug +assignees: '' +--- + +## Describe the Bug + + + +## Steps to Reproduce + +1. +2. +3. + +## Expected Behavior + + + +## Actual Behavior + + + +## Environment + +- OS: +- Python version: +- Package version: + +## Additional Context + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..77a5c85 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,27 @@ +--- +name: Feature request +about: Suggest a new feature or enhancement +title: '[FEAT] ' +labels: enhancement +assignees: '' +--- + +## Summary + + + +## Motivation + + + +## Proposed Solution + + + +## Alternatives Considered + + + +## Additional Context + + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d85087b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,22 @@ +## Description + + + +## Type of Change + +- [ ] Bug fix +- [ ] New feature +- [ ] Documentation update +- [ ] Refactor / code cleanup +- [ ] Other (describe below) + +## Related Issue + +Closes # + +## Checklist + +- [ ] My changes follow the project's code style +- [ ] I have added or updated relevant tests +- [ ] I have updated documentation (README, CHANGELOG, etc.) where applicable +- [ ] All existing tests pass locally diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1bec606 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,58 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.2.0] - 2026-05-31 + +### Added +- Python build system (`pybuild`) — a Gradle-inspired task runner +- `PYTHON_BUILD_FEATURES.md` documenting the full Gradle → pybuild feature mapping +- Task dependency DAG resolution with cycle detection +- `@task` decorator and function-call DSL for defining tasks +- `--list`, `--quiet`, and `-f` CLI flags for `pybuild` +- Custom exceptions: `TaskNotFoundError`, `CyclicDependencyError`, `TaskExecutionError` + +### Changed +- Updated project structure and documentation + +## [0.1.4] - 2025-01-01 + +### Changed +- Bumped version to 0.1.4 +- Updated GitHub Actions workflows + +## [0.1.3] - 2025-01-01 + +### Changed +- Reverted version number to 0.1.3 +- Removed GitHub Packages workflow; kept PyPI publish path only + +## [0.1.2] - 2025-01-01 + +### Added +- GitHub Packages publish setup and workflow + +## [0.1.1] - 2025-01-01 + +### Changed +- Replaced MIT License with GNU General Public License v3 + +## [0.1.0] - 2025-01-01 + +### Added +- Initial release +- CLI scaffolding tool (`auto-gen-py-project`) +- Generates `src/`, tests, `run.py`, `pyproject.toml`, `.gitignore`, `LICENSE`, `.venv`, and `build.py` + +[Unreleased]: https://github.com/axcel-blade/auto-gen-py-project/compare/v0.2.0...HEAD +[0.2.0]: https://github.com/axcel-blade/auto-gen-py-project/compare/v0.1.4...v0.2.0 +[0.1.4]: https://github.com/axcel-blade/auto-gen-py-project/compare/v0.1.3...v0.1.4 +[0.1.3]: https://github.com/axcel-blade/auto-gen-py-project/compare/v0.1.2...v0.1.3 +[0.1.2]: https://github.com/axcel-blade/auto-gen-py-project/compare/v0.1.1...v0.1.2 +[0.1.1]: https://github.com/axcel-blade/auto-gen-py-project/compare/v0.1.0...v0.1.1 +[0.1.0]: https://github.com/axcel-blade/auto-gen-py-project/releases/tag/v0.1.0 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..019d6df --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,35 @@ +# Code of Conduct + +## Our Pledge + +We as contributors and maintainers pledge to make participation in this project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to a positive environment: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior: + +- The use of sexualized language or imagery and unwelcome sexual attention or advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer at **srikanthfernando3@gmail.com**. All complaints will be reviewed and investigated and will result in a response deemed necessary and appropriate to the circumstances. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1. diff --git a/LICENSE b/LICENSE index 7a3b7c2..0ad25db 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies @@ -7,17 +7,15 @@ Preamble - The GNU General Public License is a free, copyleft license for -software and other kinds of works. + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to +our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. +software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you @@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. The precise terms and conditions for copying, distribution and modification follow. @@ -72,7 +60,7 @@ modification follow. 0. Definitions. - "This License" refers to version 3 of the GNU General Public License. + "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. @@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. - 13. Use with the GNU Affero General Public License. + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single +under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General +Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published +GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's +versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. @@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + GNU Affero General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see +For more information on this, and how to apply and follow the GNU AGPL, see . - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. \ No newline at end of file diff --git a/PYTHON_BUILD_FEATURES.md b/PYTHON_BUILD_FEATURES.md new file mode 100644 index 0000000..a4b5f5c --- /dev/null +++ b/PYTHON_BUILD_FEATURES.md @@ -0,0 +1,622 @@ +# Python Build System Features + +A mapping of Gradle's core build features to their Python equivalents, with a focus on how this project's `pybuild` task runner implements them. + +--- + +## 1. Dependency Management + +Python manages dependencies through `pip` and `pyproject.toml`. + +- `pip` downloads and installs packages from PyPI automatically. +- `pyproject.toml` declares all project dependencies in one place. +- Transitive dependencies are resolved and installed automatically. +- `pip-tools`, `Poetry`, or `uv` can lock exact versions for reproducibility. + +### Example + +```toml +# pyproject.toml +[project] +dependencies = [ + "requests>=2.28", + "click>=8.0", +] + +[project.optional-dependencies] +dev = ["pytest", "coverage"] +``` + +```bash +# Install all dependencies +pip install . + +# Install with dev extras +pip install ".[dev]" +``` + +--- + +## 2. Build Automation + +`pybuild` is this project's Gradle-inspired task runner. It automates common development tasks via a `build.py` file. + +Common automated tasks: + +- `clean` — remove build artefacts +- `lint` — run code style checks +- `test` — run the test suite +- `build` — package the project +- `publish` — upload to PyPI + +### Example + +```python +# build.py +import shutil +import subprocess +from auto_gen_py_project.build_system import task + +@task +def clean(): + """Remove build artefacts.""" + shutil.rmtree("dist", ignore_errors=True) + shutil.rmtree("build", ignore_errors=True) + +@task(depends_on=["clean"]) +def test(): + """Run the test suite.""" + subprocess.run(["pytest", "-v"], check=True) + +@task(depends_on=["test"]) +def build(): + """Build wheel and sdist.""" + subprocess.run(["python", "-m", "build"], check=True) +``` + +```bash +pybuild build # runs: clean → test → build +pybuild --list # list all available tasks +``` + +--- + +## 3. Incremental Builds + +`pybuild` uses a DAG (directed acyclic graph) of task dependencies to execute only what is needed. + +- Tasks run in topological order. +- Skipped tasks are not re-executed in the same run. +- Tools like `watchfiles` or `pytest-watch` enable file-change-triggered re-runs. + +### Example + +```bash +# Only the test task and its dependencies run — not build +pybuild test +``` + +--- + +## 4. Build Cache + +Python tools support caching at multiple levels: + +- `functools.lru_cache` / `functools.cache` — in-memory function-level caching. +- `joblib.Memory` — disk-based result caching for expensive computations. +- `pip` caches downloaded wheels in `~/.cache/pip`. +- GitHub Actions caches the `pip` cache between CI runs for faster builds. + +### Example + +```python +# Cache expensive computation results +from functools import cache + +@cache +def expensive_step(): + # result is cached for repeated calls in the same process + ... +``` + +```yaml +# GitHub Actions pip cache +- uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} +``` + +--- + +## 5. Multi-Project Builds + +Large Python monorepos can host multiple packages, each with its own `pyproject.toml`. + +- `pybuild` tasks can be chained across sub-projects by calling `subprocess.run`. +- Tools like `Hatch`, `Poetry`, or `uv workspaces` provide workspace-level management. + +### Example + +``` +monorepo/ +├── packages/ +│ ├── core/ +│ │ └── pyproject.toml +│ └── api/ +│ └── pyproject.toml +└── build.py ← orchestrates all sub-projects +``` + +```python +# build.py — root-level orchestration +@task +def test_all(): + for pkg in ["packages/core", "packages/api"]: + subprocess.run(["pybuild", "test"], cwd=pkg, check=True) +``` + +--- + +## 6. Plugin System + +`pybuild` is extended by defining custom task functions in `build.py`. + +- Any Python function decorated with `@task` becomes a first-class build step. +- Shared task libraries can be imported from internal packages. +- `setuptools` entry points allow third-party CLI plugins. + +### Common Tool Plugins + +| Tool | Purpose | +|---|---| +| `pytest` | Test execution | +| `coverage` | Code coverage | +| `black` | Code formatting | +| `ruff` | Linting and style | +| `mypy` | Static type checking | +| `twine` | Package publishing | +| `sphinx` | Documentation generation | + +### Example + +```python +# build.py — custom lint plugin-style task +@task(depends_on=["clean"]) +def lint(): + """Run ruff and mypy.""" + subprocess.run(["ruff", "check", "src/"], check=True) + subprocess.run(["mypy", "src/"], check=True) +``` + +--- + +## 7. Task-Based Architecture + +Everything in `pybuild` is a task. Tasks can depend on other tasks, forming a DAG. + +| Gradle Task | pybuild Equivalent | +|---|---| +| `clean` | `pybuild clean` | +| `test` | `pybuild test` | +| `build` | `pybuild build` | +| `jar` | `pybuild build` (produces `.whl`) | +| `bootRun` | `pybuild run` | + +### Registration Styles + +```python +# Style 1 — bare decorator +@task +def clean(): ... + +# Style 2 — decorator with options +@task(depends_on=["clean"], description="Run tests") +def test(): ... + +# Style 3 — function-call DSL (Gradle-style) +task("build", depends_on=["test"], action=build_fn) +``` + +--- + +## 8. Python DSL (`build.py`) + +Where Gradle uses a Groovy DSL (`build.gradle`), `pybuild` uses plain Python (`build.py`). Python is more readable and requires no new language to learn. + +### Groovy (Gradle) + +```groovy +// build.gradle +task clean(type: Delete) { + delete buildDir +} +task test(dependsOn: clean) { + doLast { exec { commandLine 'pytest' } } +} +``` + +### Python (pybuild) + +```python +# build.py +@task +def clean(): + shutil.rmtree("dist", ignore_errors=True) + +@task(depends_on=["clean"]) +def test(): + subprocess.run(["pytest"], check=True) +``` + +--- + +## 9. Type-Annotated Build Scripts + +Where Gradle offers a Kotlin DSL for type safety, Python build scripts gain type safety through standard type annotations and `mypy`. + +```python +# build.py — fully typed +from collections.abc import Callable +from auto_gen_py_project.build_system import task + +@task(depends_on=["lint"]) +def test() -> None: + """Run pytest with coverage.""" + subprocess.run(["pytest", "--cov=src"], check=True) +``` + +--- + +## 10. Testing Support + +Python has a rich testing ecosystem. + +| Tool | Purpose | +|---|---| +| `pytest` | Test execution and discovery | +| `unittest` | Built-in standard library test framework | +| `coverage` | Code coverage measurement | +| `pytest-cov` | Coverage plugin for pytest | +| `hypothesis` | Property-based testing | +| `responses` / `httpretty` | HTTP mocking | +| `pytest-mock` | Mock integration | + +### Example + +```python +# tests/test_main.py +import pytest +from src.main import my_function + +def test_basic(): + assert my_function(2) == 4 + +@pytest.mark.parametrize("n,expected", [(1, 1), (3, 9)]) +def test_parametrized(n, expected): + assert my_function(n) == expected +``` + +```bash +pybuild test # run full suite via pybuild +pytest -v # run directly +pytest --cov=src -v # with coverage report +``` + +--- + +## 11. Continuous Integration Support + +This project ships CI/CD workflows for GitHub Actions out of the box. + +| Workflow | File | Trigger | +|---|---|---| +| CI | `.github/workflows/ci.yml` | Push to `develop`/`feature/*`/`release/*`; PR to `main` | +| Release & Publish | `.github/workflows/release.yml` | GitHub Release published | + +Integrates with: + +- **GitHub Actions** — matrix builds across Python 3.9, 3.11, 3.13 +- **Jenkins** — call `pybuild test build` from a `Jenkinsfile` +- **GitLab CI/CD** — use `pybuild` commands in `.gitlab-ci.yml` +- **Azure DevOps** — run `pybuild` in a pipeline YAML step + +### Example CI step + +```yaml +# .github/workflows/ci.yml +- name: Run tests + run: pybuild test +``` + +--- + +## 12. Python Wrapper (Environment Pinning) + +Gradle Wrapper ensures everyone uses the same Gradle version. Python equivalents: + +| Mechanism | How it works | +|---|---| +| `.python-version` | `pyenv` reads this to auto-switch Python versions | +| `pyproject.toml` `requires-python` | Declares the minimum supported Python version | +| `venv` / `.venv` | Isolates project dependencies from the global environment | +| `uv` | Ultra-fast resolver; locks Python + packages in `uv.lock` | + +Generated projects include a local `.venv` created automatically by `auto-gen-py-project`. + +```toml +# pyproject.toml +[project] +requires-python = ">=3.8" +``` + +```bash +# Recreate the environment anywhere +python -m venv .venv +.venv/Scripts/activate # Windows +pip install -e ".[dev]" +``` + +--- + +## 13. Artifact Publishing + +Python packages are published to PyPI (or private registries) using standard tools. + +| Tool | Purpose | +|---|---| +| `build` | Creates `.whl` and `.tar.gz` source dist | +| `twine` | Uploads distributions to PyPI | +| OIDC Trusted Publisher | Passwordless PyPI publishing from GitHub Actions | +| `flit` | Simplified packaging and publishing | + +### Example + +```bash +# Build +python -m build + +# Publish (manual) +twine upload dist/* + +# Publish via pybuild +pybuild publish +``` + +```yaml +# release.yml — automated PyPI publish on GitHub Release +- name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 +``` + +--- + +## 14. Cross-Platform Support + +Python and `pybuild` run on Windows, Linux, and macOS without modification. + +- `pybuild` uses `subprocess` with list-style args (avoids shell quoting issues). +- `pathlib.Path` handles file paths cross-platform. +- Generated projects include platform-aware `.gitignore` entries. + +### Example + +```python +# Cross-platform path handling in build.py +from pathlib import Path + +@task +def clean(): + dist = Path("dist") + if dist.exists(): + shutil.rmtree(dist) +``` + +--- + +## 15. IDE Integration + +Python projects generated by `auto-gen-py-project` work out-of-the-box with: + +| IDE | Integration | +|---|---| +| **VS Code** | Python extension auto-detects `.venv`; `build.py` tasks via Terminal | +| **PyCharm** | Detects `pyproject.toml`; run configurations for `pybuild` | +| **IntelliJ IDEA** | Python plugin + `pyproject.toml` support | +| **Neovim / Vim** | LSP via `pylsp` or `pyright` | + +`pybuild --list` outputs all available tasks so any terminal-aware editor can discover them. + +--- + +## 16. Performance Optimization + +| Feature | Python Equivalent | +|---|---| +| Incremental builds | DAG-based task skipping in `pybuild` | +| Parallel execution | `concurrent.futures.ThreadPoolExecutor` in custom tasks | +| Build cache | `pip` wheel cache; `joblib`; GitHub Actions cache | +| Configuration caching | Import-time module caching in `build.py` | +| Daemon process | `pytest-xdist` for parallel test workers | + +### Example: parallel tasks in pybuild + +```python +# build.py — run lint and type-check in parallel +import concurrent.futures + +@task(depends_on=["clean"]) +def check(): + """Run lint and type checking in parallel.""" + with concurrent.futures.ThreadPoolExecutor() as pool: + f1 = pool.submit(subprocess.run, ["ruff", "check", "src/"], check=True) + f2 = pool.submit(subprocess.run, ["mypy", "src/"], check=True) + f1.result() + f2.result() +``` + +--- + +## 17. Security Features + +| Feature | Tool | +|---|---| +| Dependency vulnerability scanning | `pip-audit`, `safety` | +| Dependency verification (hashes) | `pip --require-hashes`, `pip-tools` | +| Secure credential management | Environment variables; GitHub Actions secrets | +| Signed artifact support | `sigstore` (PEP 740) | +| Dependabot alerts | GitHub's built-in `dependabot.yml` | + +### Example + +```bash +# Audit installed packages for known CVEs +pip-audit + +# Generate locked requirements with hashes +pip-compile --generate-hashes requirements.in +``` + +--- + +## 18. Configuration Management + +Python provides multiple layers of configuration management. + +| Layer | Tool | +|---|---| +| Project metadata | `pyproject.toml` | +| Environment variables | `python-dotenv`, `os.environ` | +| Typed settings | `pydantic-settings` | +| Build profiles | Environment-specific task conditions in `build.py` | +| CLI properties | `click`, `argparse` | + +### Example + +```python +# build.py — environment-aware task +import os + +@task(depends_on=["test"]) +def publish(): + """Publish to PyPI or Test PyPI depending on environment.""" + repo = os.getenv("PUBLISH_REPO", "testpypi") + subprocess.run( + ["twine", "upload", "--repository", repo, "dist/*"], + check=True, + ) +``` + +```bash +PUBLISH_REPO=pypi pybuild publish # publish to production PyPI +pybuild publish # defaults to testpypi +``` + +--- + +## 19. Custom Build Logic + +`pybuild` makes custom build logic a first-class citizen — any Python code can be a task. + +```python +# build.py — custom code generation task +import json +from pathlib import Path + +@task +def generate_schema(): + """Auto-generate JSON schema from dataclasses.""" + from src.models import MyModel + schema = MyModel.schema() + Path("docs/schema.json").write_text(json.dumps(schema, indent=2)) + +@task(depends_on=["generate_schema", "test"]) +def build(): + subprocess.run(["python", "-m", "build"], check=True) +``` + +Shared build logic can live in a dedicated package and be imported across projects: + +```python +# shared_build/tasks.py +from auto_gen_py_project.build_system import task + +@task +def lint(): + subprocess.run(["ruff", "check", "src/"], check=True) +``` + +--- + +## 20. Reporting and Analytics + +| Report Type | Tool | +|---|---| +| Test results | `pytest` console output; `pytest --junit-xml=report.xml` | +| Code coverage | `coverage html` generates an HTML report in `htmlcov/` | +| Build performance | `pybuild` prints per-task elapsed time | +| Dependency analysis | `pipdeptree`, `pip-audit` | +| Code quality metrics | `ruff`, `pylint`, `radon` (complexity), `xenon` | + +### Example + +```bash +# Generate HTML coverage report +pytest --cov=src --cov-report=html + +# View dependency tree +pipdeptree + +# pybuild prints timing automatically +pybuild build +# > Task :clean [DONE] 0.01s +# > Task :test [DONE] 1.23s +# > Task :build [DONE] 0.87s +# BUILD SUCCESSFUL in 2.11s +``` + +--- + +## Key Advantages of the Python Approach + +| Advantage | Description | +|---|---| +| No new language | `build.py` is plain Python — no Groovy or Kotlin to learn | +| Fast setup | `pip install auto-gen-py-project` and `auto-gen-py-project my_project` | +| Flexible | Any Python library is available inside tasks | +| Portable | Works on Windows, Linux, macOS without extra tooling | +| Readable | Python's syntax is cleaner than Groovy DSL for most developers | +| Ecosystem | Thousands of PyPI packages usable directly in build scripts | + +--- + +## Common Use Cases + +| Use Case | pybuild Tasks | +|---|---| +| Python Application | `clean → lint → test → build` | +| Library Development | `clean → lint → test → build → publish` | +| FastAPI / Flask API | `clean → lint → test → build → docker-build` | +| Data Science | `clean → generate-data → train → evaluate` | +| CLI Tool | `clean → test → build → install` | +| Microservices | Root `build.py` orchestrates multiple sub-project `pybuild` calls | + +--- + +## Quick Reference: Gradle → Python + +| Gradle Feature | Python Equivalent | +|---|---| +| `build.gradle` | `build.py` | +| `@task` | `@task` decorator in `pybuild` | +| `dependsOn` | `depends_on=[...]` in `@task` | +| `gradle build` | `pybuild build` | +| `gradle --tasks` | `pybuild --list` | +| `gradle clean` | `pybuild clean` | +| `gradle test` | `pybuild test` | +| `settings.gradle` | `pyproject.toml` | +| Gradle Wrapper | `venv` + `pyproject.toml` `requires-python` | +| Maven Central | PyPI (`pypi.org`) | +| `./gradlew` | `pybuild` (or `python build.py`) | +| Groovy DSL | Python | +| Kotlin DSL | Python + type annotations + `mypy` | diff --git a/README.md b/README.md index 49d0a15..b40fe12 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,76 @@ -# Auto Gen Py Project +# auto-gen-py-project -Simple CLI tool that scaffolds a clean Python project structure — with a built-in Gradle-inspired build system (`pybuild`). +[![PyPI version](https://img.shields.io/pypi/v/auto-gen-py-project)](https://pypi.org/project/auto-gen-py-project/) +[![Python](https://img.shields.io/pypi/pyversions/auto-gen-py-project)](https://pypi.org/project/auto-gen-py-project/) +[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](LICENSE) +[![CI](https://github.com/axcel-blade/auto-gen-py-project/actions/workflows/ci.yml/badge.svg)](https://github.com/axcel-blade/auto-gen-py-project/actions/workflows/ci.yml) -## Description +CLI tool that scaffolds a clean Python project — with a built-in Gradle-inspired build system (`pybuild`). -`auto-gen-py-project` helps you start Python projects faster by generating a standards-aligned layout out of the box. It creates a project with `src/`, tests, `run.py`, `pyproject.toml`, `.gitignore`, `LICENSE`, a local `.venv`, and a ready-to-use `build.py` that wires up `pybuild` — a Gradle-inspired task runner for Python. +--- + +## Table of Contents + +- [Overview](#overview) +- [Requirements](#requirements) +- [Installation](#installation) +- [Usage](#usage) +- [pybuild — Task Runner](#pybuild--task-runner) +- [Troubleshooting](#troubleshooting) +- [Contributing](#contributing) +- [License](#license) + +--- + +## Overview + +`auto-gen-py-project` generates a standards-aligned Python project layout in one command. The scaffold includes `src/`, tests, `run.py`, `pyproject.toml`, `.gitignore`, `LICENSE`, a local `.venv`, and a ready-to-use `build.py` powered by `pybuild`. -`pybuild` lets you define tasks with dependencies (a DAG) and execute them in the correct order from a simple `build.py` file, just like Gradle's `build.gradle`. +`pybuild` lets you define tasks with dependencies (a DAG) and execute them in the correct order — just like Gradle's `build.gradle`. -## Getting Started +--- -### Dependencies +## Requirements - Python 3.8+ (3.10+ recommended) - `pip` available in your environment -- OS: Windows, Linux, or macOS +- Windows, Linux, or macOS -### Installing +--- -Clone or download this repository: +## Installation ```bash git clone https://github.com/axcel-blade/auto-gen-py-project.git cd auto-gen-py-project -``` - -Install the CLI (includes `pybuild`): - -```bash python -m pip install --upgrade pip build python -m pip install . ``` -### Executing program +--- -Create a new project folder: +## Usage + +**Scaffold a new project folder:** ```bash auto-gen-py-project my_project ``` -Initialize in the current folder: +**Initialize inside the current folder:** ```bash auto-gen-py-project my_project --init ``` -If the command is not on your `PATH`, use module mode: +**Without the CLI on your `PATH`:** ```bash python -m auto_gen_py_project my_project python -m auto_gen_py_project my_project --init ``` -Generated project structure: +**Generated project layout:** ```text my_project/ @@ -73,33 +90,30 @@ my_project/ --- -## pybuild — Gradle-like Build System +## pybuild — Task Runner -Every generated project includes a `build.py` with pre-wired tasks. The `pybuild` CLI executes them in dependency order. +Every generated project includes a `build.py` with pre-wired tasks. `pybuild` resolves and runs them in dependency order. ### Defining tasks ```python # build.py -from auto_gen_py_project.build_system import task, run_task +from auto_gen_py_project.build_system import task # Decorator style @task def clean(): - """Remove build artefacts.""" shutil.rmtree("dist", ignore_errors=True) @task(depends_on=["clean"]) def test(): - """Run the test suite.""" subprocess.run(["pytest"], check=True) @task(depends_on=["test"]) def build(): - """Build wheel and sdist.""" subprocess.run(["python", "-m", "build"], check=True) -# --- or Gradle-style function calls --- +# Gradle-style function calls task("clean", action=clean_fn) task("test", depends_on=["clean"], action=test_fn) task("build", depends_on=["test"], action=build_fn) @@ -108,16 +122,16 @@ task("build", depends_on=["test"], action=build_fn) ### Running tasks ```bash -pybuild build # runs: clean → test → build -pybuild test # runs: clean → test -pybuild clean test # explicit sequence -pybuild --list # list all tasks and their dependencies -pybuild --quiet build # suppress output -pybuild -f path/to/build.py build # custom build file -python build.py build # without installing pybuild +pybuild build # runs: clean → test → build +pybuild test # runs: clean → test +pybuild clean test # explicit sequence +pybuild --list # list all tasks and dependencies +pybuild --quiet build # suppress per-task output +pybuild -f path/build.py build # custom build file +python build.py build # without installing pybuild ``` -Example output (Gradle-style): +### Example output ``` > Build: 3 task(s) to execute @@ -137,165 +151,52 @@ BUILD SUCCESSFUL in 2.11s ### How it works -- Tasks form a **directed acyclic graph (DAG)**. `pybuild` resolves the correct execution order via topological sort. +- Tasks form a **directed acyclic graph (DAG)**; execution order is resolved via topological sort. - Cycles are detected and reported with the full dependency path. - Each task name is unique within a build file; re-registering overwrites the previous definition. -- Tasks with no action are valid placeholders (lifecycle hooks). +- Tasks with no action are valid lifecycle placeholders. -### Error handling +### Errors -| Scenario | Exception raised | +| Exception | Cause | |---|---| -| Requested task does not exist | `TaskNotFoundError` | -| Dependency references missing task | `TaskNotFoundError` | -| Cycle in dependency graph | `CyclicDependencyError` | -| Task action raises an exception | `TaskExecutionError` | +| `TaskNotFoundError` | Task name does not exist or a dependency is missing | +| `CyclicDependencyError` | Circular `depends_on` chain detected | +| `TaskExecutionError` | Task action raised an exception at runtime | --- -## Help - -For command options and usage help: +## Troubleshooting ```bash +# Show all CLI options python -m auto_gen_py_project --help pybuild --help -``` - -If installation fails, check: -```bash +# Check Python and pip versions python --version python -m pip --version ``` -Common issues: - | Problem | Fix | |---|---| | `pybuild: command not found` | Run `pip install -e .` or use `python build.py ` | | `TaskNotFoundError` | Check spelling; run `pybuild --list` to see available tasks | -| `CyclicDependencyError` | Review `depends_on` chains in your `build.py` for loops | -| Build file not found | Run `pybuild` from the directory containing `build.py`, or pass `-f path/to/build.py` | +| `CyclicDependencyError` | Review `depends_on` chains in `build.py` for loops | +| Build file not found | Run from the directory containing `build.py`, or pass `-f path/to/build.py` | --- -## Authors - -- Axcel Blade — [srikanthfernando3@gmail.com](mailto:srikanthfernando3@gmail.com) - ## Contributing -Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. - -This project uses **Git Flow**. The short version: - -``` -main ← production, tagged releases only -develop ← default integration branch, base for all features -feature/* ← one branch per feature, PR → develop -release/* ← release prep (version bump, changelog), PR → main then back-merge → develop -hotfix/* ← urgent production patches, PR → main then back-merge → develop -``` - -Full details — commands, PR rules, branch protections, rollback — in [CONTRIBUTING.md](CONTRIBUTING.md). +Contributions are welcome. This project uses **Git Flow**. -Don't forget to give the project a star! Thanks again! +See [CONTRIBUTING.md](CONTRIBUTING.md) for the full workflow — branch commands, PR rules, CI overview, release process, and rollback guide. -Top contributors: +See [CHANGELOG.md](CHANGELOG.md) for version history. - - contrib.rocks image - - -

(back to top)

- -## Local development - -```bash -# Install in editable mode (registers pybuild CLI) -pip install -e . - -# Run tests -python -m pytest tests/test_build_system.py -v # fast (no venv creation) -python -m pytest tests/ -v # full suite (slow — creates venvs) - -# Use pybuild task pipeline on this project -pybuild --list -pybuild test -pybuild build -``` - -### CI / CD overview - -| Workflow | File | Trigger | What it does | -|---|---|---|---| -| CI | `ci.yml` | push to `develop`/`feature/*`/`release/*`/`hotfix/*`; PR to `main`/`develop` | Tests (3.9/3.11/3.13), build check, version consistency | -| Release & Publish | `release.yml` | GitHub Release published | Tests, build wheel+sdist, publish to PyPI via OIDC | - -### Required GitHub settings - -- **PyPI Trusted Publisher** — set up at [pypi.org/manage/account/publishing](https://pypi.org/manage/account/publishing/); no `TWINE_PASSWORD` secret needed. -- **Environment named `pypi`** in repository Settings → Environments. -- **Branch protection on `main`**: require `Test (3.9)`, `Test (3.11)`, `Test (3.13)`, `Build verification`, `Version consistency` + 1 review + up-to-date branch. -- **Branch protection on `develop`**: require `Test (*)`, `Build verification` + 1 review. - -### Release process (Git Flow) - -```bash -# 1. Cut a release branch from develop -git checkout develop && git pull -git checkout -b release/0.3.0 - -# 2. Bump version in __init__.py and setup.py, update CONTRIBUTING.md / README.md - -# 3. Merge into main and tag -git checkout main && git merge --no-ff release/0.3.0 -git tag -a v0.3.0 -m "Release 0.3.0" -git push origin main --tags - -# 4. Back-merge into develop -git checkout develop && git merge --no-ff release/0.3.0 -git push origin develop - -# 5. Publish a GitHub Release from the tag → release.yml handles PyPI -``` - -### Rollback a bad release - -```bash -# Yank on PyPI (marks as "avoid" — does not delete) -twine yank auto-gen-py-project==X.Y.Z --reason "describe the issue" - -# Remove GitHub Release and tag -gh release delete vX.Y.Z --yes -git tag -d vX.Y.Z && git push origin --delete vX.Y.Z - -# Fix via hotfix/* branch, then re-release with a patch version -``` - -## Version History - -- 0.2.0 - - Adopt Git Flow branching model (`main` / `develop` / `feature/*` / `release/*` / `hotfix/*`) - - Add Gradle-inspired build system (`pybuild` CLI + `auto_gen_py_project.build_system` package) - - Generated projects include a ready-to-use `build.py` with `clean → lint → test → build` tasks - - DAG-based task dependency resolution with cycle detection - - Three task registration styles: bare decorator, decorator with options, function-call DSL - - Add CI workflow (`ci.yml`) — matrix builds on Python 3.9/3.11/3.13 + version-consistency check - - Replace `workflow.yml` with `release.yml` — adds pre-publish test gate - - Add `CONTRIBUTING.md` with full Git Flow commands, branch protection config, rollback guide - - 23 new tests covering Task, Registry, DAG, Runner, and DSL -- 0.1.3 - - Align package metadata and version across project files - - Add `auto-gen-py-project` console command entry point - - Remove GitHub Packages workflow and keep PyPI publishing workflow -- 0.1.2 - - Create `.venv` inside generated project folders (including `--init`) - - Add `.venv/` to generated `.gitignore` -- 0.1 - - Initial release +--- ## License -This project is licensed under the GNU General Public License v3 — see the `LICENSE` file for details. +Licensed under the [GNU General Public License v3](LICENSE). diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..cb4b24f --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ------- | ------------------ | +| 0.2.x | :white_check_mark: | +| < 0.2.0 | :x: | + +## Reporting a Vulnerability + +**Please do not report security vulnerabilities through public GitHub issues.** + +Send a report to **srikanthfernando3@gmail.com** with: + +- A description of the vulnerability +- Steps to reproduce +- Potential impact +- Any suggested fixes (optional) + +You will receive a response within **48 hours**. If the issue is confirmed, a patch will be released as soon as possible depending on severity. diff --git a/SUPPORT.md b/SUPPORT.md new file mode 100644 index 0000000..1aee0a0 --- /dev/null +++ b/SUPPORT.md @@ -0,0 +1,27 @@ +# Support + +## How to Get Help + +### Bug Reports & Feature Requests + +Open an issue on [GitHub Issues](https://github.com/axcel-blade/auto-gen-py-project/issues). + +Use the appropriate issue template: +- **Bug report** — for unexpected behavior or errors +- **Feature request** — for new functionality + +### Questions & Discussions + +For general questions, use [GitHub Discussions](https://github.com/axcel-blade/auto-gen-py-project/discussions). + +### Direct Contact + +For security vulnerabilities, see [SECURITY.md](SECURITY.md). +For other sensitive matters, email **srikanthfernando3@gmail.com**. + +## Useful Resources + +- [README](README.md) — installation and usage guide +- [PYTHON_BUILD_FEATURES.md](PYTHON_BUILD_FEATURES.md) — full `pybuild` feature reference +- [CONTRIBUTING.md](CONTRIBUTING.md) — how to contribute +- [CHANGELOG.md](CHANGELOG.md) — version history