-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs simonw/python-lib#9
- Loading branch information
Showing
4 changed files
with
45 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ Use this template on your own machine with cookiecutter, or create a brand new r | |
## Installation | ||
|
||
You'll need to have [cookiecutter](https://cookiecutter.readthedocs.io/) installed. I recommend pipx for this: | ||
|
||
pipx install cookiecutter | ||
|
||
```bash | ||
pipx install cookiecutter | ||
``` | ||
Regular `pip` will work OK too. | ||
|
||
## Examples | ||
|
@@ -23,15 +23,15 @@ Three examples of tools that were initially created using this template: | |
## Usage | ||
|
||
Run `cookiecutter gh:simonw/click-app` and then answer the prompts. Here's an example run: | ||
|
||
$ cookiecutter gh:simonw/click-app | ||
app_name []: click app template demo | ||
description []: Demonstrating https://github.com/simonw/click-app | ||
hyphenated [click-app-template-demo]: | ||
underscored [click_app_template_demo]: | ||
github_username []: simonw | ||
author_name []: Simon Willison | ||
|
||
``` | ||
$ cookiecutter gh:simonw/click-app | ||
app_name []: click app template demo | ||
description []: Demonstrating https://github.com/simonw/click-app | ||
hyphenated [click-app-template-demo]: | ||
underscored [click_app_template_demo]: | ||
github_username []: simonw | ||
author_name []: Simon Willison | ||
``` | ||
I strongly recommend accepting the suggested value for "hyphenated" and "underscored" by hitting enter on those prompts. | ||
|
||
This will create a directory called `click-app-template-demo` - the tool name you enter is converted to lowercase and uses hyphens instead of spaces. | ||
|
@@ -43,50 +43,50 @@ See https://github.com/simonw/click-app-template-demo for the output of this exa | |
Having created the new structure from the template, here's how to start working on the tool. | ||
|
||
If your tool is called `my-new-tool`, you can start working on it like so: | ||
|
||
cd my-new-tool | ||
# Create and activate a virtual environment: | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
# Install dependencies so you can edit the project: | ||
pip install -e '.[test]' | ||
# With zsh you have to run this again for some reason: | ||
source venv/bin/activate | ||
# Confirm your tool can be run from the command-line | ||
my-new-tool --version | ||
|
||
```bash | ||
cd my-new-tool | ||
# Create and activate a virtual environment: | ||
python -m venv venv | ||
source venv/bin/activate | ||
# Install dependencies so you can edit the project: | ||
pip install -e '.[test]' | ||
# With zsh you have to run this again for some reason: | ||
source venv/bin/activate | ||
# Confirm your tool can be run from the command-line | ||
my-new-tool --version | ||
``` | ||
You should see the following: | ||
|
||
my-new-tool, version 0.1 | ||
|
||
```bash | ||
my-new-tool, version 0.1 | ||
``` | ||
You can run the default test for your tool like so: | ||
|
||
pytest | ||
|
||
```bash | ||
python -m pytest | ||
``` | ||
This will execute the test in `tests/test_my_new_tool.py`. | ||
|
||
Now you can open the `my_new_tool/cli.py` file and start adding Click [commands and groups](https://click.palletsprojects.com/en/7.x/commands/). | ||
|
||
## Creating a Git repository for your tool | ||
|
||
You can initialize a Git repository for your tool like this: | ||
|
||
cd my-new-tool | ||
git init | ||
git add . | ||
git commit -m "Initial structure from template" | ||
# Rename the 'master' branch to 'main': | ||
git branch -m master main | ||
|
||
```bash | ||
cd my-new-tool | ||
git init | ||
git add . | ||
git commit -m "Initial structure from template" | ||
# Rename the 'master' branch to 'main': | ||
git branch -m master main | ||
``` | ||
## Publishing your tool to GitHub | ||
|
||
Use https://github.com/new to create a new GitHub repository sharing the same name as your tool, which should be something like `my-new-tool`. | ||
|
||
Push your `main` branch to GitHub like this: | ||
|
||
git remote add origin [email protected]:YOURNAME/my-new-tool.git | ||
git push -u origin main | ||
|
||
```bash | ||
git remote add origin [email protected]:YOURNAME/my-new-tool.git | ||
git push -u origin main | ||
``` | ||
The template will have created a GitHub Action which runs your tool's test suite against every commit. | ||
|
||
## Publishing your cool as a package to PyPI | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,5 @@ jobs: | |
pip install '.[test]' | ||
- name: Run tests | ||
run: | | ||
pytest | ||
python -m pytest | ||
{% endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,5 @@ pip install -e '.[test]' | |
``` | ||
To run the tests: | ||
```bash | ||
pytest | ||
python -m pytest | ||
``` |
d200c0d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Demo: https://github.com/simonw/click-app-template-demo/tree/722501d6