Skip to content

Commit

Permalink
feat: update python template
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 6, 2024
1 parent 688c9ec commit d97fa75
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 52 deletions.
89 changes: 38 additions & 51 deletions template/py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,69 @@

[![CI](https://github.com/{{gh_uname}}/{{project-name}}/workflows/CI/badge.svg)](https://github.com/{{gh_uname}}/{{project-name}}/actions)
[![Coverage Status](https://coveralls.io/repos/github/{{gh_uname}}/{{project-name}}/badge.svg?branch=main)](https://coveralls.io/github/{{gh_uname}}/{{project-name}}?branch=main)
[![PyPI version](https://badge.fury.io/py/{{project-name}}.svg)](https://badge.fury.io/py/{{project-name}})
[![Python Versions](https://img.shields.io/pypi/pyversions/{{project-name}}.svg)](https://pypi.org/project/{{project-name}}/)

## Overview

{{project-name}} is a Python project that aims to {{describe your project's purpose}}.
{{project-name}} is a Python project that aims to ...

## Installation
## Features

### Using pip
- Feature 1: Description of feature 1
- Feature 2: Description of feature 2
- ...

To install `{{project-name}}`, simply use pip:
## Requirements

```bash
pip install {{project-name}}
```
- Python 3.11+
- Dependencies: list any major dependencies here

### From source
## Installation

```bash
# 1. Clone the repository:
git clone https://github.com/{{gh_uname}}/{{project-name}}.git

# 2. Navigate into the project directory:
cd {{project-name}}

# 3. Install the dependencies:
pip install -r requirements.txt

pip install {{project-name}}
```

## Development

If you want to contribute to the project, follow these steps to set up the development environment:

Please ensure `uv`, `ruff` and `hatch` are installed firstly.

```bash
# create a virtual env by uv
make init
## Quick Start

# install some dependencies by pyproject.toml with uv
make install-dev
Here's a simple example to get you started:

# build wheel package by hatch
make build

# run the UT and FT by hatch
make test
```python
import {{project-name}}

# Example usage
result = {{project-name}}.do_something()
print(result)
```

## Usage

To use {{project-name}}, you can follow this.
For more detailed usage instructions, please refer to our [Usage Guide](docs/usage.md).

```python
import {{project-name}}
## Development

# Example usage
{{project-name}}.do_something()
```
To set up the development environment:

## License
1. Ensure `uv`, `ruff`, and `hatch` are installed.
2. Clone the repository and navigate to the project directory.
3. Run the following commands:

Licensed under either of
```bash
make init # Create a virtual env using uv
make install-dev # Install development dependencies
make build # Build wheel package
make test # Run tests
```

* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
For more details, see our [Contributing Guide](CONTRIBUTING.md).

at your option.
## License

## Contribution
Licensed under either of:
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
## Changelog

See [CONTRIBUTING.md](CONTRIBUTING.md).
See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this project.
File renamed without changes.
74 changes: 74 additions & 0 deletions template/py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "{{project-name}}"
version = "0.0.1"
description = "{{py_proj_desc}}"
readme = "README.md"
requires-python = ">=3.11"
license = "MIT"
authors = [
{ name = "{{gh_uname}}" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"pytest>=8.0",
"pytest-cov>=5.0",
]

[project.optional-dependencies]
dev = [
"ruff>=0.5.0",
]

[project.urls]
Documentation = "https://github.com/{{gh_uname}}/{{project-name}}#readme"
Issues = "https://github.com/{{gh_uname}}/{{project-name}}/issues"
Source = "https://github.com/{{gh_uname}}/{{project-name}}"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [
"-ra", # show all captured stdout/stderr
"-q", # quiet
"--cov={{project-name}}", # report coverage of {{project-name}}
"--cov-report=term-missing", # show missing coverage
"--cov-report=html", # generate html coverage report
"--cov-report=lcov", # generate lcov coverage report
]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_functions = ["test_*"]
markers = [
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
]

[tool.coverage.run]
source_pkgs = ["{{project-name}}", "tests"]
branch = true
parallel = true
omit = [
"*/.venv/*"
]

[tool.coverage.paths]
{{project-name}} = ["src/{{project-name}}"]
tests = ["tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]
show_missing = true # Show missing lines in the report
precision = 2 # Number of decimal places to use when rounding
6 changes: 6 additions & 0 deletions template/py/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target-version = "py311"
line-length = 120

[lint]
select = ["E", "F", "W", "C", "N", "Q", "I"]
ignore = []
1 change: 0 additions & 1 deletion template/py/src/{{project-name}}/__about__.py

This file was deleted.

8 changes: 8 additions & 0 deletions template/py/src/{{project-name}}/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .example import add, divide, multiply, subtract

__all__ = [
"add",
"subtract",
"multiply",
"divide",
]
16 changes: 16 additions & 0 deletions template/py/src/{{project-name}}/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def add(a, b):
return a + b


def subtract(a, b):
return a - b


def multiply(a, b):
return a * b


def divide(a, b):
if b == 0:
raise ValueError("Division by zero is not allowed.")
return a / b
Empty file removed template/py/tests/__init__.py
Empty file.
Empty file removed template/py/tests/test_app.py
Empty file.
20 changes: 20 additions & 0 deletions template/py/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
from {{project-name}} import add, divide, multiply, subtract


def test_add():
assert add(1, 2) == 3


def test_subtract():
assert subtract(5, 3) == 2


def test_multiply():
assert multiply(2, 3) == 6


def test_divide():
assert divide(10, 2) == 5.0
with pytest.raises(ValueError):
divide(10, 0)

0 comments on commit d97fa75

Please sign in to comment.