Skip to content
Merged

Uv #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
# Install a specific version of uv.
version: "0.5.18"
- name: Install dependencies
run: make install
- name: Test Python Module Generation
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*.pyc
__pycache__/
.pytest_cache

*.egg-info
.install

# Generated project
Expand Down
33 changes: 12 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@ GENERATED_PROJECT := my-project
.PHONY: ci
ci: build ## CI Build: Test Sample
make install -C $(GENERATED_PROJECT)
cd $(GENERATED_PROJECT) && poetry poe test
cd $(GENERATED_PROJECT) && poetry poe check
cd $(GENERATED_PROJECT) && uv run poe test
cd $(GENERATED_PROJECT) && uv run poe check

# DEPENDENCIES #################################################################

install: poetry.lock ## Install project
$(MAKE) configure
poetry install --no-root

poetry.lock: pyproject.toml
$(MAKE) configure
poetry lock
.PHONY: install
install: lock ## Install project dependencies
@mkdir -p .cache
uv venv
uv pip install -r pyproject.toml


.PHONY: configure
configure:
@poetry config virtualenvs.in-project true
@poetry run python -m pip install --upgrade pip
@poetry run python -m pip install --upgrade setuptools
lock: pyproject.toml
uv lock
@touch $@


# BUILD ########################################################################
Expand All @@ -33,26 +30,20 @@ configure:
build: clean install $(GENERATED_PROJECT) ## Generate Sample
$(GENERATED_PROJECT): $(SOURCE_FILES)
@cat cookiecutter.json
@poetry run cookiecutter . --no-input --overwrite-if-exists
@uv run cookiecutter . --no-input --overwrite-if-exists
@mkdir -p $(GENERATED_PROJECT)
@touch $(GENERATED_PROJECT)

# GENERATE ######################################################################

.PHONY: generate
generate: clean install
poetry run cookiecutter .
uv run cookiecutter .

# CLEANUP ######################################################################

.PHONY: clean
clean: ## Delete all generated and temporary files
@rm -rf $(GENERATED_PROJECT)

# HELP ########################################################################

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
Empty file added lock
Empty file.
1,598 changes: 0 additions & 1,598 deletions poetry.lock

This file was deleted.

