From 58f2d5f94eaa59515af93526eb91354bfc11e276 Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Sun, 25 Dec 2022 10:39:01 -0800 Subject: [PATCH 1/2] chore: add IntelliJ project config dir to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c412538..5fbb8aa 100644 --- a/.gitignore +++ b/.gitignore @@ -105,9 +105,10 @@ venv.bak/ # code editor stuff .vscode +.idea/ database.db .DS_Store -config.toml \ No newline at end of file +config.toml From 4042326120388a7b0a8a8b6e67d7a8fffc1ff10e Mon Sep 17 00:00:00 2001 From: Alex Hill Date: Tue, 27 Dec 2022 15:27:33 -0800 Subject: [PATCH 2/2] feat!: pip-installable package Resolves #8 BREAKING CHANGE: Database initialization is no longer handled by init_db.py in the project root; instead, install the package and use the console script invenflask-init-db. BREAKING CHANGE: A development server can no longer be started by the invocation "flask app.py"; instead, install the package and use the invocation "flask --app invenflask.app run". --- MANIFEST.in | 2 + README.md | 39 ++++++++++++------- init_db.py | 9 ----- pyproject.toml | 23 +++++++++++ src/invenflask/__init__.py | 0 app.py => src/invenflask/app.py | 0 src/invenflask/init_db.py | 24 ++++++++++++ schema.sql => src/invenflask/schema.sql | 0 .../invenflask/templates}/base.html | 0 .../invenflask/templates}/checkin.html | 0 .../invenflask/templates}/checkout.html | 0 .../invenflask/templates}/create_asset.html | 0 .../invenflask/templates}/edit_asset.html | 0 .../invenflask/templates}/history.html | 0 .../invenflask/templates}/index.html | 0 .../invenflask/templates}/staff.html | 0 .../invenflask/templates}/status.html | 0 17 files changed, 75 insertions(+), 22 deletions(-) create mode 100644 MANIFEST.in delete mode 100644 init_db.py create mode 100644 pyproject.toml create mode 100644 src/invenflask/__init__.py rename app.py => src/invenflask/app.py (100%) create mode 100644 src/invenflask/init_db.py rename schema.sql => src/invenflask/schema.sql (100%) rename {templates => src/invenflask/templates}/base.html (100%) rename {templates => src/invenflask/templates}/checkin.html (100%) rename {templates => src/invenflask/templates}/checkout.html (100%) rename {templates => src/invenflask/templates}/create_asset.html (100%) rename {templates => src/invenflask/templates}/edit_asset.html (100%) rename {templates => src/invenflask/templates}/history.html (100%) rename {templates => src/invenflask/templates}/index.html (100%) rename {templates => src/invenflask/templates}/staff.html (100%) rename {templates => src/invenflask/templates}/status.html (100%) diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..9826116 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include src/invenflask/schema.sql +include src/invenflask/templates/*.html diff --git a/README.md b/README.md index eba7012..c945b56 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,35 @@ # Invenflask [![Release](https://github.com/drahamim/invenflask/actions/workflows/release.yml/badge.svg)](https://github.com/drahamim/invenflask/actions/workflows/release.yml) -Dependancies: -sqlite3 3.32.3 -Python 3.10.9 -Flask 2.2.2 -Werkzeug 2.2.2 - +A small inventory ledger, based on Flask. ## Setup -Initialize the database\ -``` python3 init_db.py``` - -start flask\ -```flask app.py``` - +Proper Python distributions are currently a work in progress. Until then, install from a git clone or a source code snapshot from [releases](https://github.com/drahamim/invenflask/releases). + +Within the unpacked directory: +1. Set up virtual environment: + ``` + python3 -m venv venv + ``` +2. Install invenflask: + ``` + venv/bin/pip install . + ``` +3. Initialize database: + ``` + venv/bin/invenflask-init-db + ``` + This will create or overwrite a sqlite3 database named `database.db` in the current directory, which is the only setup the application currently understands. + + Note that this is a destructive operation. If `database.db` already exists, all tables that +4. Start a development server: + ``` + venv/bin/flask --app invenflask.app run + ``` + +For development, perform an _editable install_ instead at step 2 above, with `pip install -e .` ## import staff This will require a CSV formatted file @@ -32,4 +45,4 @@ sqlite> .mode csv sqlite> .import ./test_data/.csv staffs # verify it worked sqlite> SELECT * from staffs; -``` \ No newline at end of file +``` diff --git a/init_db.py b/init_db.py deleted file mode 100644 index cf3786c..0000000 --- a/init_db.py +++ /dev/null @@ -1,9 +0,0 @@ -import sqlite3 - -connection = sqlite3.connect('database.db') - -with open('schema.sql') as f: - connection.executescript(f.read()) - -connection.commit() -connection.close() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d084d5e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,23 @@ +[project] +name = "invenflask" +version = "2.0.0" +authors = [ + { name = "Daniel Rahamim" } +] +description = "A Flask-based asset checkin/checkout system" +readme = "README.md" +requires-python = ">=3.10" + +dependencies = [ + "flask >=2.2.2, <3" +] + +[project.scripts] +invenflask-init-db = "invenflask.init_db:main" + +[project.urls] +"Bug Tracker" = "https://github.com/drahamim/invenflask/issues" + +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" diff --git a/src/invenflask/__init__.py b/src/invenflask/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app.py b/src/invenflask/app.py similarity index 100% rename from app.py rename to src/invenflask/app.py diff --git a/src/invenflask/init_db.py b/src/invenflask/init_db.py new file mode 100644 index 0000000..f7246b5 --- /dev/null +++ b/src/invenflask/init_db.py @@ -0,0 +1,24 @@ +import argparse +from importlib.resources import files +import sqlite3 + + +def main(): + parser = argparse.ArgumentParser( + prog="invenflask-init-db", + description="Initialize the database for an invenflask instance" + ) + parser.add_argument( + '--database', + default="database.db", + help="Database file to (re)initialize" + ) + args = parser.parse_args() + + schema_sql = files("invenflask").joinpath("schema.sql").read_text() + connection = sqlite3.connect(args.database) + try: + connection.executescript(schema_sql) + connection.commit() + finally: + connection.close() diff --git a/schema.sql b/src/invenflask/schema.sql similarity index 100% rename from schema.sql rename to src/invenflask/schema.sql diff --git a/templates/base.html b/src/invenflask/templates/base.html similarity index 100% rename from templates/base.html rename to src/invenflask/templates/base.html diff --git a/templates/checkin.html b/src/invenflask/templates/checkin.html similarity index 100% rename from templates/checkin.html rename to src/invenflask/templates/checkin.html diff --git a/templates/checkout.html b/src/invenflask/templates/checkout.html similarity index 100% rename from templates/checkout.html rename to src/invenflask/templates/checkout.html diff --git a/templates/create_asset.html b/src/invenflask/templates/create_asset.html similarity index 100% rename from templates/create_asset.html rename to src/invenflask/templates/create_asset.html diff --git a/templates/edit_asset.html b/src/invenflask/templates/edit_asset.html similarity index 100% rename from templates/edit_asset.html rename to src/invenflask/templates/edit_asset.html diff --git a/templates/history.html b/src/invenflask/templates/history.html similarity index 100% rename from templates/history.html rename to src/invenflask/templates/history.html diff --git a/templates/index.html b/src/invenflask/templates/index.html similarity index 100% rename from templates/index.html rename to src/invenflask/templates/index.html diff --git a/templates/staff.html b/src/invenflask/templates/staff.html similarity index 100% rename from templates/staff.html rename to src/invenflask/templates/staff.html diff --git a/templates/status.html b/src/invenflask/templates/status.html similarity index 100% rename from templates/status.html rename to src/invenflask/templates/status.html