treescript-builder 0.1.1__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {treescript_builder-0.1.1/treescript_builder.egg-info → treescript_builder-0.1.3}/PKG-INFO +1 -1
  2. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/setup.py +2 -2
  3. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/data/data_directory.py +6 -2
  4. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/data/path_stack.py +30 -27
  5. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/data/tree_state.py +11 -2
  6. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/__init__.py +1 -1
  7. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/argument_parser.py +24 -27
  8. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/file_validation.py +14 -14
  9. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/input_data.py +2 -2
  10. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/line_reader.py +8 -8
  11. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/string_validation.py +1 -1
  12. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/tree/build_validation.py +0 -4
  13. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/tree/tree_builder.py +2 -2
  14. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/tree/tree_trimmer.py +5 -6
  15. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/tree/trim_validation.py +0 -3
  16. {treescript_builder-0.1.1 → treescript_builder-0.1.3/treescript_builder.egg-info}/PKG-INFO +1 -1
  17. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/LICENSE +0 -0
  18. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/README.md +0 -0
  19. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/setup.cfg +0 -0
  20. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/__init__.py +0 -0
  21. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/__main__.py +0 -0
  22. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/data/__init__.py +0 -0
  23. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/data/instruction_data.py +0 -0
  24. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/data/tree_data.py +0 -0
  25. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/input/argument_data.py +0 -0
  26. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder/tree/__init__.py +0 -0
  27. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder.egg-info/SOURCES.txt +0 -0
  28. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder.egg-info/dependency_links.txt +0 -0
  29. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder.egg-info/entry_points.txt +0 -0
  30. {treescript_builder-0.1.1 → treescript_builder-0.1.3}/treescript_builder.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: treescript-builder
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Builds File Trees from TreeScript. If DataLabels are present in TreeScript, a DataDirectory argument is required.
5
5
  Home-page: https://github.com/DK96-OS/treescript-builder
6
6
  Author: DK96-OS
@@ -5,7 +5,7 @@ from setuptools import find_packages, setup
5
5
 
