Skip to content

A Copier template for Python projects that uses Rye as package manager.

License

Notifications You must be signed in to change notification settings

montanarograziano/copier-rye

Repository files navigation

rye-managed pre-commit enabled documentation mkdocs

copier-rye is a Copier template ideated to speed up the development process of Python applications. No more configuration hassle and boilerplate!

⚡ Features

copier-rye offers a production-ready development environment, with many useful features like formatting, linting, pre-commit hooks, and documentation already set up. Here's an overview of the features:

  • rye is a comprehensive project and package management solution for Python.
  • just is a modern rewrite of make in Rust 🦀
  • pre-commit validates your commits.
  • ruff provides static code analysis and a code and import formatting using black and isort styles.
  • mypy validates your type hints.
  • pytest runs your test suite.
  • mkdocs builds your documentation, while mkdocs-material provides an elegant theme. mike takes care of versioning your docs.
  • commitizen ensures you follow Conventional commit style and generates your release changelogs according to SemVer

Note

Developer guidelines

  • The template adopts to the src layout.
  • mypy is configured with a strict ruleset. The recommended approach to loosen those constraints is by temporary per-module ignores.
  • google is the docstring style of choice.
  • ruff is used to format the code using black style, while imports are sorted with isort style.
  • Releases follow Semantic Versioning.
  • Commit follow the Conventional Commit specification.

Note

just a command runner

just recipes will save you a ton of time! Install just. To see the available recipes, run the following:

just

🛠️ How to

Install rye and just:

curl -sSf https://rye-up.com/get | bash # For Linux/ Mac Users

# for example, on macOS
brew install just

Optional: Install uv

For blazingly fast dependency install you can set rye to use uv under the hood when retrieving dependencies: First of all, install uv.

pipx install uv

Warning

🔎 Why pipx? pip install --user is not recommended, as it does not ensure dependency isolation. For this purpose, the Python Packaging Authority (PyPA) advises to use pipx. pipx installs and runs python CLIs in isolated environments. To install it, follow the instructions here.

Then, configure rye to use uv:

rye config --set-bool behavior.use-uv=true

Create a New Project

If you want to create a new package, or any coding project, you just have to run two short commands.

  1. Initialise the template:
copier copy --trust gh:montanarograziano/copier-rye my-project
  1. Initialize GitHub repository locally (necessary to install pre-commit hooks) and install all default dependencies, running the following just recipe:
just init

For this command to execute successfully, you need to have rye and the Git installed.

If you do not want to configure CI/CD on GitHub, you can simply run the following:

just install

🙋 FAQ

How do I write conventional commits?

Conventional commits are enforced with commitizen, which is configured as a pre-commit hook at pre-push time. In other words, if you attempt to push to a remote repo and your commit messages do not follow the conventional commits, the push will be rejected. However, commitizen also offers a git command to commit with the conventional commit specification with a terminal UI. With just, you can simply run the following:

just commit

Or even the shorter just c. A prompt will guide you through the commit.

📝 Template fields

{
  "project_name": "",
  "project_description": "",
  "author_fullname": "",
  "author_email": "",
  "author_username": "",
  "repository_provider": "",
  "repository_namespace": "",
  "repository_name": "",
  "copyright_holder": "",
  "copyright_holder_email": "",
  "copyright_date": "",
  "copyright_license": "",
  "ensure_python_version": "3.10",
  "python_package_distribution_name": "",
  "python_package_import_name": ""

}
  • project_name: the name of the project indicated in pyproject.toml.
  • project_description: the description of the project indicated in pyproject.toml.
  • author_fullname: the author full name.
  • author_email: the author email address.
  • repository_provider: the repository provider (e.g., GitHub, GitLab, BitBucket). Only GitHub is supported for now.
  • repository_namespace: the repository namespace.
  • package_name: the package name.
  • copyright_license: the selected license.
  • ensure_python_version: the minimal python version required for the project.
  • python_package_distribution_name: the Python package distribution name (for pip install NAME).
  • python_package_import_name: the Python package import name (for import NAME in Python code)

🤗 Contributing

PR and issues are always accepted, especially since this project is far from being mature.

Development

  1. Install rye and just.

  2. Clone the repository:

# using github cli
gh repo clone montanarograziano/copier-rye

# using git (SSH recommended)
git clone [email protected]:montanarograziano/copier-rye
  1. Install the dependencies:
just install

Before submitting a PR

Run the following:

just pre-release

The following operations will be performed:

  1. Format with black and isort.
  2. Lint with ruff.
  3. Run type checks with mypy.
  4. Audit dependencies with pip-audit.
  5. Check commit messages are consistent with Conventional Commits using commitizen.
  6. Check whether a version bump is possible.
  7. Run all tests.

📚 Credits

This template is heavly inspired by @baggiponte Chef (based on Cookiecutter) and @pawamoy copier-uv (based on Copier). They use respectively pdm and uv as packaging solution. Both are very well done and works great, and so...

Why bother creating (yet another) template?

As of today, it seems that there are no Copier templates that uses rye, given the novelty of the project. Furthermore, sometimes a feature is not implemented in any available template or you need a custom one.

Personally, I believe that leveraging templating to abstract on stuff like dependency manager, is a possible solution: give the user many choices and let him decide which one suits him best.

Feel free to contact to discuss more about this topic!

About

A Copier template for Python projects that uses Rye as package manager.

Resources

License

Stars

Watchers

Forks

Packages

No packages published