72 changes: 62 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
[tool.poetry]
[project]
name = "python-module-template"
version = "1.3.0"
version = "2.0.0"
description = "A template for Python libraries."
authors = ["Jerome Guibert <jguibert@gmail.com>"]
authors = [{ name = "Jerome Guibert", email = "jguibert@gmail.com" }]
maintainers = [{ name = "Jerome Guibert", email = "jguibert@gmail.com" }]
readme = "readme.md"
license = {file = "LICENSE.md"}
keywords = []
classifiers = [
# update this list to match your application: https://pypi.org/pypi?%3Aaction=list_classifiers
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[tool.poetry.dependencies]
python = ">=3.9,<4"
cookiecutter = "*"
#jinja2-time = "^0.2.0"
poetry = "^2.0.0"
requires-python = ">=3.9,<4"
dependencies = ["cookiecutter"]

[dependency-groups]
dev = [
"poethepoet >= 0.32.1",
"setuptools>=42",
]
docs = [
"mkdocs~= 1.6",
"mkdocs-include-markdown-plugin >= 7.1.2",
"mkdocstrings[python] ~= 0.27",
"mkdocs-material == 9.*",
"mkdocs-include-markdown-plugin ~= 7.1.2"
]

[tool.uv]
package = true
cache-dir = "./.cache"
default-groups = ["dev", "docs"]

[tool.poe.tasks.docs]
help = "Build site documentation"
shell = """
git fetch origin gh-pages &
uv run mkdocs build --clean
"""

[tool.poe.tasks.docs-publish]
help = "Publish site documentation"
cmd = """
uv run mkdocs gh-deploy --clean
"""

[tool.poe.tasks.requirements]
help = "Generate requirements.txt"
cmd = "uv pip compile pyproject.toml -o requirements.txt "
capture_stdout = "requirements.txt"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
138 changes: 67 additions & 71 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It utilizes popular libraries to fully automate all development and deployment t
## Features

* Core:
* [poetry](https://python-poetry.org/) to rules them all
* [uv](https://docs.astral.sh/uv/) as depdencies manager
* [pep-0518](https://www.python.org/dev/peps/pep-0518/) alias `pyproject.toml` for managing dependencies, package metadata, ...
* Project tooling:
* Formatting, Analysing with [ruff](https://github.com/charliermarsh/ruff)
Expand All @@ -20,7 +20,7 @@ It utilizes popular libraries to fully automate all development and deployment t
* 'package': launch an install/test/check on each push and pull request on 'main' branch.
* 'release": on each tag push, launch:
- a github release
- a pypi publish . You have to configure a secret 'PYPI_TOKEN' in your git repository.
- a pypi publish . You have to add a Trusted Publisher to an existing PyPI project(https://docs.pypi.org/trusted-publishers/adding-a-publisher/).
- a site documentation publication
* [dependabot](https://github.com/dependabot) to manage dependencies updates.
* Documentation:
Expand All @@ -30,6 +30,9 @@ It utilizes popular libraries to fully automate all development and deployment t
* Expose with documentation site under 'gh-pages' branch per default.


Until 2025/01/15, I use [poetry](https://python-poetry.org/) to rules them all. This work is still avalaible on `poetry`branch.


## About this project

In 2019, I worked on [template-python](https://github.com/geronimo-iia/template-python) which was based on [Jace's Python Template](https://github.com/jacebrowning/template-python).
Expand Down Expand Up @@ -70,6 +73,17 @@ In 2025, with the new release of poetry 2.0.0, I wanna make an update:
- simplify workflow and makefile
- update pyproject.toml declaration as our Python standard evolve :)

Few weeks later, my mates show me [uv](https://docs.astral.sh/uv/). An extremely fast Python package and project manager, written in Rust.
What I found very usefull:
- it's fast to resolve and install dependencies
- follow closely the pyproject.toml standardization
- more simple to manage than poetry
- you can handle complex dependencies nightmare https://docs.astral.sh/uv/concepts/resolution/, & see your dependencies tree...
- you can develop localy with unreleased libraries
- to build our library : we can use setuptools
This tool still missing something like poetthepoet, but i hope that it could be integrated soon.
So let's have a try !



## Usage
Expand All @@ -81,7 +95,7 @@ $ pip install cookiecutter
$ cookiecutter gh:geronimo-iia/python-module-template -f
```

or
or using local clone and [uv](https://docs.astral.sh/uv/):

```
git clone git@github.com:geronimo-iia/python-module-template.git
Expand All @@ -94,80 +108,62 @@ Cookiecutter will ask you for some basic info (your name, project name, python p

Poe target list:

| Name | Comment |
| ----------------------- | ---------------------------------------------------------------------------------------- |
| poetry poe check | Run linters and static analysis |
| poetry poe test | Run unit tests |
| poetry poe build | Builds the source and wheels archives (and run check & test target) |
| poetry poe publish | Publishes the package, previously built with the build command, to the remote repository |
| poetry poe docs | Builds site documentation. |
| poetry poe docs-publish | Build and publish site documentation. |
| poetry poe clean | Delete all generated and temporary files |
| poetry poe requirements | Generate requirements.txt |
| | |

You could retrieve those commands with `poetry poe`. It will output something like this :
| Name | Comment |
| ---------------- | ---------------------------------------- |
| poe types | Run the type checker |
| poe lint | Run linting tools on the code base |
| poe style | Validate black code style |
| poe test | Run unit tests |
| poe check | Run all checks on the code base |
| poe build | Builds module |
| poe publish | Publishes the package |
| poe docs | Builds site documentation. |
| poe docs-publish | Build and publish site documentation. |
| poe clean | Delete all generated and temporary files |
| poe requirements | Generate requirements.txt |
| | |

You could retrieve those commands with `poe`. It will output something like this :

```
Poe the Poet - A task runner that works well with poetry.
version 0.25.0

Result: No task specified.

USAGE
poetry poe [-h] [-v | -q] [--root PATH] [--ansi | --no-ansi] task [task arguments]

GLOBAL OPTIONS
-h, --help Show this help page and exit
--version Print the version and exit
-v, --verbose Increase command output (repeatable)
-q, --quiet Decrease command output (repeatable)
-d, --dry-run Print the task contents but don't actually run it
--root PATH Specify where to find the pyproject.toml
--ansi Force enable ANSI output
--no-ansi Force disable ANSI output

CONFIGURED TASKS
build Build module
publish Publish module
check Run Linter
test Run unit tests
docs Build site documentation
docs-publish Publish site documentation
clean Remove all generated and temporary files
requirements Generate requirements.txt
Usage:
poe [global options] task [task arguments]

Global options:
-h, --help Show this help page and exit
--version Print the version and exit
-v, --verbose Increase command output (repeatable)
-q, --quiet Decrease command output (repeatable)
-d, --dry-run Print the task contents but don't actually run it
-C PATH, --directory PATH
Specify where to find the pyproject.toml
-e EXECUTOR, --executor EXECUTOR
Override the default task executor
--ansi Force enable ANSI output
--no-ansi Force disable ANSI output

Configured tasks:
types Run the type checker
lint Run linting tools on the code base
style Validate black code style
test Run unit tests
check Run all checks on the code base
build Build module
publish Publish module
docs Build site documentation
docs-publish Publish site documentation
clean Remove all generated and temporary files
requirements Generate requirements.txt

```


Make Target list:

| Name | Comment |
| ----------------------- | ----------------------------------------------------------------------------------------------- |
| make install | Install project dependencies |
| make configure | Configure poetry |
| make tag | Create and push a tag based on current project version. This will launch github release action. |
| make next-patch-version | Increment patch version of the project. |
| | |

## Note on configuration of Poetry

To configure poetry, you could use `make configure`or run :

```bash
# virtualenvs under project folder
poetry config virtualenvs.in-project true

# install needed plugins
poetry self add poetry-plugin-export
poetry self add 'poethepoet[poetry_plugin]'

# update tooling
poetry run python -m pip install --upgrade pip
poetry run python -m pip install --upgrade setuptools
```

See also:
| Name | Comment |
| ------------ | ---------------------------- |
| make install | Install project dependencies |
| make lock | Lock project dependencies |
| | |

- https://python-poetry.org/docs/#installation
- https://poethepoet.natn.io/installation.html

Loading
Loading