Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit abd9395

Browse files
committed
early check for bad package name
1 parent 068dbfb commit abd9395

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/dls_python3_skeleton/__main__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"https://github.com/dls-controls/versiongit",
2727
),
2828
}
29+
VALID_PKG = re.compile("[a-zA-Z][a-zA-Z_0-9]*$")
2930

3031

3132
def git(*args, cwd=None) -> str:
@@ -58,7 +59,7 @@ def merge_skeleton(
5859
path = path.resolve()
5960
repo = path.name
6061
package = override_package or repo
61-
valid = re.match("[a-zA-Z][a-zA-Z_0-9]*$", package)
62+
valid = VALID_PKG.match(package)
6263
assert valid, f"'{package}' is not a valid python package name"
6364

6465
def replace_text(text: str) -> str:
@@ -125,6 +126,11 @@ def replace_text(text: str) -> str:
125126

126127
def new(args):
127128
path: Path = args.path
129+
130+
package = path.name
131+
valid = VALID_PKG.match(package)
132+
assert valid, f"'{package}' is not a valid python package name"
133+
128134
if path.exists():
129135
assert path.is_dir() and not list(
130136
path.iterdir()

0 commit comments

Comments
 (0)