Skip to content

Commit ca5178e

Browse files
committed
Added short usage sequence.
Added src dir Added __main__.py Removed hyphen from project name
1 parent 2f3aefe commit ca5178e

File tree

6 files changed

+88
-7
lines changed

6 files changed

+88
-7
lines changed

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@
33
[Copier](https://copier.readthedocs.io/) is a library for rendering project templates, which lives at [github.com/copier-org/copier](https://github.com/copier-org/copier/).
44
[Poetry](https://python-poetry.org/) makes Python packaging and dependency management easy using pyproject.toml, and lives at [github.com/python-poetry/poetry](https://github.com/python-poetry/poetry/)
55

6-
This copier template is my first attempt at using these two tools togehter to make creating new Python projects easier.
6+
This copier template is my first attempt at using these two tools togehter to make creating new Python projects easier on Windows.
77

88
## Usage
99

10+
I'm more of a traditionalist and want the virtual environment files in a .venv directory in each project, so I have done:
11+
``` shell
12+
PS C:\> poetry config virtualenvs.in-project true
13+
```
14+
This will globally configure poetry to do so and will let me do the following:
15+
16+
``` shell
17+
PS C:\> copier https://github.com/Cecron/copier-python.git myproj
18+
PS C:\> cd myproj
19+
PS C:\> poetry install
20+
PS C:\> py -3 -m venv .\.venv\ --prompt . # Set virtual env prompt to show directory name
21+
PS C:\> .venv\Scripts\activate.ps1
22+
```
23+
24+
1025
To give a basic understanding of how to create and use a copier template, I'll show how the first versions of this template was created, including how to apply the template to both generate a new project and also how to update the project whith a an improved version of the template.
1126

1227
### Create a directory to place the template in
@@ -44,7 +59,7 @@ pytest = "^5.2"
4459

4560
``` shell
4661
PS C:\copier-template> type copier.yaml
47-
package_name: my-package
62+
package_name: mypackage
4863
package_description: A short description of the package.
4964
author_name: Cecron
5065
author_email: Cecron@example.com
@@ -81,7 +96,7 @@ PS C:\copier-template> cd ..
8196
PS C:\> copier copier-template myproj
8297
# Answer questions
8398
package_name? Format: yaml
84-
🎤 [my-package]:
99+
🎤 [mypackage]:
85100

86101
package_description? Format: yaml
87102
🎤 [A short description of the package.]:
@@ -147,7 +162,7 @@ PS C:\copier-template> cd ..
147162
PS C:\> copier update myproj
148163

149164
package_name? Format: yaml
150-
🎤 [my-package]:
165+
🎤 [mypackage]:
151166

152167
package_description? Format: yaml
153168
🎤 [A short description of the package.]:

README.md.tmpl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [[ package_name ]]
2+
3+
[[ package_description ]]
4+
5+
## Installation
6+
7+
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install foobar.
8+
9+
```shell
10+
pip install [[package_name]]
11+
```
12+
13+
## Usage
14+
15+
Use from within your Python code:
16+
17+
```python
18+
import [[ package_name ]]
19+
20+
...
21+
```
22+
23+
Use from command-line:
24+
25+
```shell
26+
[[ package_name ]]
27+
# or
28+
python -m [[ package_name ]]
29+
# or
30+
poetry run [[ package_name ]]
31+
32+
```
33+
34+
## Description
35+
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
36+
37+
## Visuals
38+
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
39+
40+
41+
42+
## Contributing
43+
State if you are open to contributions and what your requirements are for accepting them.
44+
45+
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
46+
47+
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
48+
49+
## Authors and acknowledgment
50+
[[ author_name ]] <[[ author_email ]]>
51+
52+
## License
53+
[[ copyright_license ]]
54+

copier.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package_name: my-package
1+
package_name: mypackage
22
package_description: A short description of the package.
33
author_name: Cecron
44
author_email: Cecron@example.com
55
copyright_license: "CC-BY-4.0"
66

77
_exclude:
88
- ".git"
9-
- "README.md"
109
# Don't match emacs backup files
1110
- "*~"

pyproject.toml.tmpl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@ description = "[[ package_description ]]"
99
authors = ["[[ author_name ]] <[[ author_email ]]>"]
1010
maintainers = ["[[ author_name ]] <[[ author_email ]]>"]
1111
license = "[[ copyright_license ]]"
12-
readme = "README.rst"
12+
readme = "README.md"
13+
packages = [
14+
{ include = "[[ package_name ]]", from = "src" },
15+
]
1316

1417
[tool.poetry.dependencies]
1518
python = "^3.8"
1619

1720
[tool.poetry.dev-dependencies]
1821
pytest = "^5.2"
22+
23+
[tool.poetry.scripts]
24+
[[ package_name ]] = "[[ package_name ]].app:main"

src/[[ package_name ]]/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import app
2+
3+
app.main()

src/[[ package_name ]]/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
def main():
4+
print("Hello world")

0 commit comments

Comments
 (0)