Skip to content

Commit f35d090

Browse files
committed
Update pre_gen_project.py
1 parent 6dfd190 commit f35d090

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

hooks/pre_gen_project.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import print_function
22
import sys
3+
import re
34

45
full_name = '{{cookiecutter.author_name}}'
56
email = '{{cookiecutter.author_email}}'
@@ -9,7 +10,7 @@
910
project_shortname_message = '''
1011
({variable}={value}) should be a valid Python package name.
1112
12-
Only lowercase letters and `_` are allowed.
13+
Only lowercase letters, numbers, and `_` are allowed, and the name must start with a non-numeric character.
1314
'''
1415

1516

@@ -23,18 +24,9 @@ def verify(check, variable_name, value, message):
2324
def package_check(s):
2425
return '(For package.json)' in s
2526

26-
27-
def _check_specials_characters(s):
28-
i = ord(s)
29-
if i == 95:
30-
# Allow for `_`
31-
return False
32-
return not 96 < i < 123
33-
34-
3527
def check_specials_characters(s):
36-
return any(_check_specials_characters(x) for x in s)
37-
28+
pattern = re.compile("^[a-z_][a-z_0-9]*")
29+
return not pattern.fullmatch(s)
3830

3931
for values in (
4032
(package_check, 'author_name', full_name, invalid_package_message),

0 commit comments

Comments
 (0)