Skip to content

Commit e3dd79e

Browse files
authored
Ensure project names with dashes are converted for python code (#21)
* ensure python package name is compliant * update to include py 3.14 in tests for template * Update .pre-commit-config.yaml
1 parent 16849bb commit e3dd79e

13 files changed

Lines changed: 26 additions & 20 deletions

.github/workflows/run-tests.yml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run_tests:
2929
strategy:
3030
matrix:
31-
python_version: ["3.10", "3.11", "3.12", "3.13"]
31+
python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
3232
os: [ubuntu-24.04, macos-14]
3333
runs-on: ${{ matrix.os }}
3434
env:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ repos:
3434
additional_dependencies:
3535
- mdformat-gfm
3636
- repo: https://github.com/adrienverge/yamllint
37-
rev: v1.37.1
37+
rev: v1.38.0
3838
hooks:
3939
- id: yamllint
4040
exclude: pre-commit-config.yaml
4141
- repo: https://github.com/astral-sh/ruff-pre-commit
42-
rev: "v0.14.11"
42+
rev: "v0.14.13"
4343
hooks:
4444
- id: ruff-format
4545
- id: ruff-check

copier.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ project_name:
44
help: >-
55
What is the name of your project?
66
This will be used in the package name
7-
and other places. Please use "_"
8-
underscores instead of spaces where
9-
necessary, e.g. "my_project".
7+
and other places. Dashes will be converted
8+
to underscores for the Python package/module
9+
name (e.g. "my-project" -> "my_project").
1010
1111
project_description:
1212
type: str
@@ -15,6 +15,11 @@ project_description:
1515
This will be used in the package metadata
1616
and other places.
1717
18+
python_package_name:
19+
type: str
20+
default: "{{ project_name|replace('-', '_') }}"
21+
when: false
22+
1823
author_name:
1924
type: str
2025
default: "Your Name"

docs/src/python-api.md.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Python API
22

33
```{eval-rst}
4-
{{ project_name }}.main
4+
{{ python_package_name }}.main
55
-------------------
6-
.. automodule:: src.{{ project_name }}.main
6+
.. automodule:: src.{{ python_package_name }}.main
77
:members:
88
:private-members:
99
:undoc-members:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ pythonpath = [ "." ]
6262

6363
[tool.vulture]
6464
min_confidence = 90
65-
paths = [ "src/{{ project_name }}", "tests" ]
65+
paths = [ "src/{{ python_package_name }}", "tests" ]

pyproject.toml.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies = [
2222
"fire>=0.7.0",
2323
"jinja2>=3.1.6",
2424
]
25-
scripts.{{ project_name }} = "{{ project_name }}.cli:trigger"
25+
scripts.{{ project_name }} = "{{ python_package_name }}.cli:trigger"
2626

2727
[dependency-groups]
2828
dev = [
@@ -46,7 +46,7 @@ notebooks = [
4646
root = "."
4747
version_scheme = "no-guess-dev"
4848
local_scheme = "no-local-version"
49-
version_file = "src/{{ project_name }}/_version.py"
49+
version_file = "src/{{ python_package_name }}/_version.py"
5050

5151
[tool.ruff]
5252
target-version = "py311"
@@ -95,4 +95,4 @@ formats = "ipynb,py:light"
9595

9696
[tool.vulture]
9797
min_confidence = 90
98-
paths = [ "src/{{ project_name }}", "tests" ]
98+
paths = [ "src/{{ python_package_name }}", "tests" ]

src/notebooks/example_notebook.ipynb.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"outputs": [],
3232
"source": [
3333
"# show an import from a local package\n",
34-
"from {{ project_name }} import show_message"
34+
"from {{ python_package_name }} import show_message"
3535
]
3636
},
3737
{

src/notebooks/example_notebook.py.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# Clicking it applies the formatting to the notebook.
3131

3232
# show an import from a local package
33-
from {{ project_name }} import show_message
33+
from {{ python_package_name }} import show_message
3434

3535
# use the function within the notebook to show it works
3636
show_message("Hello, notebook!")

src/{{ project_name }}/cli.py.jinja renamed to src/{{ python_package_name }}/cli.py.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
CLI for nviz
2+
CLI for {{ python_package_name }}
33
"""
44

55
import fire
66

7-
from {{ project_name }}.main import show_message
7+
from {{ python_package_name }}.main import show_message
88

99

10-
class {{ project_name }}CLI:
10+
class {{ python_package_name }}CLI:
1111
def show_message(
1212
self,
1313
message: str = "Hello, world!",
@@ -33,4 +33,4 @@ def trigger() -> None:
3333
"""
3434
Trigger the CLI to run.
3535
"""
36-
fire.Fire({{ project_name }}CLI)
36+
fire.Fire({{ python_package_name }}CLI)

0 commit comments

Comments
 (0)