Skip to content

My opinionated Cookiecutter template for beginning a Python application with Rye dependency management and other modern tooling.

License

Notifications You must be signed in to change notification settings

bcorfman/ryestart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ryestart

My opinionated Cookiecutter template for beginning a Python application with Rye dependency management and other modern tooling.

To be clear, this template is NOT for Python libraries.


Features


Assumptions

  • The template requires Mac OS X, Linux, or WSL2 on Windows with a quality Linux distro like Ubuntu. (WSL2/Ubuntu is what I use.)
  • Homebrew must be installed.

Quickstart

  • See Assumptions above.

  • Install Rye then Cookiecutter using rye tools install cookiecutter. This makes Cookiecutter available as a global tool. This is what I do.

    OR

  • Install the latest Cookiecutter using their instructions. This has the disadvantage of tying the tool to a system-level Python, or you can use something like pipx for an isolated install. However, this is yet another Python dependency manager that you will need to manage.

Now generate the project:

cookiecutter gh:bcorfman/ryestart

The setup does several things:

  • Prompts for a few needed project configuration details like Project/Repo name, Author name, email and desired Python version that will be installed by Rye.
  • Installs the GitHub CLI and/or Rye via Homebrew, if they aren't installed already.
  • Pulls your GitHub username and PAT from Git Credential Manager and uses them to authenticate to your account.
  • Checks for the existence of the Repo name on your GitHub account; if it's already there, the setup aborts with an error.
  • git init is called inside the project directory to create a Git repo.
  • make devinstall is executed to install some basic Python dev libraries: ipython, pytest and pytest-cov.
  • Finally, the configured project is committed to the new Git repo and pushed up to your GitHub repo as well.

Get inside the newly created project:

cd <repo_name>

Start working!


Can you modify how ryestart works? Yes!

ryestart is built the way I like it. But what if it's not configured the way you work?

  • One regular annoyance is that Cookiecutter will always prompt you for your name and your email ... Unless you like typing these over and over, the best thing is to create a .cookiecutterrc inside your home directory.

    For instance, my ~/.cookiecutterrc looks like this:

    default_context:
      author_name: "Brandon Corfman"
      author_email: "h9tbgnbbk@privaterelay.appleid.com"
    
  • If you want to install different default libraries inside your project besides the ones I've chosen, modify the devinstall section of the Makefile.

  • If you want to customize the entire setup process, take a look in post_gen_project.py.

  • Finally, since ryestart has a permissive license, fork the project and contribute back via a pull request, or turn that fork into a standalone repository and make the customizations your own.


Available Makefile tasks

make devinstall   # installs all project & development tooling. Executed by Cookiecutter in
                  #   post_gen_project.py hook.
make install      # installs project files only. No development toolking.
make run          # prints "Hello World" as a sample
make test         # tests that "Hello World" is printed
make lint         # automatically orders imports and fixes code issues with Ruff. 
                  # Linting is customized in pyproject.toml
make format       # Automatically formats your code and imports with Ruff. 
                  # Formatting is customized in pyproject.toml.

Directory structure

This is what your new project will look like:

├── .gitignore            <- A modest Python .gitignore customized for this project
├── LICENSE               <- The project's MIT license with your name.
├── README.md             <- The top-level README for developers using this project.
├── Makefile              <- Configure/build/formatting/test tasks that can be run from the command-line. 
├── main.py               <- The top-level application file.
├── pyproject.toml        <- Rye-compatible TOML file reproducing the development environment
│    
├── .vscode               <- Visual Studio Code configuration files
|   ├── extensions.json   <- VSCode extension recommendations that will make your development easier.
|   ├── launch.json       <- Configures VSCode to run and debug the project.
|   └── settings.json     <- Calls RunOnSave extension to format and lint the code whenever the project is saved.
|
├── core                  <- Core Python source files
|   ├── __init__.py       <- Makes the core directory a module that can be imported
|   └── hello.py          <- A starter submodule that prints "Hello World!"
|
└── tests                     
    ├── __init__.py       <- Makes the tests directory a module that can be imported
    └── test_hello.py     <- tests that "Hello World!" is printed by the core.hello module

About

My opinionated Cookiecutter template for beginning a Python application with Rye dependency management and other modern tooling.

Topics

Resources

License

Stars

Watchers

Forks