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
Added on

NPX Install

npx skill4agent add ynz012x/skills new-python-project

SKILL.md Content (Chinese)

View Translation Comparison →

Python Project Initialization

Process Overview

  1. Confirm Project Information - Interact with users to confirm project name and Python version
  2. Initialize Project - Use uv init to create the project and enable git version control
  3. Configure Code Style Checking - Use pre-commit to manage and initialize code style checking hooks, and apply corresponding specification configurations
  4. Configure Testing Framework - Add pytest and pytest-cov as development dependencies
  5. Configure Version Management Tools - Optimize VCS management by configuring .gitignore, set up version metadata, and configure bumpversion for semantic versioning
  6. Add Common Development Tools - Add ipython for local debugging
  7. Install and Verify - Install all dependencies and verify configurations
  8. Update README - Create and update the README file with project usage instructions
  9. 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 ruff
Write the content of assets/pre-commit-config.yaml to the
.pre-commit-config.yaml
file in the project root directory
Apply the template assets/flake8.j2 to the
.flake8
file in the project root directory, replacing the variable
{{ project_name }}
with the project name
Install pre-commit hooks:
bash
uv run pre-commit install

Step 4: Configure Testing Framework

Add pytest and pytest-cov as development dependencies:
bash
uv add --dev pytest pytest-cov
Create tests directory and initial test files:
bash
mkdir -p tests
touch tests/__init__.py
Add pytest configuration to
pyproject.toml
:
toml
[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 .gitignore
Add bumpversion dependency:
bash
uv add --dev bumpversion
Configure Version Metadata
  1. Create a
    src/<project_name>/_version.py
    file to store project version metadata
    python
    __version__ = "0.1.0"
  2. Export version information to the project package namespace, adjust
    src/<project_name>/__init__.py
    python
    """<project_name> package."""
    
    from ._version import __version__  # noqa: F401
  3. Add test case to verify version metadata retrieval
    python
    from <project_name> import __version__
    
    def test_version():
        assert __version__
Apply the template assets/bumpversion.cfg.j2 to the
.bumpversion.cfg
file in the project root directory, replacing the variable
{{ project_name }}
with the project name

Step 6: Add Common Development Tools

bash
uv add --dev ipython

Step 7: Install and Verify

Install all dependencies:
bash
uv sync
Verify 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
README.md
file in the project root directory.

Step 9: Complete Initial Commit

bash
git add .
git commit -m "Initial project setup"