6
6
  setup(
7
7
  name="treescript-builder",
8
- version="0.1.1",
8
+ version="0.1.3",
9
9
  description='Builds File Trees from TreeScript. If DataLabels are present in TreeScript, a DataDirectory argument is required.',
10
10
  long_description=open('README.md').read(),
11
11
  long_description_content_type='text/markdown',
@@ -13,7 +13,7 @@ setup(
13
13
  url='https://github.com/DK96-OS/treescript-builder',
14
14
  project_urls={
15
15
  "Issues": "https://github.com/DK96-OS/treescript-builder/issues",
16
- "Source Code": "https://github.com/DK96-OS/treescript-builder"
16
+ "Source Code": "https://github.com/DK96-OS/treescript-builder",
17
17
  },
18
18
  license="GPLv3",
19
19
  packages=find_packages(exclude=['test', 'test.*']),
@@ -10,7 +10,11 @@ from treescript_builder.input.string_validation import validate_data_label
10
10
 
11
11
  class DataDirectory:
12
12
  """ Manages Access to the Data Directory.
13
- - Search for a Data Label, and obtain the Path to the Data File.
13
+ - Search for a Data Label, and obtain the Path to the Data File.
14
+
15
+ **Method Summary:**
16
+ - validate_build(TreeData): Path?
17
+ - validate_trim(TreeData): Path?
14
18
  """
15
19
 
16
20
  def __init__(self, data_dir: Path):
@@ -81,5 +85,5 @@ class DataDirectory:
81
85
  data_files = self._data_dir.glob(data_label)
82
86
  try:
83
87
  return next(data_files)
84
- except StopIteration as s:
88
+ except StopIteration:
85
89
  return None
@@ -6,6 +6,14 @@ from pathlib import Path
6
6
 
7
7
  class PathStack:
8
8
  """ A Stack of Directory names in a Path.
9
+
10
+ **Method Summary:**
11
+ - push(str)
12
+ - pop: str?
13
+ - join_stack: Path
14
+ - create_path(str): Path
15
+ - reduce_depth(int): bool
16
+ - get_depth: int
9
17
  """
10
18
 
11
19
  def __init__(self):
@@ -15,56 +23,52 @@ class PathStack:
15
23
  def push(self, directory_name: str):
16
24
  """ Push a directory to the Path Stack.
17
25
 
18
- Parameters:
19
- - directory_name (str): The name of the next directory in the Path Stack.
26
+ **Parameters:**
27
+ - directory_name (str): The name of the next directory in the Path Stack.
20
28
  """
21
29
  self._stack.append(directory_name)
22
30
 
23
31
  def pop(self) -> str | None:
24
- """
25
- Pop the top of the Stack, and return the directory name.
32
+ """ Pop the top of the Stack, and return the directory name.
26
33
 
27
- Returns:
28
- str : The String removed from the top of the Stack.
34
+ **Returns:**
35
+ str - The String removed from the top of the Stack.
29
36
  """
30
37
  if len(self._stack) <= 0:
31
38
  return None
32
39
  return self._stack.pop()
33
40
 
34
41
  def join_stack(self) -> Path:
35
- """
36
- Combines all elements in the path Stack to form the parent directory.
42
+ """ Combines all elements in the path Stack to form the parent directory.
37
43
 
38
- Returns:
39
- Path representing the current directory.
44
+ **Returns:**
45
+ Path - representing the current directory.
40
46
  """
41
47
  if len(self._stack) == 0:
42
48
  return Path("./")
43
49
  return Path(f"./{'/'.join(self._stack)}/")
44
50
 
45
51
  def create_path(self, filename: str) -> Path:
46
- """
47
- Combines all Elements in the Stack and appends a File name.
52
+ """ Combines all Elements in the Stack and appends a File name.
48
53
 
49
- Parameters:
50
- - filename (str): The name of the file to append to the end of the path.
54
+ **Parameters:**
55
+ - filename (str): The name of the file to append to the end of the path.
51
56
 
52
- Returns:
53
- Path : The Path to the file.
57
+ **Returns:**
58
+ Path - The Path to the file.
54
59
  """
55
60
  if type(filename) is not str or len(filename) < 1:
56
61
  return self.join_stack()
57
62
  return self.join_stack() / filename
58
63
 
59
64
  def reduce_depth(self, depth: int) -> bool:
60
- """
61
- Reduce the Depth of the Path Stack.
65
+ """ Reduce the Depth of the Path Stack.
62
66
 
63
- Parameters:
64
- - depth (int): The depth to reduce the stack to.
67
+ **Parameters:**
68
+ - depth (int): The depth to reduce the stack to.
65
69
 
66
- Returns:
67
- boolean : Whether the Reduction was successful, ie 0 or more Stack pops.
70
+ **Returns:**
71
+ boolean - Whether the Reduction was successful, ie 0 or more Stack pops.
68
72
  """
69
73
  current_depth = self.get_depth()
70
74
  if current_depth < depth or depth < 0:
@@ -76,11 +80,10 @@ class PathStack:
76
80
  return True
77
81
 
78
82
  def get_depth(self) -> int:
79
- """
80
- Obtain the current Depth of the Stack.
81
- The state where the current directory is the path, ie: './' has a depth of 0.
83
+ """ Obtain the current Depth of the Stack.
84
+ - The state where the current directory is the path, ie: './' has a depth of 0.
82
85
 
83
- Returns:
84
- int : The number of elements in the Path Stack.
86
+ **Returns:**
87
+ int - The number of elements in the Path Stack.
85
88
  """
86
89
  return len(self._stack)
@@ -1,5 +1,4 @@
1
- """Tree State.
2
- A Key component in Tree Validation for Build operations.
1
+ """ Tree State: A Key component in Tree Validation for Build operations.
3
2
  Author: DK96-OS 2024 - 2025
4
3
  """
5
4
  from pathlib import Path
@@ -12,6 +11,16 @@ from treescript_builder.data.tree_data import TreeData
12
11
 
13
12
  class TreeState:
14
13
  """ Manages the State of the Tree during Validation.
14
+
15
+ **Method Summary:**
16
+ - validate_tree_data(TreeData): int
17
+ - get_current_depth: int
18
+ - get_current_path: Path
19
+ - add_to_queue(str)
20
+ - add_to_stack(str)
21
+ - process_queue: Path?
22
+ - process_stack(int): Generator[Path]
23
+ - reduce_depth(int): bool
15
24
  """
16
25
 
17
26
  def __init__(self):
@@ -1,4 +1,4 @@
1
- """The Input Module.
1
+ """ The Input Module.
2
2
  - Validate And Format Input Arguments.
3
3
  - Read Input Tree String from File.
4
4
  Author: DK96-OS 2024 - 2025
@@ -1,33 +1,32 @@
1
- """Defines and Validates Argument Syntax.
1
+ """ Defines and Validates Argument Syntax.
2
2
  - Encapsulates Argument Parser.
3
3
  - Returns Argument Data, the args provided by the User.
4
4
  Author: DK96-OS 2024 - 2025
5
5
  """
6
6
  from argparse import ArgumentParser
7
7
  from sys import exit
8
- from typing import Optional
9
8
 
10
9
  from treescript_builder.input.argument_data import ArgumentData
11
10
  from treescript_builder.input.string_validation import validate_name
12
11
 
13
12
 
14
- def parse_arguments(args: Optional[list[str]] = None) -> ArgumentData:
13
+ def parse_arguments(
14
+ args: list[str],
15
+ ) -> ArgumentData:
15
16
  """ Parse command line arguments.
16
17
 
17
- Parameters:
18
- - args: A list of argument strings.
18
+ **Parameters:**
19
+ - args(list): A list of argument strings.
19
20
 
20
- Returns:
21
- ArgumentData : Container for Valid Argument Data.
21
+ **Returns:**
22
+ ArgumentData - Container for Valid Argument Data.
22
23
  """
23
24
  if args is None or len(args) == 0:
24
- exit("No Arguments given. ")
25
- # Initialize the Parser and Parse Immediately
26
- try:
25
+ exit("No Arguments given.")
26
+ try: # Initialize the Parser and Parse Immediately
27
27
  parsed_args = _define_arguments().parse_args(args)
28
- except SystemExit as e:
28
+ except SystemExit:
29
29
  exit("Unable to Parse Arguments.")
30
- #
31
30
  return _validate_arguments(
32
31
  parsed_args.tree_file_name,
33
32
  parsed_args.data_dir,
@@ -41,16 +40,16 @@ def _validate_arguments(
41
40
  is_reverse: bool
42
41
  ) -> ArgumentData:
43
42
  """ Checks the values received from the ArgParser.
44
- - Uses Validate Name method from StringValidation.
45
- - Ensures that Reverse Operations have a Data Directory.
43
+ - Uses Validate Name method from StringValidation.
44
+ - Ensures that Reverse Operations have a Data Directory.
46
45
 
47
- Parameters:
48
- - tree_file_name (str): The file name of the tree input.
49
- - data_dir_name (str): The Data Directory name.
50
- - is_reverse (bool): Whether the builder operation is reversed.
46
+ **Parameters:**
47
+ - tree_file_name (str): The file name of the tree input.
48
+ - data_dir_name (str): The Data Directory name.
49
+ - is_reverse (bool): Whether the builder operation is reversed.
51
50
 
52
- Returns:
53
- ArgumentData - A DataClass of syntactically correct arguments.
51
+ **Returns:**
52
+ ArgumentData - A DataClass of syntactically correct arguments.
54
53
  """
55
54
  # Validate Tree Name Syntax
56
55
  if not validate_name(tree_file_name):
@@ -60,7 +59,6 @@ def _validate_arguments(
60
59
  pass
61
60
  elif not validate_name(data_dir_name):
62
61
  exit("The Data Directory argument was invalid.")
63
- #
64
62
  return ArgumentData(
65
63
  tree_file_name,
66
64
  data_dir_name,
@@ -69,15 +67,14 @@ def _validate_arguments(
69
67
 
70
68
 
71
69
  def _define_arguments() -> ArgumentParser:
72
- """
73
- Initializes and Defines Argument Parser.
74
- - Sets Required/Optional Arguments and Flags.
70
+ """ Initializes and Defines Argument Parser.
71
+ - Sets Required/Optional Arguments and Flags.
75
72
 
76
- Returns:
77
- argparse.ArgumentParser - An instance with all supported FTB Arguments.
73
+ **Returns:**
74
+ argparse.ArgumentParser - An instance with all supported FTB Arguments.
78
75
  """
79
76
  parser = ArgumentParser(
80
- description="File Tree Builder"
77
+ description="""TreeScript-Builder: The File Tree Builder and Trimmer."""
81
78
  )
82
79
  # Required argument
83
80
  parser.add_argument(
@@ -1,5 +1,5 @@
1
1
  """ File Validation Methods.
2
- These Methods all raise SystemExit exceptions.
2
+ - These Methods all raise SystemExit exceptions.
3
3
  Author: DK96-OS 2024 - 2025
4
4
  """
5
5
  from pathlib import Path
@@ -11,14 +11,14 @@ from treescript_builder.input.string_validation import validate_name
11
11
  def validate_input_file(file_name: str) -> str | None:
12
12
  """ Read the Input File, Validate (non-blank) data, and return Input str.
13
13
 
14
- Parameters:
15
- - file_name (str): The Name of the Input File.
14
+ **Parameters:**
15
+ - file_name (str): The Name of the Input File.
16
16
 
17
- Returns:
18
- str - The String Contents of the Input File.
17
+ **Returns:**
18
+ str - The String Contents of the Input File.
19
19
 
20
- Raises:
21
- SystemExit - If the File does not exist, or is empty or blank, or read failed.
20
+ **Raises:**
21
+ SystemExit - If the File does not exist, or is empty or blank, or read failed.
22
22
  """
23
23
  file_path = Path(file_name)
24
24
  if not file_path.exists():
@@ -26,7 +26,7 @@ def validate_input_file(file_name: str) -> str | None:
26
26
  try:
27
27
  if (data := file_path.read_text()) is not None and validate_name(data):
28
28
  return data
29
- except IOError as e:
29
+ except OSError:
30
30
  exit("Failed to Read from File.")
31
31
  return None
32
32
 
@@ -34,14 +34,14 @@ def validate_input_file(file_name: str) -> str | None:
34
34
  def validate_directory(dir_path_str: str | None) -> Path | None:
35
35
  """ Ensure that if the Directory is present, it Exists.
36
36
 
37
- Parameters:
38
- - dir_path_str (str, optional): The String representation of the Path to the Directory.
37
+ **Parameters:**
38
+ - dir_path_str (str, optional): The String representation of the Path to the Directory.
39
39
 
40
- Returns:
41
- Path? - The , or None if given input is None.
40
+ **Returns:**
41
+ Path? - The , or None if given input is None.
42
42
 
43
- Raises:
44
- SystemExit - If a given path does not exist.
43
+ **Raises:**
44
+ SystemExit - If a given path does not exist.
45
45
  """
46
46
  if dir_path_str is None:
47
47
  return None
@@ -1,4 +1,4 @@
1
- """Valid Input Data Class.
1
+ """ Valid Input Data Class.
2
2
  Author: DK96-OS 2024 - 2025
3
3
  """
4
4
  from dataclasses import dataclass
@@ -11,7 +11,7 @@ class InputData:
11
11
 
12
12
  **Fields:**
13
13
  - tree_input (str): The Tree Input to the FTB operation.
14
- - data_dir (Path, optional): An Optional Path to the Data Directory.
14
+ - data_dir (Path?): An Optional Path to the Data Directory.
15
15
  - is_reversed (bool): Whether this FTB operation is reversed.
16
16
  """
17
17
  tree_input: str
@@ -1,10 +1,10 @@
1
- """Line Reader.
1
+ """ Line Reader.
2
2
 
3
3
  The Default Input Reader.
4
- Processes a single line at a time, and determines its key properties.
5
- The Depth is the Integer number of directories between the current line and the root.
6
- The Directory Boolean indicates whether the line represents a Directory.
7
- The Name String is the name of the line.
4
+ - Processes a single line at a time, and determines its key properties.
5
+ - The Depth is the Integer number of directories between the current line and the root.
6
+ - The Directory Boolean indicates whether the line represents a Directory.
7
+ - The Name String is the name of the line.
8
8
  Author: DK96-OS 2024 - 2025
9
9
  """
10
10
  from itertools import groupby
@@ -23,8 +23,8 @@ def read_input_tree(input_tree_data: str) -> Generator[TreeData, None, None]:
23
23
  **Parameters:**
24
24
  - input_data (InputData): The Input.
25
25
 
26
- **Returns:**
27
- Generator[TreeData] - Produces TreeData from the Input Data.
26
+ **Yields:**
27
+ TreeData - Produces TreeData from the Input Data.
28
28
 
29
29
  **Raises:**
30
30
  SystemExit - When any Line cannot be read successfully.
@@ -108,7 +108,7 @@ def _validate_node_name(node_name: str) -> tuple[bool, str] | None:
108
108
  if (dir_name := validate_dir_name(node_name)) is not None:
109
109
  return (True, dir_name)
110
110
  # Fall-Through to File Node
111
- except ValueError as e:
111
+ except ValueError:
112
112
  # An error in the dir name, such that it cannot be a file either
113
113
  return None
114
114
  # Is a File
@@ -1,4 +1,4 @@
1
- """String Validation Methods.
1
+ """ String Validation Methods.
2
2
  Author: DK96-OS 2024 - 2025
3
3
  """
4
4
  from typing import Literal
@@ -13,14 +13,12 @@ from treescript_builder.data.tree_state import TreeState
13
13
  def validate_build(
14
14
  tree_data: Generator[TreeData, None, None],
15
15
  data_dir_path: Path | None = None,
16
- verbose: bool = False,
17
16
  ) -> tuple[InstructionData, ...]:
18
17
  """ Validate the Build Instructions.
19
18
 
20
19
  **Parameters:**
21
20
  - tree_data (Generator[TreeData]): The Generator that provides TreeData.
22
21
  - data_dir_path (Path?): The optional Data Directory Path. Default: None.
23
- - verbose (bool): Whether to print DataDirectory information during validation.
24
22
 
25
23
  **Returns:**
26
24
  tuple[InstructionData] - A generator that yields Instructions.
@@ -29,8 +27,6 @@ def validate_build(
29
27
  return tuple(iter(_validate_build_generator(tree_data)))
30
28
  else:
31
29
  data = DataDirectory(data_dir_path)
32
- if verbose:
33
- print(f"Validating Build With DataDir: {data_dir_path}")
34
30
  return tuple(iter(_validate_build_generator_data(tree_data, data)))
35
31
 
36
32
 
@@ -52,7 +52,7 @@ def _create_file(
52
52
  """
53
53
  try:
54
54
  copy2(data, path)
55
- except BaseException as e:
55
+ except OSError:
56
56
  return False
57
57
  return True
58
58
 
@@ -72,6 +72,6 @@ def _make_dir_exist(
72
72
  return True
73
73
  try:
74
74
  path.mkdir(parents=True, exist_ok=True)
75
- except IOError as e:
75
+ except OSError:
76
76
  return False
77
77
  return True
@@ -25,10 +25,9 @@ def _trim(instruct: InstructionData) -> bool:
25
25
  if instruct.data_path is None:
26
26
  try:
27
27
  instruct.path.unlink(missing_ok=True)
28
- return True
29
- except IOError as e:
30
- print("IO File Error")
28
+ except OSError:
31
29
  return False
30
+ return True
32
31
  return _extract_file(instruct.path, instruct.data_path)
33
32
 
34
33
 
@@ -47,9 +46,9 @@ def _extract_file(
47
46
  """
48
47
  try:
49
48
  move(path, data)
50
- return True
51
- except:
49
+ except OSError:
52
50
  return False
51
+ return True
53
52
 
54
53
 
55
54
  def _remove_dir(
@@ -65,6 +64,6 @@ def _remove_dir(
65
64
  """
66
65
  try:
67
66
  path.rmdir()
68
- except BaseException as e:
67
+ except OSError:
69
68
  return False
70
69
  return True
@@ -13,7 +13,6 @@ from treescript_builder.data.tree_state import TreeState
13
13
  def validate_trim(
14
14
  tree_data: Generator[TreeData, None, None],
15
15
  data_dir_path: Path | None = None,
16
- verbose: bool = False,
17
16
  ) -> tuple[InstructionData, ...]:
18
17
  """ Validate the Trim Instructions.
19
18
 
@@ -29,8 +28,6 @@ def validate_trim(
29
28
  return tuple(iter(_validate_trim_generator(tree_data)))
30
29
  else:
31
30
  data = DataDirectory(data_dir_path)
32
- if verbose:
33
- print(f"Validating Trim With DataDir: {data_dir_path}")
34
31
  return tuple(iter(_validate_trim_generator_data(tree_data, data)))
35
32
 
36
33
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: treescript-builder
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Builds File Trees from TreeScript. If DataLabels are present in TreeScript, a DataDirectory argument is required.
5
5
  Home-page: https://github.com/DK96-OS/treescript-builder
6
6
  Author: DK96-OS