1
1
"""The command line interface to the babelizer."""
2
+
2
3
import fnmatch
3
4
import os
4
5
import pathlib
6
+ import sys
5
7
import tempfile
6
8
from functools import partial
7
9
8
10
import click
9
11
import git
10
- import pkg_resources
12
+
13
+ if sys .version_info >= (3 , 12 ): # pragma: no cover (PY12+)
14
+ import importlib .resources as importlib_resources
15
+ else : # pragma: no cover (<PY312)
16
+ import importlib_resources
17
+
11
18
12
19
from .errors import OutputDirExistsError , ScanError , SetupPyError , ValidationError
13
20
from .metadata import BabelMetadata
@@ -70,7 +77,7 @@ def init(meta, template, quiet, verbose, package_version):
70
77
META is babelizer configuration information, usually saved to a file.
71
78
"""
72
79
output = pathlib .Path ("." )
73
- template = template or pkg_resources . resource_filename ("babelizer" , "data" )
80
+ template = template or str ( importlib_resources . files ("babelizer" ) / "data" )
74
81
75
82
if not quiet :
76
83
out (f"reading template from { template } " )
@@ -138,7 +145,7 @@ def update(template, quiet, verbose):
138
145
err ("this does not appear to be a babelized folder (missing 'babel.yaml')" )
139
146
raise click .Abort ()
140
147
141
- template = template or pkg_resources . resource_filename ("babelizer" , "data" )
148
+ template = template or str ( importlib_resources . files ("babelizer" ) / "data" )
142
149
143
150
if not quiet :
144
151
out (f"reading template from { template } " )
@@ -359,9 +366,7 @@ def ask_until_done(text):
359
366
}
360
367
361
368
libraries = {}
362
- if (not prompt ) or any (
363
- [x is not None for x in (name , library , header , entry_point )]
364
- ):
369
+ if (not prompt ) or any (x is not None for x in (name , library , header , entry_point )):
365
370
babelized_class = name or ask ("Name of babelized class" , default = "<name>" )
366
371
libraries [babelized_class ] = {
367
372
"language" : language ,
@@ -385,11 +390,13 @@ def ask_until_done(text):
385
390
libraries [babelized_class ] = {
386
391
"language" : language ,
387
392
"library" : ask (f"[{ babelized_class } ] Name of library to babelize" ),
388
- "header" : ask (
389
- f"[{ babelized_class } ] Name of header file containing BMI class "
390
- )
391
- if language != "python"
392
- else "__UNUSED__" ,
393
+ "header" : (
394
+ ask (
395
+ f"[{ babelized_class } ] Name of header file containing BMI class "
396
+ )
397
+ if language != "python"
398
+ else "__UNUSED__"
399
+ ),
393
400
"entry_point" : ask (f"[{ babelized_class } ] Name of BMI class " ),
394
401
}
395
402
if not yes ("Add another library?" , default = False ):
0 commit comments