Skip to content

Commit

Permalink
build(python): use uv for all scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
pplmx committed Aug 21, 2024
1 parent 95d203e commit c76a122
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 63 deletions.
1 change: 1 addition & 0 deletions template/py/{{cookiecutter.project_slug}}/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# 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.1.0/),
Expand Down
2 changes: 1 addition & 1 deletion template/py/{{cookiecutter.project_slug}}/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 {{cookiecutter.full_name}}
Copyright (c) 2024 {{cookiecutter.full_name}}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 10 additions & 11 deletions template/py/{{cookiecutter.project_slug}}/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
.PHONY: help init install-dev build test ruff image clean
.PHONY: help build test ruff image clean
.DEFAULT_GOAL := help

APP_NAME := {{cookiecutter.project_slug}}

# Create virtual environment
init:
@uv venv
# Init the venv
init: sync

# Install development dependencies
install-dev:
@uv pip install .[dev]
# Sync the project with the venv
sync:
@uv sync

# Build wheel
build:
@hatch build
@uvx hatch build

# Test
test:
@hatch test
@uvx hatch test

# Ruff
ruff:
@ruff format .
@ruff check . --fix
@uvx ruff format .
@uvx ruff check . --fix

# Build image
image:
Expand Down
1 change: 1 addition & 0 deletions template/py/{{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Python Versions](https://img.shields.io/pypi/pyversions/{{cookiecutter.project_slug}}.svg)](https://pypi.org/project/{{cookiecutter.project_slug}}/)

## Table of Contents

- [Overview](#overview)
- [Features](#features)
- [Quick Start](#quick-start)
Expand Down
34 changes: 7 additions & 27 deletions template/py/{{cookiecutter.project_slug}}/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This guide will help you set up your development environment and contribute to the `{{cookiecutter.project_slug}}` project.

## Table of Contents

- [Setting Up the Development Environment](#setting-up-the-development-environment)
- [Running Tests](#running-tests)
- [Building the Project](#building-the-project)
Expand All @@ -13,41 +14,21 @@ This guide will help you set up your development environment and contribute to t
### Prerequisites

Before you begin, ensure you have the following installed:
- Python 3.11+
- `pipx` (recommended for tool installation)

### Installation Steps

1. Install required tools:

We recommend using `pipx` for installing `uv`, `ruff`, and `hatch`. If you don't have `pipx`, install it first:

```bash
python -m pip install --user pipx
python -m pipx ensurepath
```
- Python {{cookiecutter.python_version}}+

Then install the required tools:
### Installation Steps

```bash
pipx install uv ruff hatch
```
1. Install `uv`

Alternative installation method using `uv`:
- For macOS and Linux:
```bash
# macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
uv tool install ruff hatch
```

- For Windows:
```powershell
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
uv tool install ruff hatch
```

> Note: Ensure that `~/.local/bin` is in your `PATH` environment variable.

2. Clone the repository and navigate to the project directory:

```bash
Expand All @@ -58,8 +39,7 @@ Before you begin, ensure you have the following installed:
3. Set up the development environment:

```bash
make init # Create a virtual environment using uv
make install-dev # Install development dependencies
make init
```

## Running Tests
Expand Down
64 changes: 40 additions & 24 deletions template/py/{{cookiecutter.project_slug}}/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,63 @@
import pytest

from {{cookiecutter.package_name}} import add, divide, multiply, subtract


@pytest.mark.parametrize("a, b, expected", [
(1, 2, 3),
(0, 0, 0),
(-1, -1, -2),
])
@pytest.mark.parametrize(
"a, b, expected",
[
(1, 2, 3),
(0, 0, 0),
(-1, -1, -2),
],
)
def test_add(a, b, expected):
assert add(a, b) == expected


@pytest.mark.parametrize("a, b, expected", [
(1, 2, -1),
(0, 0, 0),
(-1, -1, 0),
])
@pytest.mark.parametrize(
"a, b, expected",
[
(1, 2, -1),
(0, 0, 0),
(-1, -1, 0),
],
)
def test_subtract(a, b, expected):
assert subtract(a, b) == expected


@pytest.mark.parametrize("a, b, expected", [
(1, 2, 2),
(0, 0, 0),
(-1, -1, 1),
])
@pytest.mark.parametrize(
"a, b, expected",
[
(1, 2, 2),
(0, 0, 0),
(-1, -1, 1),
],
)
def test_multiply(a, b, expected):
assert multiply(a, b) == expected


@pytest.mark.parametrize("a, b, expected", [
(1, 2, 0.5),
(-1, -1, 1),
])
@pytest.mark.parametrize(
"a, b, expected",
[
(1, 2, 0.5),
(-1, -1, 1),
],
)
def test_divide(a, b, expected):
assert divide(a, b) == expected


@pytest.mark.parametrize("a, b", [
(0, 0),
(10, 0),
(-10, 0),
])
@pytest.mark.parametrize(
"a, b",
[
(0, 0),
(10, 0),
(-10, 0),
],
)
def test_divide_by_zero(a, b):
with pytest.raises(ValueError, match="Division by zero is not allowed."):
divide(a, b)

0 comments on commit c76a122

Please sign in to comment.