Package: d8s-python
Democritus PythonDemocritus functions[1]for working with Python data (code and ASTs).[1] Democritus functions aresimple, effective, modular, well-tested, and well-documentedPython functions.We used8s(pronounced "dee-eights") as an abbreviation fordemocritus(you can read more about thishere).Installationpip install d8s-pythonUsageYou import the library like:fromd8s_pythonimport*Once imported, you can use any of the functions listed below.Functionsdefpython_functions_signatures(code_text:str,*,ignore_private_functions:bool=False,ignore_nested_functions:bool=False,keep_function_name:bool=False,)->List[str]:"""Return the function signatures for all of the functions in the given code_text."""defpython_todos(code_text:str,todo_regex:str='TODO:.*')->List[str]:"""Return all todos in the given code_text that match the given todo_regex."""defpython_make_pythonic(name:str)->str:"""Make the name pythonic.(e.g. 'fooBar' => 'foo_bar', 'foo-bar' => 'foo_bar', 'foo bar' => 'foo_bar', 'Foo Bar' => 'foo_bar')."""defpython_namespace_has_argument(namespace:argparse.Namespace,argument_name:str)->bool:"""."""defpython_traceback_prettify(traceback:str)->str:"""Return a string with the given traceback pretty-printed."""defpython_traceback_pretty_print(traceback:str)->None:"""Return a string with the given traceback pretty-printed."""defpython_clean(code_text:str)->str:"""Clean python code as it is often found in documentation and snippets."""defpython_function_blocks(code_text:str,*,ignore_private_functions:bool=False,ignore_nested_functions:bool=False)->List[str]:"""Find the code (as a string) for every function in the given code_text."""defpython_line_count(python_code:str,*,ignore_empty_lines:bool=True)->int:"""Return the number of lines in the given function_text."""defpython_function_lengths(code_text:str)->List[int]:"""Find the lengths of each function in the given code_text."""defpython_version()->str:"""Return the python version of the current environment."""defpython_is_version_2()->bool:"""Return whether or not the python version of the current environment is v2.x."""defpython_is_version_3()->bool:"""Return whether or not the python version of the current environment is v3.x."""defpython_files_using_function(function_name:str,search_path:str)->List[str]:"""Find where the given function is used in the given search path."""defpython_keywords()->List[str]:"""Get a list of the python keywords."""defpython_object_properties_enumerate(python_object:Any,*,run_methods:bool=True,internal_properties:bool=True)->None:"""Enumerate and print out the properties of the given object."""defpython_copy_deep(python_object:Any)->Any:"""Return a deep (complete, recursive) copy of the given python object."""defpython_copy_shallow(python_object:Any)->Any:"""Return shallow copy of the given python object."""defpython_file_names(path:str,*,exclude_tests:bool=False)->List[str]:"""Find all python files in the given directory."""defpython_fstrings(code_text:str,*,include_braces:bool=False)->Iterator[str]:"""Find all of the python formatted string literals in the given text. See https://realpython.com/python-f-strings/ for more details about f-strings."""defpython_code_details(code_text:str):"""Get details about the given code_text. This is a wrapper for `dis.code_info`"""defpython_disassemble(code_text:str):"""Disassemble the python code_text. This is a wrapper for `dis.dis`"""defpython_stack_local_data():"""Get local data in the current python environment."""defpython_object_doc_string(python_object:Any)->Union[str,None]:"""Get the doc string for the given python object (e.g. module, function, or class)."""defpython_object_source_file(python_object:Any)->str:"""Get the source file for the given python object (e.g. module, function, or class)."""defpython_object_module(python_object:Any)->str:"""Get the module for the given python object (e.g. function or class)."""defpython_object_source_code(python_object:Any)->str:"""Get the source code for the given python object (e.g. module, function, or class)."""defpython_object_signature(python_object:Any)->str:"""Get the argument signature for the given python object (e.g. module, function, or class)."""defpython_sort_type_list_by_name(python_type_list:List[type],**kwargs)->List[type]:"""."""defpython_type_name(python_type:type)->str:"""Return the common name of the given type."""defpython_object_type_to_word(python_object:Any)->str:"""Convert the given python type to a string."""defpython_ast_raise_name(node:ast.Raise)->Optional[str]:"""Get the name of the exception raise by the given ast.Raise object."""defpython_ast_exception_handler_exceptions_handled(handler:ast.ExceptHandler)->Optional[Iterable[str]]:"""Return all of the exceptions handled by the given exception handler."""defpython_ast_exception_handler_exceptions_raised(handler:ast.ExceptHandler)->Optional[Iterable[str]]:"""Return the exception raised by the given exception handler."""defpython_exceptions_handled(code_text:str)->Iterable[str]:"""Return a list of all exceptions handled in the given code."""defpython_exceptions_raised(code_text:str)->Iterable[str]:"""Return a list of all exceptions raised in the given code."""defpython_functions_as_import_string(code_text:str,module_name:str)->str:"""."""defpython_ast_object_line_number(ast_object:object)->Optional[int]:"""."""defpython_ast_object_line_numbers(ast_object:object)->Tuple[int,int]:"""."""defpython_ast_objects_of_type(code_text_or_ast_object:Union[str,object],ast_type:type,*,recursive_search:bool=True)->Iterable[object]:"""Return all of the ast objects of the given ast_type in the code_text_or_ast_object."""defpython_ast_objects_not_of_type(code_text_or_ast_object:Union[str,object],ast_type:type)->Iterable[object]:"""Return all of the ast objects which are not of the given ast_type in the code_text_or_ast_object."""defpython_ast_parse(code_text:str)->ast.Module:"""."""defpython_ast_function_defs(code_text:str,recursive_search:bool=True)->Iterable[ast.FunctionDef]:"""."""defpython_function_arguments(function_text:str)->List[ast.arg]:"""."""defpython_function_argument_names(function_text:str)->Iterable[str]:"""."""defpython_function_argument_defaults(function_text:str)->List[str]:"""."""defpython_function_argument_annotations(function_text:str)->List[str]:"""."""defpython_function_names(code_text:str,*,ignore_private_functions:bool=False,ignore_nested_functions:bool=False)->List[str]:"""."""defpython_function_docstrings(code_text:str,*,ignore_private_functions:bool=False,ignore_nested_functions:bool=False)->List[str]:"""Get docstrings for all of the functions in the given text."""defpython_variable_names(code_text:str)->List[str]:"""Get all of the variables names in the code_text."""defpython_constants(code_text:str)->List[str]:"""Get all constants in the code_text."""Development👋  If you want to get involved in this project, we have some short, helpful guides below:contribute to this project 🥇test it 🧪lint it 🧹explore it 🔭If you have any questions or there is anything we did not cover, please raise an issue and we'll be happy to help.CreditsThis package was created withCookiecutterand Floyd Hightower'sPython project template.