Tutorial#

  1. Install cruft

    First, you need to create a virtualenv for the package project. Use your favorite method, or create a virtualenv for your new package like this:

    python3 -m venv ~/.virtualenvs/my.package
    

    Here, my.package is the name of the package that you’ll create.

Then install cruft:

$ cd ~/.virtualenvs/my.package
$ source bin/activate
$ python -m pip install cruft
  1. Generate Your Package

    Now it’s time to generate your Python package.

    Use cruft, pointing it at the cookiecutter-namespace-template repo:

    $ cruft create https://github.com/veit/cookiecutter-namespace-template.git
    

    You’ll be asked to enter a bunch of values to set the package up. If you don’t know what to enter, stick with the defaults.

  2. Create a Git Repo

    Go to your Git account and create a new repo named my.package, where my.package matches the [namespace.package] from your answers to running cookiecutter.

    Note

    If your venv folder is within your project folder, be sure to add the venv folder name to your .gitignore file.

    You will find one folder named after the [namespace.package]. Move into this folder, and then setup git to use your Git repo and upload the code:

    $ cd my.package
    $ git init .
    $ git add .
    $ git commit -m "Initial commit"
    $ git remote add origin git@example.org:MYUSERNAME/MY.PYCKAGE.git
    $ git push -u origin main
    

    Where MYUSERNAME and MY.PACKAGE are adjusted for your username and package name.

    You’ll need a ssh key to push the repo. You can generate a key or add an existing one.

  3. Install dev requirements

    You should still be in the folder containing the pyproject.toml file.

    Install the new project’s local development requirements:

    $ python -m pip install -e '.[dev]'
    
  4. Release on PyPI