From 97035d8e4cae649505c97d17e4c21b072dbc9813 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 6 Dec 2021 22:37:23 +0100 Subject: [PATCH] Switch layout to src folder layout --- .gitignore | 2 +- habitmove/__init__.py | 4 - poetry.lock | 166 +++++++++++++++++++- pyproject.toml | 10 +- src/habitmove/__init__.py | 9 ++ run.py => src/habitmove/cli.py | 13 +- {habitmove => src/habitmove}/habits.py | 0 {habitmove => src/habitmove}/loopdata.py | 0 {habitmove => src/habitmove}/nomie.py | 9 +- {habitmove => src/habitmove}/nomiedata.py | 0 {habitmove => src/habitmove}/repetitions.py | 0 {habitmove => src/habitmove}/schema.py | 0 12 files changed, 196 insertions(+), 17 deletions(-) delete mode 100644 habitmove/__init__.py create mode 100644 src/habitmove/__init__.py rename run.py => src/habitmove/cli.py (69%) rename {habitmove => src/habitmove}/habits.py (100%) rename {habitmove => src/habitmove}/loopdata.py (100%) rename {habitmove => src/habitmove}/nomie.py (94%) rename {habitmove => src/habitmove}/nomiedata.py (100%) rename {habitmove => src/habitmove}/repetitions.py (100%) rename {habitmove => src/habitmove}/schema.py (100%) diff --git a/.gitignore b/.gitignore index 7397c55..6fe089d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -data/ +testdata/ output.db # Created by https://www.toptal.com/developers/gitignore/api/vim,linux,python,pandas diff --git a/habitmove/__init__.py b/habitmove/__init__.py deleted file mode 100644 index 074201a..0000000 --- a/habitmove/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -import habitmove.schema as schema -import habitmove.habits as habits -import habitmove.repetitions as rep -import habitmove.nomie as nomie diff --git a/poetry.lock b/poetry.lock index c93bb8f..714bcdc 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,8 +1,170 @@ -package = [] +[[package]] +name = "atomicwrites" +version = "1.4.0" +description = "Atomic file writes." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "attrs" +version = "21.2.0" +description = "Classes Without Boilerplate" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[package.extras] +dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit"] +docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] +tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins"] + +[[package]] +name = "click" +version = "8.0.3" +description = "Composable command line interface toolkit" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + +[[package]] +name = "colorama" +version = "0.4.4" +description = "Cross-platform colored terminal text." +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "iniconfig" +version = "1.1.1" +description = "iniconfig: brain-dead simple config-ini parsing" +category = "dev" +optional = false +python-versions = "*" + +[[package]] +name = "packaging" +version = "21.3" +description = "Core utilities for Python packages" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +pyparsing = ">=2.0.2,<3.0.5 || >3.0.5" + +[[package]] +name = "pluggy" +version = "1.0.0" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "py" +version = "1.11.0" +description = "library with cross-python path, ini-parsing, io, code, log facilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "pyparsing" +version = "3.0.6" +description = "Python parsing module" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.extras] +diagrams = ["jinja2", "railroad-diagrams"] + +[[package]] +name = "pytest" +version = "6.2.5" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} +attrs = ">=19.2.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +py = ">=1.8.2" +toml = "*" + +[package.extras] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] + +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "ce2aa767160f871dd3652615ba0a0dceb7733d62eb8cb4665b87f30a562e3adf" +content-hash = "11b15112d348ca956ae061f53d51b37fcb0adb9b06f9b1245c4a93eddc08bb1f" [metadata.files] +atomicwrites = [ + {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, + {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, +] +attrs = [ + {file = "attrs-21.2.0-py2.py3-none-any.whl", hash = "sha256:149e90d6d8ac20db7a955ad60cf0e6881a3f20d37096140088356da6c716b0b1"}, + {file = "attrs-21.2.0.tar.gz", hash = "sha256:ef6aaac3ca6cd92904cdd0d83f629a15f18053ec84e6432106f7a4d04ae4f5fb"}, +] +click = [ + {file = "click-8.0.3-py3-none-any.whl", hash = "sha256:353f466495adaeb40b6b5f592f9f91cb22372351c84caeb068132442a4518ef3"}, + {file = "click-8.0.3.tar.gz", hash = "sha256:410e932b050f5eed773c4cda94de75971c89cdb3155a72a0831139a79e5ecb5b"}, +] +colorama = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] +iniconfig = [ + {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"}, + {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, +] +packaging = [ + {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, + {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, +] +pluggy = [ + {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, + {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, +] +py = [ + {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, + {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, +] +pyparsing = [ + {file = "pyparsing-3.0.6-py3-none-any.whl", hash = "sha256:04ff808a5b90911829c55c4e26f75fa5ca8a2f5f36aa3a51f68e27033341d3e4"}, + {file = "pyparsing-3.0.6.tar.gz", hash = "sha256:d9bdec0013ef1eb5a84ab39a3b3868911598afa494f5faa038647101504e2b81"}, +] +pytest = [ + {file = "pytest-6.2.5-py3-none-any.whl", hash = "sha256:7310f8d27bc79ced999e760ca304d69f6ba6c6649c0b60fb0e04a4a77cacc134"}, + {file = "pytest-6.2.5.tar.gz", hash = "sha256:131b36680866a76e6781d13f101efb86cf674ebb9762eb70d3082b6f29889e89"}, +] +toml = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] diff --git a/pyproject.toml b/pyproject.toml index 15e602e..47a9483 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,18 +1,22 @@ [tool.poetry] name = "habitmove" -version = "0.4" +version = "0.4.0" description = "migrate nomie data to loop habits tracker" authors = ["Marty Oehme "] +packages = [ + { include = "habitmove", from = "src"}, +] [tool.poetry.dependencies] +importlib-metadata = {version = "^1.0", python = "<3.8"} python = "^3.9" +click = "^8.0" [tool.poetry.dev-dependencies] [tool.poetry.scripts] -habitmove = "run:main" +habitmove = "habitmove.cli:main" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" - diff --git a/src/habitmove/__init__.py b/src/habitmove/__init__.py new file mode 100644 index 0000000..4ed1b57 --- /dev/null +++ b/src/habitmove/__init__.py @@ -0,0 +1,9 @@ +# init.py +import sys + +if sys.version_info >= (3, 8): + from importlib.metadata import version as metadata_version +else: + from importlib_metadata import version as metadata_version + +__version__ = str(metadata_version(__name__)) diff --git a/run.py b/src/habitmove/cli.py similarity index 69% rename from run.py rename to src/habitmove/cli.py index 4456f1a..acc2a66 100755 --- a/run.py +++ b/src/habitmove/cli.py @@ -5,6 +5,9 @@ import habitmove.repetitions as rep import habitmove.nomie as nomie from habitmove.nomiedata import NomieImport +import click +from . import __version__ + import sys @@ -25,9 +28,13 @@ def migrate(data: NomieImport): db.close() -def main(): - file = sys.argv[1] - data = nomie.get_data(file) +@click.command() +@click.version_option(version=__version__) +@click.argument("inputfile") +def main(inputfile): + # TODO test and error gracefully for no input given + # file = sys.argv[1] + data = nomie.get_data(inputfile) migrate(data) diff --git a/habitmove/habits.py b/src/habitmove/habits.py similarity index 100% rename from habitmove/habits.py rename to src/habitmove/habits.py diff --git a/habitmove/loopdata.py b/src/habitmove/loopdata.py similarity index 100% rename from habitmove/loopdata.py rename to src/habitmove/loopdata.py diff --git a/habitmove/nomie.py b/src/habitmove/nomie.py similarity index 94% rename from habitmove/nomie.py rename to src/habitmove/nomie.py index 4764272..847edf6 100644 --- a/habitmove/nomie.py +++ b/src/habitmove/nomie.py @@ -2,6 +2,7 @@ import json import re +from click import secho, echo from habitmove.nomiedata import Tracker, Event, Activity, NomieImport @@ -35,13 +36,13 @@ def verify_continue(data: NomieImport): for e in data.events: activity_count += len(e.activities) if e.activities else 0 - print(f"Exporting from nomie {data.version}:") - print(f"Found trackers: {trackers}") - print( + secho(f"Exporting from nomie {data.version}:", fg="green") + echo(f"Found trackers: {trackers}") + echo( f"Found events: {len(data.events)} entries, containing {activity_count} individual activities." ) if not confirmation_question("Do you want to continue?", default_no=False): - print("Aborted.") + echo("Aborted.") exit(0) diff --git a/habitmove/nomiedata.py b/src/habitmove/nomiedata.py similarity index 100% rename from habitmove/nomiedata.py rename to src/habitmove/nomiedata.py diff --git a/habitmove/repetitions.py b/src/habitmove/repetitions.py similarity index 100% rename from habitmove/repetitions.py rename to src/habitmove/repetitions.py diff --git a/habitmove/schema.py b/src/habitmove/schema.py similarity index 100% rename from habitmove/schema.py rename to src/habitmove/schema.py