2626 "https://github.com/dls-controls/versiongit" ,
2727 ),
2828}
29- VALID_PKG = re .compile ("[a-zA-Z][a-zA-Z_0-9]*$" )
3029
3130
3231def git (* args , cwd = None ) -> str :
@@ -54,13 +53,10 @@ def merge_skeleton(
5453 org : str ,
5554 full_name : str ,
5655 email : str ,
57- override_package : str = None ,
56+ package ,
5857):
5958 path = path .resolve ()
6059 repo = path .name
61- package = override_package or repo
62- valid = VALID_PKG .match (package )
63- assert valid , f"'{ package } ' is not a valid python package name"
6460
6561 def replace_text (text : str ) -> str :
6662 text = text .replace ("dls-controls" , org )
@@ -124,12 +120,16 @@ def replace_text(text: str) -> str:
124120 print ("Instructions on how to develop this module are in CONTRIBUTING.rst" )
125121
126122
123+ def validate_package (args ) -> str :
124+ package = args .package or args .path .name
125+ valid = re .match ("[a-zA-Z][a-zA-Z_0-9]*$" , package )
126+ assert valid , f"'{ package } ' is not a valid python package name"
127+ return package
128+
129+
127130def new (args ):
128131 path : Path = args .path
129-
130- package = args .package or path .name
131- valid = VALID_PKG .match (package )
132- assert valid , f"'{ package } ' is not a valid python package name"
132+ package = validate_package (args )
133133
134134 if path .exists ():
135135 assert path .is_dir () and not list (
@@ -144,12 +144,14 @@ def new(args):
144144 org = args .org ,
145145 full_name = args .full_name or git ("config" , "--get" , "user.name" ).strip (),
146146 email = args .email or git ("config" , "--get" , "user.email" ).strip (),
147- override_package = args . package ,
147+ package = package ,
148148 )
149149
150150
151151def existing (args ):
152152 path : Path = args .path
153+ package = validate_package (args )
154+
153155 assert path .is_dir (), f"Expected { path } to be an existing directory"
154156 conf = ConfigParser ()
155157 conf .read (path / "setup.cfg" )
@@ -158,7 +160,7 @@ def existing(args):
158160 org = args .org ,
159161 full_name = conf ["metadata" ]["author" ],
160162 email = conf ["metadata" ]["author_email" ],
161- override_package = args . package ,
163+ package = package ,
162164 )
163165
164166
0 commit comments