From faeb2458a47790fd43065708d98f8bcfb4a503e6 Mon Sep 17 00:00:00 2001 From: Paul Wright Date: Sat, 3 Aug 2024 23:25:42 +0100 Subject: [PATCH] Initial repository desgion (#2) Initial attempt at some structuring of the repo --- .../tests => docker}/__init__.py | 0 weird_salads/README.rst | 61 ++++++++++++ .../data/.gitignore => api/__init__.py} | 0 weird_salads/example_mod.py | 94 ------------------- weird_salads/example_subpkg/__init__.py | 5 - weird_salads/inventory/__init__.py | 0 weird_salads/orders/__init__.py | 0 weird_salads/streamlit_app/__init__,py | 0 weird_salads/tests/test_example.py | 4 - weird_salads/utils/__init__.py | 0 10 files changed, 61 insertions(+), 103 deletions(-) rename {weird_salads/example_subpkg/tests => docker}/__init__.py (100%) create mode 100644 weird_salads/README.rst rename weird_salads/{example_subpkg/data/.gitignore => api/__init__.py} (100%) delete mode 100644 weird_salads/example_mod.py delete mode 100644 weird_salads/example_subpkg/__init__.py create mode 100644 weird_salads/inventory/__init__.py create mode 100644 weird_salads/orders/__init__.py create mode 100644 weird_salads/streamlit_app/__init__,py delete mode 100644 weird_salads/tests/test_example.py create mode 100644 weird_salads/utils/__init__.py diff --git a/weird_salads/example_subpkg/tests/__init__.py b/docker/__init__.py similarity index 100% rename from weird_salads/example_subpkg/tests/__init__.py rename to docker/__init__.py diff --git a/weird_salads/README.rst b/weird_salads/README.rst new file mode 100644 index 0000000..79cf84c --- /dev/null +++ b/weird_salads/README.rst @@ -0,0 +1,61 @@ +Overview +-------- + +* api (FastAPI) +* data [small data files (if needed), probably where the SQLite DB will be stored...] +* database (scripts alembic migrations) +* inventory [deals with inventory-related tasks] +* order [deals with the order tasks] +* streamlit_app (streamlit frontend) +* tests [openastronomy location for tests] + + +Repository Layout +================= + +Below is the proposed directory structure for the `weird_salads` project: + +.. code-block:: text + + weird_salads/ + ├── weird_salads/ # Main application package + │ ├── README.rst + │ ├── data/ # Small data-related files (/SQLite DB) + │ ├── database/ # DB related utils, e.g. alembic + │ ├── api/ # FastAPI-related code + │ │ ├── __init__.py + │ │ ├── app.py # FastAPI app and routers + │ │ ├── endpoints/ + │ │ ├── schemas/ + │ │ │ ├── orders_schema.py # Orders Pydantic schemas + │ │ │ └── inventory_schema.py # Inventory Pydantic schemas + │ │ └── ... + │ ├── inventory/ # Inventory module + │ │ ├── inventory_service/ # Business logic + │ │ │ ├── exceptions.py # inventory-specific exceptions + │ │ │ ├── inventory_service.py + │ │ │ └── ... + │ │ ├── repository/ # Data layer access + │ │ │ ├── __init__.py + │ │ │ ├── inventory_repository.py + │ │ │ ├── models.py + │ │ │ └── ... + │ │ └── ... + │ ├── orders/ # Orders module (similar to Inventory) + │ │ ├── orders_service/ + │ │ │ ├── exceptions.py + │ │ │ ├── orders_service.py + │ │ │ └── orders.py + │ │ ├── repository/ + │ │ │ ├── __init__.py + │ │ │ ├── orders_repository.py + │ │ │ ├── models.py + │ │ │ └── ... + │ │ └── ... + │ ├── streamlit_app/ # Streamlit frontend + │ ├── tests/ # Unit and integration tests + │ ├── utils/ # Shared utility functions + │ │ ├── unit_of_work.py # Unit of work for transaction management + │ │ └── ... + │ └── version.py # Version information + └── ... diff --git a/weird_salads/example_subpkg/data/.gitignore b/weird_salads/api/__init__.py similarity index 100% rename from weird_salads/example_subpkg/data/.gitignore rename to weird_salads/api/__init__.py diff --git a/weird_salads/example_mod.py b/weird_salads/example_mod.py deleted file mode 100644 index 6cd213a..0000000 --- a/weird_salads/example_mod.py +++ /dev/null @@ -1,94 +0,0 @@ -__all__ = ["primes", "do_primes"] - - -def primes(imax): - """ - Returns prime numbers up to imax. - - Parameters - ---------- - imax : `int` - The number of primes to return. This should be less or equal to 10000. - - Returns - ------- - result : `list` - The list of prime numbers. - """ - p = list(range(10000)) - result = [] - k = 0 - n = 2 - - if imax > 10000: - raise ValueError("imax should be <= 10000") - - while len(result) < imax: - i = 0 - while i < k and n % p[i] != 0: - i = i + 1 - if i == k: - p[k] = n - k = k + 1 - result.append(n) - if k > 10000: - break - n = n + 1 - - return result - - -def do_primes(n, usecython=False): - if usecython: - raise Exception("This template does not have the example C code included.") - - else: - print("Using pure python primes") - return primes(n) - - -def main(args=None): - from time import time - - from astropy.utils.compat import argparse - - parser = argparse.ArgumentParser(description="Process some integers.") - parser.add_argument( - "-c", - "--use-cython", - dest="cy", - action="store_true", - help="Use the Cython-based Prime number generator.", - ) - parser.add_argument( - "-t", - "--timing", - dest="time", - action="store_true", - help="Time the Fibonacci generator.", - ) - parser.add_argument( - "-p", - "--print", - dest="prnt", - action="store_true", - help="Print all of the Prime numbers.", - ) - parser.add_argument( - "n", metavar="N", type=int, help="Get Prime numbers up to this number." - ) - - res = parser.parse_args(args) - - pre = time() - primes = do_primes(res.n, res.cy) - post = time() - - print(f"Found {len(primes)} prime numbers") - print(f"Largest prime: {primes[-1]}") - - if res.time: - print(f"Running time: {post - pre} s") - - if res.prnt: - print(f"Primes: {primes}") diff --git a/weird_salads/example_subpkg/__init__.py b/weird_salads/example_subpkg/__init__.py deleted file mode 100644 index 621b0a7..0000000 --- a/weird_salads/example_subpkg/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -This is the docstring for the examplesubpkg package. Normally you would -have whatever.py files in this directory implementing some modules, but this -is just an example sub-package, so it doesn't actually do anything. -""" diff --git a/weird_salads/inventory/__init__.py b/weird_salads/inventory/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/weird_salads/orders/__init__.py b/weird_salads/orders/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/weird_salads/streamlit_app/__init__,py b/weird_salads/streamlit_app/__init__,py new file mode 100644 index 0000000..e69de29 diff --git a/weird_salads/tests/test_example.py b/weird_salads/tests/test_example.py deleted file mode 100644 index d87af37..0000000 --- a/weird_salads/tests/test_example.py +++ /dev/null @@ -1,4 +0,0 @@ -def test_primes(): - from ..example_mod import primes - - assert primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] diff --git a/weird_salads/utils/__init__.py b/weird_salads/utils/__init__.py new file mode 100644 index 0000000..e69de29