new-python-project
Original:🇨🇳 Chinese
Translated
Initialize a standardized Python project, including dependency management, code style checking, testing framework, version management, etc. This skill is triggered when users need to create a new Python project.
11installs
Sourceynz012x/skills
Added on
NPX Install
npx skill4agent add ynz012x/skills new-python-projectTags
Translated version includes tags in frontmatterSKILL.md Content (Chinese)
View Translation Comparison →Python Project Initialization
Process Overview
- Confirm Project Information - Interact with users to confirm project name and Python version
- Initialize Project - Use uv init to create the project and enable git version control
- Configure Code Style Checking - Use pre-commit to manage and initialize code style checking hooks, and apply corresponding specification configurations
- Configure Testing Framework - Add pytest and pytest-cov as development dependencies
- Configure Version Management Tools - Optimize VCS management by configuring .gitignore, set up version metadata, and configure bumpversion for semantic versioning
- Add Common Development Tools - Add ipython for local debugging
- Install and Verify - Install all dependencies and verify configurations
- Update README - Create and update the README file with project usage instructions
- Complete Initial Commit
Step 1: Confirm Project Information
Confirm the following information with users:
- Project Name (project_name): Defaults to the current directory name
- Project Description (project_description): A short project description to quickly understand the project's function and positioning
- Python Version (python_version): Recommended to use officially supported versions (3.10 and above)
Step 2: Initialize Project
Use uv to initialize the project and enable git version control:
bash
uv init \
# Project name
--name=<project_name> \
# Project description
--description="<project_description>" \
# Initialize src/<project_name> package directory
--package \
# Initialize git
--vcs=git \
# Minimum supported Python version
--python=<python_version>Step 3: Configure Code Style Checking
Add pre-commit and code formatting tools:
bash
uv add --dev pre-commit black flake8 flake8-import-order ruffWrite the content of assets/pre-commit-config.yaml to the file in the project root directory
.pre-commit-config.yamlApply the template assets/flake8.j2 to the file in the project root directory, replacing the variable with the project name
.flake8{{ project_name }}Install pre-commit hooks:
bash
uv run pre-commit installStep 4: Configure Testing Framework
Add pytest and pytest-cov as development dependencies:
bash
uv add --dev pytest pytest-covCreate tests directory and initial test files:
bash
mkdir -p tests
touch tests/__init__.pyAdd pytest configuration to :
pyproject.tomltoml
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*", "*Test"]
python_functions = ["test_*"]
addopts = [
"-v",
"--cov=src/<project_name>",
"--cov-report=term-missing",
"--tb=short",
]
[tool.coverage.run]
source = ["src/<project_name>"]
branch = true
omit = ["tests/*"]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise NotImplementedError",
"if __name__ == .__main__.:",
]Step 5: Configure Version Management Tools
Add .gitignore
bash
curl https://raw.githubusercontent.com/github/gitignore/refs/heads/main/Python.gitignore -o .gitignoreAdd bumpversion dependency:
bash
uv add --dev bumpversionConfigure Version Metadata
-
Create afile to store project version metadata
src/<project_name>/_version.pypython__version__ = "0.1.0" -
Export version information to the project package namespace, adjust
src/<project_name>/__init__.pypython"""<project_name> package.""" from ._version import __version__ # noqa: F401 -
Add test case to verify version metadata retrievalpython
from <project_name> import __version__ def test_version(): assert __version__
Apply the template assets/bumpversion.cfg.j2 to the file in the project root directory, replacing the variable with the project name
.bumpversion.cfg{{ project_name }}Step 6: Add Common Development Tools
bash
uv add --dev ipythonStep 7: Install and Verify
Install all dependencies:
bash
uv syncVerify configurations:
bash
# Verify pytest
uv run pytest
# Verify pre-commit
uv run pre-commit run --all-files
# Verify bumpversion
uv run bumpversion --help
# Verify version metadata
uv run python -c 'from <project_name> import __version__; print(__version__)'Step 8: Update README
Generate the project README file using the template assets/README.md.j2, replacing the following variables:
- - Project name
{{ project_name }} - - Project description
{{ project_description }}
Write the generated content to the file in the project root directory.
README.mdStep 9: Complete Initial Commit
bash
git add .
git commit -m "Initial project setup"