Package: python-graph-alg-lib
Library of Graph Algorithms for PythonIntroductionLibrary of Graph Algorithms for Python is a simple Python library providing implementations of various graph algorithms. It is more or less an educational/experimental project serving me as Python sandbox. The current version of the library provides the following algorithms:topological sortshortest path search for unweighted graphsshortest path search for weighted graphs (Dijkstra's algorithm)Prim's minimum spanning tree algorithm (limited to connected graphs)Kruskal's minimum spanning tree algorithm (applicable to both connected and disconnected graphs)Runtime Environment, Source Code Organization etc.Python Version and DependenciesWhen implementing the library, I used Python 3.8. Slightly older versions of Python might work as well, but there is no guarantee as I have never tested the library with them. The library code uses only the Python Standard Library. In other words, it does not depend on any other modules. Unit tests depend onPyTest 5.4.3. If you want to measure the code coverage, you will also needPyTest Coverage 2.10.0(i.e. optional test dependency). Similarly, if you want to generate test reports in HTML format,PyTest HTML pluginis needed.Library CodeThe library code is divided to five modules:graphlib.graphmodule provides two graph implementations (adjacency matrix, adjacency set), plus
an abstract base class prescribing the public API of any graph implementation.graphlib.algorithmsprovides implementations of various graph algorithms like topological sort, shortest path search, minimum spanning tree search etc.graphlib.utilmodule provides functionalities that support the implementation of the algorithms, for instance a priority queue.graphlib.dumpmodule provides dump-functions that can pretty-print various structures like graph, result of shortest path search, result of minimum spanning tree search etc. These functions can write their output to a file, to stdout, or to an instance of io.StringIO.graphlib.jsondefmodule provides functions that can build a graph accorging to a JSON definition.Test CodeThe test code is concentrated in thetestsdirectory, which is just a flat structure of modules with test code. For each of the library modules listed in theLibrary Codesection, there is a corresponding test module. The names of all test modules start with the prefixtest_, so that PyTest can recognize them as test modules. Within each test module, test methods are grouped to test suite classes. A test suite class is a simple class serving as collection (grouping) of test methods exercising the same functionality. All test dependencies are captured in thetest dependenciesfile. Visualizations of the graphs used by the test code can be found in thetest-graphsdirectory.API Documentation and Examples of UsageThe source code of the library involves docstring, so the API documentation is available in the usual way. Examples of usage can be found in the unit tests, no other examples are provided.Creation of Distribution PackageIn order to build the distribution package, execute the following command in the root directory of the project:python setup.py sdist bdist_wheelThe command above creates both source archive in .tar.gz format and distribution in wheel format.Execution of Unit TestsIn order to execute the unit tests, execute the following command in the root directory of the project:python -m pytest -v testsThe following command triggers the execution of the unit tests, and it also generates code coverage report in HTML format. The command also generates detailed test results in HTML format to the filetest-results.html.python -m pytest --cov=graphlib --cov-branch --cov-report html --html=test-results.html testsThe command above will only work if you have installed the corresponding PyTest plug-ins (seetest dependencies).Pylint AnalysisIn order to perform analysis of the library code withPylint, execute the following command in the root directory of the project:python -m pylint graphlibThe command above will only work if you have installed Pylint.