diff --git a/README.md b/README.md index 2d100f7..906f854 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,14 @@ Use cases: ## Installation -*TODO* +### With pip from Github - ## Usage @@ -35,6 +33,7 @@ positional arguments: options: -h, --help show this help message and exit + -v, --version show program's version number and exit -l LOGLEVEL, --loglevel LOGLEVEL set log level, possible options: CRITICAL, ERROR, WARNING, INFO, DEBUG -n, --dry-run do not modify files, only show log diff --git a/dyn2py/__init__.py b/dyn2py/__init__.py index 39bad7e..ff473be 100644 --- a/dyn2py/__init__.py +++ b/dyn2py/__init__.py @@ -23,10 +23,15 @@ __all__ = [ "PythonNode", "DynamoFileException", "PythonNodeNotFoundException", + "PythonNodeException", "PythonFileException" ] +def __dir__(): + return __all__ + + def run(options: Options | None = None) -> None: """Run an extraction as from the command line @@ -49,6 +54,11 @@ def run(options: Options | None = None) -> None: """) ) + parser.add_argument("-v", "--version", + action="version", + version=f'{METADATA["Name"]} {METADATA["Version"]}' + ) + parser.add_argument("-l", "--loglevel", metavar="LOGLEVEL", choices=LOGLEVELS, diff --git a/dyn2py/files.py b/dyn2py/files.py index b811d1c..2862927 100644 --- a/dyn2py/files.py +++ b/dyn2py/files.py @@ -110,21 +110,18 @@ class File(): """ return bool(self.extension == ".py") - def write(self, options: Options | None = None) -> None: + def write(self, options: Options = Options()) -> None: """Prepare writing file to the disk: create backup, process dry-run, call filetype specific write_file() methods Should be called on subclasses! Args: - options(Options | None, optional): Run options. Defaults to None. + options(Options, optional): Run options. Defaults to Options(). Raises: TypeError: If called on a File object """ - if not options: - options = Options() - # This should only work on subclasses: if type(self).__name__ == "File": raise TypeError("This method shouldn't be called on File objects!") @@ -169,16 +166,13 @@ class DynamoFile(File): open_files: set[DynamoFile] = set() """A set of open Dynamo files, before saving. Self added by read()""" - def extract_python(self, options: Options | None = None) -> None: + def extract_python(self, options: Options = Options()) -> None: """Extract and write python files Args: - options(Options | None, optional): Run options. Defaults to None. + options(Options, optional): Run options. Defaults to Options(). """ - if not options: - options = Options() - logging.info(f"Extracting from file: {self.filepath}") # Go through nodes in the file: @@ -314,17 +308,15 @@ class DynamoFile(File): with open(self.filepath, "w", encoding="utf-8", newline="") as output_file: json.dump(self.full_dict, output_file, indent=2, use_decimal=True) - def get_related_python_files(self, options: Options | None = None) -> list["PythonFile"]: + def get_related_python_files(self, options: Options = Options()) -> list["PythonFile"]: """Get python files exported from this Dynamo file Args: - options(Options | None, optional): Run options. Defaults to None. + options(Options, optional): Run options. Defaults to Options(). Returns: list[PythonFile]: A list of PythonFile objects """ - if not options: - options = Options() # Find the folder of the python files if options.python_folder: @@ -483,16 +475,13 @@ class PythonFile(File): logging.debug(f"Header data from python file: {self.header_data}") # logging.debug(f"Code from python file: {self.code}") - def update_dynamo(self, options: Options | None = None) -> None: + def update_dynamo(self, options: Options = Options()) -> None: """Update a the source Dynamo graph from this python script Args: - options (Options | None, optional): Run options. Defaults to None. + options (Options, optional): Run options. Defaults to Options(). """ - if not options: - options = Options() - dynamo_file = self.get_source_dynamo_file() new_python_node = PythonNode(python_file=self) diff --git a/pyproject.toml b/pyproject.toml index 518b7ea..bc37051 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "dyn2py" -version = "0.2.0" +version = "0.2.1" description = "Extract python code from Dynamo graphs" readme = "README.md" requires-python = ">=3.8"