|
2 years ago | |
---|---|---|
hooks | 2 years ago | |
{{cookiecutter.package_name}} | 2 years ago | |
README.md | 2 years ago | |
cookiecutter.json | 2 years ago | |
requirements.txt | 2 years ago |
This template allows you to easily setup new Python projects with the most important libraries and configuration files for managing dependencies and virtualenv, code formatting, debugging, testing, static code analysis and creating command-line interfaces.
This project is based on python-new-project, with a heavy amount of changes
The template will:
pyproject.toml
configuration file for managing project dependencies and virtual environments using PoetryREADME.md
README file.gitignore
fileThis is a cookiecutter template.
To use it, make sure you have at least Python 3.7 and git installed.
Then install cookiecutter
and poetry
via pip
:
pip install poetry --user
pip install cookiecutter --user
You can now create a new Python project by running:
cookiecutter <git-url>
This will take you to a project setup asking for:
package_display_name
- The name that will be used in README, documentation, etcpackage_name
- The Python package name and name of the project folder (will generate automatically)package_description
- The Python package descriptionpackage_command
- This will configure poetry to allow calling the package, package_name/console:entry_point
, via this command. Generally, this would be the same value as package_name
author_name
- The author of the packageauthor_email
- The email for the authorgit_branch
- The branch to utilize when performing git init -b <branch>
github_repo_name
- For documentation, such as URLs to the issue trackergithub_user_name
- For documentation, such as URLs to the issue trackerpython_version
- The Python version that should be defined in pyproject.toml
The generated structure looks like this:
└── package_name/
├── docs
│ ├── build
│ ├── make.bat
│ ├── Makefile
│ └── source
│ ├── conf.py
│ ├── dev
│ │ └── index.rst
│ ├── index.rst
│ └── user
│ └── index.rst
├── poetry.lock
├── pyproject.toml
├── README.md
├── src
│ └── package_name
│ ├── console.py
│ ├── __init__.py
│ └── logger.py
└── tests/
├── __init__.py
└── test_project.py
From here, you can install the current dependencies, if needed running poetry install
from within package_name
. We can run poetry shell
and package_name
to run the script.
The project includes pydantic to help with configuration and settings for projects.
The provided example console.py
allows for the following object:
>>> from package_name.console import Config
>>> config = Config()
>>> config
Config(api_key='EXAMPLEKEY', more_settings=SubModel(foo='bar'))
>>> config.more_settings.foo
'bar'
The config settings can be defined either through environment variables, such as the following:
API_KEY='MY_ACTUAL_KEY'
MORE_SETTINGS__FOO='OTHER'