From bea6c0eca5834a763f27526db72f3d718d35dea4 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 30 Sep 2021 17:19:29 +0200 Subject: [PATCH] Fix ability to be run via poetry and cli Program can now be invoked through poetry for development purposes, invoke as follows from main directory: `poetry run move`. Alternatively, can still be invoked via `python run.py ` and now via `./run.py ` which uses system default python installation. For now both commands are only mainly useful from the poetry development virtual environment itself. --- CHANGELOG.md | 6 +++++ README.md | 14 ++++++++--- habitmove/__init__.py | 4 ++++ {loop => habitmove}/habits.py | 0 migrate.py => habitmove/nomie.py | 14 ----------- {loop => habitmove}/repetitions.py | 0 {loop => habitmove}/schema.py | 0 loop/migration.py | 16 ------------- pyproject.toml | 8 +++++-- run.py | 38 ++++++++++++++++++++++++++++++ 10 files changed, 65 insertions(+), 35 deletions(-) create mode 100644 habitmove/__init__.py rename {loop => habitmove}/habits.py (100%) rename migrate.py => habitmove/nomie.py (76%) mode change 100755 => 100644 rename {loop => habitmove}/repetitions.py (100%) rename {loop => habitmove}/schema.py (100%) delete mode 100644 loop/migration.py create mode 100755 run.py diff --git a/CHANGELOG.md b/CHANGELOG.md index cf4f821..70c6f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe ## [Unreleased] +## [0.3.1] - 2021-09-30 + +### Fixed + +* Fix ability to run via poetry or be invoked from command-line + ### Removed * Remove pandas dependency and dataframe functionality diff --git a/README.md b/README.md index c9a9cf9..66175ad 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ Can take an export of nomie habits in json format and convert it to be importable in Loop Habit Tracker. Confirmed working for nomie version 5.6.4 and Loop Habit Tracker version 2.0.2. -Presumably works for other nomie 5.x versions and other Loop 2.x versions as well, but is untested. +Presumably works for other nomie 5.x versions and other Loop 2.x versions as well, +but that is untested. ## Usage @@ -11,9 +12,16 @@ Currently takes a single argument, the nomie database file, and will output to ` Can also take an existing Loop Habit database (exported from the application), and add the nomie exported habits and checkmarks to it. Simply put the exported Loop database in the same directory and call it `output.db`, -it will not (should not) overwrite anything. +it will not (should not™️) overwrite anything. -Invoked like: `python migrate.py nomie-export.json` +Invoked like: `python run.py nomie-export.json`. +Note, however, that -- until a packaged version is released -- you will need to have some packages in your environment. +If you wish to run it un-packaged, install poetry and let it do all dependency management by doing: + +``` +poetry install +poetry run habitmove +``` # Schemas diff --git a/habitmove/__init__.py b/habitmove/__init__.py new file mode 100644 index 0000000..074201a --- /dev/null +++ b/habitmove/__init__.py @@ -0,0 +1,4 @@ +import habitmove.schema as schema +import habitmove.habits as habits +import habitmove.repetitions as rep +import habitmove.nomie as nomie diff --git a/loop/habits.py b/habitmove/habits.py similarity index 100% rename from loop/habits.py rename to habitmove/habits.py diff --git a/migrate.py b/habitmove/nomie.py old mode 100755 new mode 100644 similarity index 76% rename from migrate.py rename to habitmove/nomie.py index 132865e..beef225 --- a/migrate.py +++ b/habitmove/nomie.py @@ -1,9 +1,6 @@ #!/usr/bin/env python import json -import sys - -import loop.migration as loop def load_file(filename): @@ -36,14 +33,3 @@ def verify_continue(data): if not confirmation_question("Do you want to continue?", default_no=False): print("Aborted.") exit(0) - - -if __name__ == "__main__": - # load nomie json - nomie_data = load_file(sys.argv[1]) - verify_continue(nomie_data) - trackers = nomie_data["trackers"] - events = nomie_data["events"] - - # give it over to loop migrator - loop.migrate(trackers, events) diff --git a/loop/repetitions.py b/habitmove/repetitions.py similarity index 100% rename from loop/repetitions.py rename to habitmove/repetitions.py diff --git a/loop/schema.py b/habitmove/schema.py similarity index 100% rename from loop/schema.py rename to habitmove/schema.py diff --git a/loop/migration.py b/loop/migration.py deleted file mode 100644 index 3527499..0000000 --- a/loop/migration.py +++ /dev/null @@ -1,16 +0,0 @@ -import loop.schema as schema -import loop.habits as habits -import loop.repetitions as rep - - -def migrate(trackers, events): - db = schema.migrate("output.db") - if trackers is not None: - - habitlist = habits.migrate(db, trackers) - - if events is not None: - rep.migrate(db, habitlist, events) - - db.commit() - db.close() diff --git a/pyproject.toml b/pyproject.toml index eba1fde..8b14cc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] -name = "nomie-migration" -version = "0.3.0" +name = "habitmove" +version = "0.3.1" description = "migrate nomie data to loop habits tracker" authors = ["Marty Oehme "] @@ -9,6 +9,10 @@ python = "^3.9" [tool.poetry.dev-dependencies] +[tool.poetry.scripts] +habitmove = "run:main" + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + diff --git a/run.py b/run.py new file mode 100755 index 0000000..9a80be4 --- /dev/null +++ b/run.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import habitmove.schema as schema +import habitmove.habits as habits +import habitmove.repetitions as rep +import habitmove.nomie as nomie + + +import sys + + +def migrate(trackers, events): + db = schema.migrate("output.db") + if trackers is not None: + + habitlist = habits.migrate(db, trackers) + + if events is not None: + rep.migrate(db, habitlist, events) + + db.commit() + db.close() + + +def main(): + # load nomie json + nomie_data = nomie.load_file(sys.argv[1]) + nomie.verify_continue(nomie_data) + trackers = nomie_data["trackers"] + events = nomie_data["events"] + migrate(trackers, events) + + +if __name__ == "__main__": + main() + +# things to have as (data) classes: +# tracker, event, tag? +# habit, repetition