From bf5b103aba88bc8cb57c6bd938c918bb3ad54aae Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Sat, 16 Nov 2019 00:44:42 -0500 Subject: [PATCH] Further rework __init__.py imports to be library friendly --- __init__.py | 16 ++++------------ main.py | 9 +++------ resources/__init__.py | 14 ++++++++++++++ resources/graphs/__init__.py | 16 ++++++++++++++++ resources/graphs/basic_graph/__init__.py | 13 +++++++++++++ resources/{ => graphs}/basic_graph/components.py | 0 resources/{ => graphs}/basic_graph/graph.py | 0 resources/graphs/directed_graph/__init__.py | 13 +++++++++++++ .../{ => graphs}/directed_graph/components.py | 0 resources/{ => graphs}/directed_graph/graph.py | 0 resources/graphs/state_machine/__init__.py | 13 +++++++++++++ .../{ => graphs}/state_machine/components.py | 0 resources/{ => graphs}/state_machine/graph.py | 0 .../resources/graphs}/__init__.py | 0 .../resources/graphs/basic_graph}/__init__.py | 0 tests/resources/{ => graphs}/basic_graph/edge.py | 2 +- .../resources/{ => graphs}/basic_graph/graph.py | 4 ++-- tests/resources/{ => graphs}/basic_graph/node.py | 2 +- .../directed_graph}/__init__.py | 0 .../{ => graphs}/directed_graph/edge.py | 2 +- .../{ => graphs}/directed_graph/graph.py | 4 ++-- .../{ => graphs}/directed_graph/node.py | 2 +- .../state_machine}/__init__.py | 0 .../resources/{ => graphs}/state_machine/edge.py | 2 +- .../{ => graphs}/state_machine/graph.py | 4 ++-- .../resources/{ => graphs}/state_machine/node.py | 2 +- tests/resources/state_machine/__init__.py | 0 27 files changed, 88 insertions(+), 30 deletions(-) create mode 100644 resources/graphs/__init__.py create mode 100644 resources/graphs/basic_graph/__init__.py rename resources/{ => graphs}/basic_graph/components.py (100%) rename resources/{ => graphs}/basic_graph/graph.py (100%) create mode 100644 resources/graphs/directed_graph/__init__.py rename resources/{ => graphs}/directed_graph/components.py (100%) rename resources/{ => graphs}/directed_graph/graph.py (100%) create mode 100644 resources/graphs/state_machine/__init__.py rename resources/{ => graphs}/state_machine/components.py (100%) rename resources/{ => graphs}/state_machine/graph.py (100%) rename {resources/basic_graph => tests/resources/graphs}/__init__.py (100%) rename {resources/directed_graph => tests/resources/graphs/basic_graph}/__init__.py (100%) rename tests/resources/{ => graphs}/basic_graph/edge.py (99%) rename tests/resources/{ => graphs}/basic_graph/graph.py (99%) rename tests/resources/{ => graphs}/basic_graph/node.py (99%) rename tests/resources/{basic_graph => graphs/directed_graph}/__init__.py (100%) rename tests/resources/{ => graphs}/directed_graph/edge.py (98%) rename tests/resources/{ => graphs}/directed_graph/graph.py (92%) rename tests/resources/{ => graphs}/directed_graph/node.py (98%) rename tests/resources/{directed_graph => graphs/state_machine}/__init__.py (100%) rename tests/resources/{ => graphs}/state_machine/edge.py (99%) rename tests/resources/{ => graphs}/state_machine/graph.py (95%) rename tests/resources/{ => graphs}/state_machine/node.py (94%) delete mode 100644 tests/resources/state_machine/__init__.py diff --git a/__init__.py b/__init__.py index eb5e7d3..c15db28 100644 --- a/__init__.py +++ b/__init__.py @@ -3,20 +3,12 @@ Library base importing definitions. """ # Import files/values we want to be available to library users. -from .resources.basic_graph.edge import Edge as BasicEdge -from .resources.basic_graph.node import Node as BasicNode -from .resources.basic_graph.graph import Graph as BasicGraph -from .resources.directed_graph.edge import Edge as DirectedEdge -from .resources.directed_graph.node import Node as DirectedNode -from .resources.directed_graph.graph import Graph as DirectedGraph -from .resources.state_machine.edge import Edge as StateMachineEdge -from .resources.state_machine.node import Node as StateMachineNode -from .resources.state_machine.graph import Graph as StateMachineGraph +from .resources import * # Define imports when using the * flag on this library. __all__ = [ - BasicEdge, BasicNode, BasicGraph, - DirectedEdge, DirectedNode, DirectedGraph, - StateMachineEdge, StateMachineNode, StateMachineGraph, + 'BasicEdge', 'BasicNode', 'BasicGraph', + 'DirectedEdge', 'DirectedNode', 'DirectedGraph', + 'StateMachineEdge', 'StateMachineNode', 'StateMachineGraph', ] diff --git a/main.py b/main.py index ebb126b..0c9011b 100644 --- a/main.py +++ b/main.py @@ -14,12 +14,9 @@ Example usage and output for graph library. # User Class Imports. from random import randint from resources import logging as init_logging -from resources.basic_graph.components import BasicEdge, BasicNode -from resources.basic_graph.graph import BasicGraph -from resources.directed_graph.components import DirectedEdge, DirectedNode -from resources.directed_graph.graph import DirectedGraph -from resources.state_machine.components import StateMachineEdge, StateMachineNode -from resources.state_machine.graph import StateMachineGraph +from resources import BasicEdge, BasicGraph, BasicNode +from resources import DirectedEdge, DirectedGraph, DirectedNode +from resources import StateMachineEdge, StateMachineGraph, StateMachineNode # Initialize Logger. diff --git a/resources/__init__.py b/resources/__init__.py index e69de29..28e6dd0 100644 --- a/resources/__init__.py +++ b/resources/__init__.py @@ -0,0 +1,14 @@ +""" +"Resources" folder importing definitions. +""" + +# Import files/values we want to be available to other folders. +from .graphs import * + + +# Define imports when using the * flag on this folder. +__all__ = [ + 'BasicEdge', 'BasicNode', 'BasicGraph', + 'DirectedEdge', 'DirectedNode', 'DirectedGraph', + 'StateMachineEdge', 'StateMachineNode', 'StateMachineGraph', +] diff --git a/resources/graphs/__init__.py b/resources/graphs/__init__.py new file mode 100644 index 0000000..882d3e6 --- /dev/null +++ b/resources/graphs/__init__.py @@ -0,0 +1,16 @@ +""" +"Graphs" folder importing definitions. +""" + +# Import files/values we want to be available to other folders. +from .basic_graph import * +from .directed_graph import * +from .state_machine import * + + +# Define imports when using the * flag on this folder. +__all__ = [ + 'BasicEdge', 'BasicNode', 'BasicGraph', + 'DirectedEdge', 'DirectedNode', 'DirectedGraph', + 'StateMachineEdge', 'StateMachineNode', 'StateMachineGraph', +] diff --git a/resources/graphs/basic_graph/__init__.py b/resources/graphs/basic_graph/__init__.py new file mode 100644 index 0000000..90a670a --- /dev/null +++ b/resources/graphs/basic_graph/__init__.py @@ -0,0 +1,13 @@ +""" +"Basic Graph" folder importing definitions. +""" + +# Import files/values we want to be available to other folders. +from .components import BasicEdge, BasicNode +from .graph import BasicGraph + + +# Define imports when using the * flag on this folder. +__all__ = [ + 'BasicEdge', 'BasicNode', 'BasicGraph', +] diff --git a/resources/basic_graph/components.py b/resources/graphs/basic_graph/components.py similarity index 100% rename from resources/basic_graph/components.py rename to resources/graphs/basic_graph/components.py diff --git a/resources/basic_graph/graph.py b/resources/graphs/basic_graph/graph.py similarity index 100% rename from resources/basic_graph/graph.py rename to resources/graphs/basic_graph/graph.py diff --git a/resources/graphs/directed_graph/__init__.py b/resources/graphs/directed_graph/__init__.py new file mode 100644 index 0000000..348e802 --- /dev/null +++ b/resources/graphs/directed_graph/__init__.py @@ -0,0 +1,13 @@ +""" +"Directed Graph" folder importing definitions. +""" + +# Import files/values we want to be available to other folders. +from .components import DirectedEdge, DirectedNode +from .graph import DirectedGraph + + +# Define imports when using the * flag on this folder. +__all__ = [ + 'DirectedEdge', 'DirectedNode', 'DirectedGraph', +] diff --git a/resources/directed_graph/components.py b/resources/graphs/directed_graph/components.py similarity index 100% rename from resources/directed_graph/components.py rename to resources/graphs/directed_graph/components.py diff --git a/resources/directed_graph/graph.py b/resources/graphs/directed_graph/graph.py similarity index 100% rename from resources/directed_graph/graph.py rename to resources/graphs/directed_graph/graph.py diff --git a/resources/graphs/state_machine/__init__.py b/resources/graphs/state_machine/__init__.py new file mode 100644 index 0000000..48a24d6 --- /dev/null +++ b/resources/graphs/state_machine/__init__.py @@ -0,0 +1,13 @@ +""" +"State Machine Graph" folder importing definitions. +""" + +# Import files/values we want to be available to other folders. +from .components import StateMachineEdge, StateMachineNode +from .graph import StateMachineGraph + + +# Define imports when using the * flag on this folder. +__all__ = [ + 'StateMachineEdge', 'StateMachineNode', 'StateMachineGraph', +] diff --git a/resources/state_machine/components.py b/resources/graphs/state_machine/components.py similarity index 100% rename from resources/state_machine/components.py rename to resources/graphs/state_machine/components.py diff --git a/resources/state_machine/graph.py b/resources/graphs/state_machine/graph.py similarity index 100% rename from resources/state_machine/graph.py rename to resources/graphs/state_machine/graph.py diff --git a/resources/basic_graph/__init__.py b/tests/resources/graphs/__init__.py similarity index 100% rename from resources/basic_graph/__init__.py rename to tests/resources/graphs/__init__.py diff --git a/resources/directed_graph/__init__.py b/tests/resources/graphs/basic_graph/__init__.py similarity index 100% rename from resources/directed_graph/__init__.py rename to tests/resources/graphs/basic_graph/__init__.py diff --git a/tests/resources/basic_graph/edge.py b/tests/resources/graphs/basic_graph/edge.py similarity index 99% rename from tests/resources/basic_graph/edge.py rename to tests/resources/graphs/basic_graph/edge.py index 0f19d66..f0bed5b 100644 --- a/tests/resources/basic_graph/edge.py +++ b/tests/resources/graphs/basic_graph/edge.py @@ -12,7 +12,7 @@ Tests for "Basic Edge" class. import unittest # User Class Imports. -from resources.basic_graph.components import BasicEdge, BasicNode +from resources import BasicEdge, BasicNode class TestBasicEdge(unittest.TestCase): diff --git a/tests/resources/basic_graph/graph.py b/tests/resources/graphs/basic_graph/graph.py similarity index 99% rename from tests/resources/basic_graph/graph.py rename to tests/resources/graphs/basic_graph/graph.py index e3611fd..42654fa 100644 --- a/tests/resources/basic_graph/graph.py +++ b/tests/resources/graphs/basic_graph/graph.py @@ -12,8 +12,8 @@ Tests for "Basic Graph" class. import unittest # User Class Imports. -from resources.basic_graph.components import BasicEdge, BasicNode -from resources.basic_graph.graph import BasicGraph +from resources import BasicEdge, BasicNode +from resources import BasicGraph class TestBasicGraph(unittest.TestCase): diff --git a/tests/resources/basic_graph/node.py b/tests/resources/graphs/basic_graph/node.py similarity index 99% rename from tests/resources/basic_graph/node.py rename to tests/resources/graphs/basic_graph/node.py index b91e1b2..578dfd4 100644 --- a/tests/resources/basic_graph/node.py +++ b/tests/resources/graphs/basic_graph/node.py @@ -12,7 +12,7 @@ Tests for "Basic Node" class. import unittest # User Class Imports. -from resources.basic_graph.components import BasicEdge, BasicNode +from resources import BasicEdge, BasicNode class TestBasicNode(unittest.TestCase): diff --git a/tests/resources/basic_graph/__init__.py b/tests/resources/graphs/directed_graph/__init__.py similarity index 100% rename from tests/resources/basic_graph/__init__.py rename to tests/resources/graphs/directed_graph/__init__.py diff --git a/tests/resources/directed_graph/edge.py b/tests/resources/graphs/directed_graph/edge.py similarity index 98% rename from tests/resources/directed_graph/edge.py rename to tests/resources/graphs/directed_graph/edge.py index 63b4202..192d63b 100644 --- a/tests/resources/directed_graph/edge.py +++ b/tests/resources/graphs/directed_graph/edge.py @@ -12,7 +12,7 @@ Tests for "Directed Edge" class. import unittest # User Class Imports. -from resources.directed_graph.components import DirectedEdge, DirectedNode +from resources import DirectedEdge, DirectedNode class TestDirectedEdge(unittest.TestCase): diff --git a/tests/resources/directed_graph/graph.py b/tests/resources/graphs/directed_graph/graph.py similarity index 92% rename from tests/resources/directed_graph/graph.py rename to tests/resources/graphs/directed_graph/graph.py index 815deac..0510cfb 100644 --- a/tests/resources/directed_graph/graph.py +++ b/tests/resources/graphs/directed_graph/graph.py @@ -12,8 +12,8 @@ Tests for "Directed Graph" class. import unittest # User Class Imports. -from resources.directed_graph.components import DirectedEdge, DirectedNode -from resources.directed_graph.graph import DirectedGraph +from resources import DirectedEdge, DirectedNode +from resources import DirectedGraph class TestDirectedGraph(unittest.TestCase): diff --git a/tests/resources/directed_graph/node.py b/tests/resources/graphs/directed_graph/node.py similarity index 98% rename from tests/resources/directed_graph/node.py rename to tests/resources/graphs/directed_graph/node.py index b3d0644..b8f0238 100644 --- a/tests/resources/directed_graph/node.py +++ b/tests/resources/graphs/directed_graph/node.py @@ -12,7 +12,7 @@ Tests for "Directed Node" class. import unittest # User Class Imports. -from resources.directed_graph.components import DirectedEdge, DirectedNode +from resources import DirectedEdge, DirectedNode class TestDirectedNode(unittest.TestCase): diff --git a/tests/resources/directed_graph/__init__.py b/tests/resources/graphs/state_machine/__init__.py similarity index 100% rename from tests/resources/directed_graph/__init__.py rename to tests/resources/graphs/state_machine/__init__.py diff --git a/tests/resources/state_machine/edge.py b/tests/resources/graphs/state_machine/edge.py similarity index 99% rename from tests/resources/state_machine/edge.py rename to tests/resources/graphs/state_machine/edge.py index f3b092c..2f47edc 100644 --- a/tests/resources/state_machine/edge.py +++ b/tests/resources/graphs/state_machine/edge.py @@ -12,7 +12,7 @@ Tests for "State Machine Edge" class. import unittest # User Class Imports. -from resources.state_machine.components import StateMachineEdge, StateMachineNode +from resources import StateMachineEdge, StateMachineNode class TestStateMachineEdge(unittest.TestCase): diff --git a/tests/resources/state_machine/graph.py b/tests/resources/graphs/state_machine/graph.py similarity index 95% rename from tests/resources/state_machine/graph.py rename to tests/resources/graphs/state_machine/graph.py index af35200..5ab6de1 100644 --- a/tests/resources/state_machine/graph.py +++ b/tests/resources/graphs/state_machine/graph.py @@ -12,8 +12,8 @@ Tests for "State Machine Graph" class. import unittest # User Class Imports. -from resources.state_machine.components import StateMachineEdge, StateMachineNode -from resources.state_machine.graph import StateMachineGraph +from resources import StateMachineEdge, StateMachineNode +from resources import StateMachineGraph class TestDirectedGraph(unittest.TestCase): diff --git a/tests/resources/state_machine/node.py b/tests/resources/graphs/state_machine/node.py similarity index 94% rename from tests/resources/state_machine/node.py rename to tests/resources/graphs/state_machine/node.py index 8bccf7a..1a84c22 100644 --- a/tests/resources/state_machine/node.py +++ b/tests/resources/graphs/state_machine/node.py @@ -12,7 +12,7 @@ Tests for "State Machine Node" class. import unittest # User Class Imports. -from resources.state_machine.components import StateMachineEdge, StateMachineNode +from resources import StateMachineEdge, StateMachineNode class TestStateMachineNode(unittest.TestCase): diff --git a/tests/resources/state_machine/__init__.py b/tests/resources/state_machine/__init__.py deleted file mode 100644 index e69de29..0000000 -- GitLab