66import argparse
77from pathlib import Path
88import re
9+ import types
910from typing import Tuple
1011import ast
1112import inspect
1213from textwrap import dedent
14+ from addict import Addict as Container
1315
1416try :
1517 # this will be part of standard library for python >= 3.11
1618 import tomllib
1719except ModuleNotFoundError :
18- import tomli as tomllib
20+ import tomli as tomllib # type: ignore
1921
2022import platformdirs
2123
3436
3537def create_parser ():
3638 """
37- Returns the parser object which is then evaluated in main(). This is necessary for sphinx to automatically
38- generate the cli docs.
39+ Returns the parser object which is then evaluated in main(). This is necessary for sphinx to
40+ automatically generate the cli docs.
3941 """
4042
4143 parser = argparse .ArgumentParser (
@@ -173,6 +175,15 @@ def create_parser():
173175 action = "store_true" ,
174176 )
175177
178+ parser .add_argument (
179+ "--refactor-entity-label" ,
180+ help = "change main label of entity in source file of loaded module. "
181+ "Recommended: Apply ony to clean git repo." ,
182+ nargs = 2 ,
183+ metavar = ("key" , "new label" )
184+ )
185+
186+
176187 return parser
177188
178189
@@ -183,6 +194,13 @@ def main():
183194 debug ()
184195 exit ()
185196
197+ if args .refactor_entity_label :
198+ from . import refactor_tools as rt
199+ assert args .inputfile is not None
200+ assert len (args .refactor_entity_label ) == 2
201+ rt .change_entity_label (* args .refactor_entity_label , args .inputfile )
202+ exit ()
203+
186204 if args .version :
187205 print (release .__version__ )
188206 exit ()
@@ -235,15 +253,15 @@ def main():
235253 visualization .visualize_entity (uri , write_tmp_files = True )
236254 elif args .start_django :
237255 try :
238- import pyirkdjango .core
256+ import pyirkdjango .core # type: ignore
239257 except ImportError :
240258 print (aux .bred ("Error:" ), "the module pyirkdjango seems not to be installed." )
241259 # exit(10)
242260 raise
243261 pyirkdjango .core .start_django ()
244262 elif args .start_django_shell :
245263 try :
246- import pyirkdjango .core
264+ import pyirkdjango .core # type: ignore
247265 except ImportError :
248266 print (aux .bred ("Error:" ), "the module pyirkdjango seems not to be installed." )
249267 # exit(10)
@@ -259,7 +277,7 @@ def main():
259277 print ("nothing to do, see option `--help` for more info" )
260278
261279
262- def process_package (pkg_path : str ) -> Tuple [irkloader .ModuleType , str ]:
280+ def process_package (pkg_path : str ) -> Tuple [types .ModuleType , str ]:
263281 if os .path .isdir (pkg_path ):
264282 pkg_path = os .path .join (pkg_path , "irkpackage.toml" )
265283
@@ -273,7 +291,7 @@ def process_package(pkg_path: str) -> Tuple[irkloader.ModuleType, str]:
273291 return mod , main_module_prefix
274292
275293
276- def process_mod (path : str , prefix : str , relative_to_workdir : bool = False ) -> irkloader .ModuleType :
294+ def process_mod (path : str , prefix : str , relative_to_workdir : bool = False ) -> types .ModuleType :
277295 if not relative_to_workdir :
278296 msg = "using mod paths which are not relative to workdir is deprecated since pyirk version 0.6.0"
279297 raise DeprecationWarning (msg )
@@ -522,7 +540,7 @@ def process_template(template_path):
522540 return rendered_template
523541
524542
525- def path_to_ast_container (mod_path : str ) -> core . aux . Container :
543+ def path_to_ast_container (mod_path : str ) -> Container :
526544
527545 with open (mod_path ) as fp :
528546 lines = fp .readlines ()
0 commit comments