From d9de94e3101aa6550c98940eed96666efc36c03a Mon Sep 17 00:00:00 2001 From: a <4184070+MrCurtis@users.noreply.github.com> Date: Fri, 26 Jan 2024 20:13:58 +0000 Subject: [PATCH] Tidy up file structure. We use what seems to be the standard `src` and `tests` directory structure. --- .github/workflows/test.yml | 2 ++ README.md | 16 ++++++++++++++++ pyproject.toml | 3 ++- src/fk_graph/__init__.py | 3 +++ cytoscape.py => src/fk_graph/cytoscape.py | 0 data_setup.py => src/fk_graph/data_setup.py | 0 graph.py => src/fk_graph/graph.py | 0 plot_graph.py => src/fk_graph/plot_graph.py | 4 ++-- .../fk_graph/plotly_functions.py | 8 ++++---- tests/__init__.py | 0 test_data_setup.py => tests/test_data_setup.py | 4 ++-- test_graph.py => tests/test_graph.py | 4 ++-- .../test_intergration.py | 8 +++----- 13 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 src/fk_graph/__init__.py rename cytoscape.py => src/fk_graph/cytoscape.py (100%) rename data_setup.py => src/fk_graph/data_setup.py (100%) rename graph.py => src/fk_graph/graph.py (100%) rename plot_graph.py => src/fk_graph/plot_graph.py (66%) rename plotly_functions.py => src/fk_graph/plotly_functions.py (98%) create mode 100644 tests/__init__.py rename test_data_setup.py => tests/test_data_setup.py (89%) rename test_graph.py => tests/test_graph.py (99%) rename integration_test.py => tests/test_intergration.py (72%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 711de7c..74b817f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,5 +15,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt + - name: Install library + run: pip install . - name: Run tests run: python -m unittest diff --git a/README.md b/README.md index 6f07b13..aaaed25 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,19 @@ To install: ``` pip install fk-graph ``` + +Development: +------------ + +Clone the repo and `cd` in to the project directory. Create a virtual env, then install +the requirements with + +``` +pip install -r requirements.txt +``` + +Finally, to be able to run tests while developing, install the package as an editable install. + +``` +pip install --editable . +``` diff --git a/pyproject.toml b/pyproject.toml index 1d04a1e..31411e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,8 @@ requires = ["hatchling"] build-backend = "hatchling.build" [project] name = "fk-graph" -version = "0.0.7" +packages = ["src/fk_graph"] +version = "0.0.8" authors = [ { name="Andrew Curtis", email="fk.graph@fastmail.com" }, { name="John C Thomas" }, diff --git a/src/fk_graph/__init__.py b/src/fk_graph/__init__.py new file mode 100644 index 0000000..3170469 --- /dev/null +++ b/src/fk_graph/__init__.py @@ -0,0 +1,3 @@ +from fk_graph.data_setup import setup_data +from fk_graph.graph import get_graph +from fk_graph.plot_graph import plot diff --git a/cytoscape.py b/src/fk_graph/cytoscape.py similarity index 100% rename from cytoscape.py rename to src/fk_graph/cytoscape.py diff --git a/data_setup.py b/src/fk_graph/data_setup.py similarity index 100% rename from data_setup.py rename to src/fk_graph/data_setup.py diff --git a/graph.py b/src/fk_graph/graph.py similarity index 100% rename from graph.py rename to src/fk_graph/graph.py diff --git a/plot_graph.py b/src/fk_graph/plot_graph.py similarity index 66% rename from plot_graph.py rename to src/fk_graph/plot_graph.py index 2214359..3705c1c 100644 --- a/plot_graph.py +++ b/src/fk_graph/plot_graph.py @@ -1,8 +1,8 @@ -from plotly_functions import plot_v2, process_graph +from fk_graph.plotly_functions import plot_v2, process_graph import networkx as nx import plotly as ply def plot(graph:nx.Graph) -> ply.graph_objs.Figure: args = process_graph(graph) fig = plot_v2(*args) - return fig \ No newline at end of file + return fig diff --git a/plotly_functions.py b/src/fk_graph/plotly_functions.py similarity index 98% rename from plotly_functions.py rename to src/fk_graph/plotly_functions.py index 2185a71..ac3e7da 100644 --- a/plotly_functions.py +++ b/src/fk_graph/plotly_functions.py @@ -13,7 +13,7 @@ import plotly.express as px from plotly import graph_objects as go -from graph import Node +from fk_graph.graph import Node import flask @@ -296,8 +296,8 @@ def basic_graph(data=(('A', 'B'), ('B', 'C'), ('C', 'A'))) -> nx.Graph: def _get_test_graph() -> nx.Graph: - from data_setup import setup_data - from graph import get_graph + from fk_graph.data_setup import setup_data + from fk_graph.graph import get_graph from sqlalchemy import create_engine engine = create_engine("sqlite+pysqlite:///:memory:", echo=False) setup_data(engine) @@ -321,4 +321,4 @@ def dash_app(): if __name__ == '__main__': dash_app() - pass \ No newline at end of file + pass diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test_data_setup.py b/tests/test_data_setup.py similarity index 89% rename from test_data_setup.py rename to tests/test_data_setup.py index 82330b5..3b8ba6e 100644 --- a/test_data_setup.py +++ b/tests/test_data_setup.py @@ -2,9 +2,9 @@ from sqlalchemy import create_engine, text -from data_setup import setup_data +from fk_graph.data_setup import setup_data -from plotly_functions import basic_test +from fk_graph.plotly_functions import basic_test class DataSetupTests(TestCase): diff --git a/test_graph.py b/tests/test_graph.py similarity index 99% rename from test_graph.py rename to tests/test_graph.py index 63224ca..019153b 100644 --- a/test_graph.py +++ b/tests/test_graph.py @@ -2,9 +2,9 @@ from networkx import Graph, is_isomorphic from sqlalchemy import Column, create_engine, ForeignKey, insert, Integer, MetaData, String, Table -from data_setup import setup_data +from fk_graph.data_setup import setup_data -from graph import ( +from fk_graph.graph import ( get_graph, Node, PrimaryKeyDoesNotExist, diff --git a/integration_test.py b/tests/test_intergration.py similarity index 72% rename from integration_test.py rename to tests/test_intergration.py index 542bf05..3dfc705 100644 --- a/integration_test.py +++ b/tests/test_intergration.py @@ -1,12 +1,10 @@ from unittest import TestCase -from data_setup import setup_data - -from graph import get_graph - from sqlalchemy import create_engine, text -from plot_graph import plot +from fk_graph.graph import get_graph +from fk_graph.data_setup import setup_data +from fk_graph.plot_graph import plot engine = create_engine("sqlite+pysqlite:///:memory:", echo=True)