A comprehensive Bash script to automate the creation of Python packages with extensive customization options, including build systems, project layouts, GitHub integration, Continuous Integration (CI) setup, dependency management, and more.
- Features
- Prerequisites
- Installation
- Usage
- Options
- Supported Licenses
- Project Layouts
- Build Systems
- Testing Frameworks
- Continuous Integration
- Code Formatting and Linting
- Documentation Setup
- Virtual Environment Management
- Logging
- Contributing
- License
- Support
- Advanced Build Systems: Choose between
setuptools
andPoetry
for project configuration. - Flexible Project Layouts: Opt for
src
ordirect
project structures. - Automated Repository Management: Initialize Git repositories and create GitHub repositories via GitHub CLI (
gh
). - Enhanced Dependency Management: Set up pre-commit hooks, code formatters (
black
,autopep8
), and linters (flake8
,pylint
). - Documentation Setup: Integrate Sphinx for professional project documentation.
- Continuous Integration (CI): Configure CI pipelines with GitHub Actions, Travis CI, or CircleCI.
- Comprehensive License Support: Choose from multiple licenses with automated license file generation.
- Robust Error Handling and Logging: Detailed logging of all actions and errors for easy troubleshooting.
- Interactive and Non-Interactive Modes: Fully configurable via command-line flags or guided interactive prompts.
- Virtual Environment Management: Select between
venv
,virtualenv
, or Poetry's built-in environment management. - Project Publishing Preparation: Set up workflows for PyPI publishing and enhanced
README.md
templates.
Ensure the following tools are installed on your system:
- Bash: Unix shell.
- Python 3.6+: Ensure
python3
is available in your PATH. - curl: For fetching license texts.
- git: For version control.
- GitHub CLI (
gh
) (optional): For GitHub repository creation.
Note: Some features require additional tools like poetry
or pre-commit
. The script will prompt you if these are missing.
-
Clone the Repository (if applicable):
git clone https://github.com/yourusername/ultimate-python-package-script.git cd ultimate-python-package-script
-
Download the Script: Alternatively, you can download the
create_python_package.sh
script directly. -
Make the Script Executable:
chmod +x create_python_package.sh
Create a new Python package with default settings:
./create_python_package.sh your_package_name
The script offers a wide range of options to customize your Python package setup. Below are the available flags and their descriptions.
-
Basic Package Creation with Default Settings:
./create_python_package.sh my_package
-
Package with Git Initialization and MIT License:
./create_python_package.sh my_package --git --license MIT
-
Using Poetry, Src Layout, and Pytest:
./create_python_package.sh my_package --build-system poetry --layout src --tests pytest
-
Setting Up GitHub Repository, CI with GitHub Actions, Black Formatter, and Flake8 Linter:
./create_python_package.sh my_package --git --create-repo --license Apache-2.0 --ci github --format black --lint flake8
-
Creating a Direct Layout Package with Sphinx Documentation and Virtualenv:
./create_python_package.sh my_package --layout direct --docs --env virtualenv
Flag | Description | Example |
---|---|---|
--git |
Initialize a Git repository | --git |
--remote <url> |
Set remote repository URL | --remote https://github.com/user/repo.git |
--create-repo |
Create a GitHub repository using GitHub CLI (gh ) |
--create-repo |
--license <type> |
Add a LICENSE file (e.g., MIT, Apache-2.0, GPL-3.0, BSD-3-Clause) | --license MIT |
--build-system <type> |
Choose build system: setuptools (default) or poetry |
--build-system poetry |
--layout <type> |
Choose project layout: src (default) or direct |
--layout direct |
--tests <framework> |
Choose testing framework: unittest (default) or pytest |
--tests pytest |
--ci <service> |
Set up Continuous Integration: github (default), travis , circleci |
--ci github |
--format <formatter> |
Choose code formatter: black , autopep8 , none (default) |
--format black |
--lint <linter> |
Choose linter: flake8 , pylint , none (default) |
--lint flake8 |
--docs |
Set up Sphinx documentation | --docs |
--env <tool> |
Choose virtual environment tool: venv (default), virtualenv , poetry |
--env virtualenv |
--python <version> |
Specify Python version for virtual environment (default: 3 ) |
--python 3.8 |
--help |
Display help message | --help |
- MIT
- Apache-2.0
- GPL-3.0
- BSD-3-Clause
Additional licenses can be added by extending the script.
-
Src Layout (
--layout src
): Organizes package code within asrc/
directory.my_package/ ├── src/ │ └── my_package/ │ └── __init__.py ├── tests/ │ └── test_sample.py ├── setup.py ├── README.md └── ...
-
Direct Layout (
--layout direct
): Places package code directly in the project root.my_package/ ├── my_package/ │ └── __init__.py ├── tests/ │ └── test_sample.py ├── setup.py ├── README.md └── ...
- Setuptools (
--build-system setuptools
): Traditional Python build system usingsetup.py
. - Poetry (
--build-system poetry
): Modern dependency and packaging tool withpyproject.toml
.
- Unittest (
--tests unittest
): Python's built-in testing framework. - Pytest (
--tests pytest
): Advanced testing framework with rich features.
Supported CI services:
- GitHub Actions (
--ci github
) - Travis CI (
--ci travis
) - CircleCI (
--ci circleci
)
Configure the desired CI service to automate testing and deployment.
-
Formatters (
--format
):- Black: Code formatter for consistent styling.
- AutoPEP8: Automatically formats Python code to conform to PEP 8.
- None: Skip formatting setup.
-
Linters (
--lint
):- Flake8: Comprehensive linting tool for style and syntax checks.
- Pylint: Highly configurable linter with extensive checks.
- None: Skip linting setup.
Pre-commit hooks are configured to enforce code quality.
-
Sphinx (
--docs
): Generate professional documentation with Sphinx.Initializes Sphinx in the
docs/
directory with basic configuration.
Choose how to manage your virtual environment:
- venv (
--env venv
): Python's built-in virtual environment tool. - virtualenv (
--env virtualenv
): Third-party virtual environment tool with additional features. - Poetry (
--env poetry
): Manages environments automatically when using Poetry as the build system.
All actions and errors are logged to create_py_package.log
within the project directory for easy troubleshooting.
Contributions are welcome! Please follow these steps:
-
Fork the Repository
-
Create a Feature Branch
git checkout -b feature/YourFeature
-
Commit Your Changes
git commit -m "Add your feature"
-
Push to the Branch
git push origin feature/YourFeature
-
Open a Pull Request
Please ensure your code adheres to the project's coding standards and passes all linting and formatting checks.
This project is licensed under the MIT License.