From 3efc900ed4ee223b7eeee23db3109e2fdbae90bb Mon Sep 17 00:00:00 2001 From: Paul Haedrich Date: Wed, 27 Apr 2022 19:32:37 +0200 Subject: [PATCH] =?UTF-8?q?trex=200.1.1=20=F0=9F=A6=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 +- src/main.py | 74 ------------- trex/README.md | 0 trex/__init__.py | 0 trex/poetry.lock | 206 ++++++++++++++++++++++++++++++++++++ trex/pyproject.toml | 21 ++++ trex/tests/__init__.py | 0 trex/tests/test_trex.py | 5 + trex/trex/__init__.py | 1 + trex/trex/main.py | 136 ++++++++++++++++++++++++ {src => trex/trex}/utils.py | 40 ++++++- 11 files changed, 406 insertions(+), 80 deletions(-) delete mode 100644 src/main.py create mode 100644 trex/README.md create mode 100644 trex/__init__.py create mode 100644 trex/poetry.lock create mode 100644 trex/pyproject.toml create mode 100644 trex/tests/__init__.py create mode 100644 trex/tests/test_trex.py create mode 100644 trex/trex/__init__.py create mode 100644 trex/trex/main.py rename {src => trex/trex}/utils.py (80%) diff --git a/requirements.txt b/requirements.txt index 7379290..36ee171 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -typer \ No newline at end of file +typer +tabulate \ No newline at end of file diff --git a/src/main.py b/src/main.py deleted file mode 100644 index f0b0451..0000000 --- a/src/main.py +++ /dev/null @@ -1,74 +0,0 @@ -import typer - -# trex-o imports -import utils - -# app configuration -app = typer.Typer() -APP_NAME = "trex" -APP_VERSION = "0.1.0" - -""" -def main(): - typer.echo(storage.get_app_dir()) -""" - -@app.command() -def version(): - logo_text = typer.style(""" - _ - | |_ _ __ _____ __ - | __| '__/ _ \ \/ / - | |_| | | __/> < - \__|_| \___/_/\_\ - """, fg=typer.colors.GREEN, bold=True) - - logo_line = typer.style(f""" - ---------------------------------------------- - Version {APP_VERSION} 🦖 by berrysauce - ---------------------------------------------- - """, fg=typer.colors.BRIGHT_GREEN, bold=True) - - more_info = typer.style(""" - Honey, it's the Templatosaurus Rex! - Docs and more at berrysauce.me/trex - """, fg=typer.colors.WHITE, bold=False) - - path_info = typer.style(f""" - trex is located at: - {utils.get_app_dir()} - """, fg=typer.colors.BRIGHT_BLACK, bold=False) - - typer.echo(logo_text+logo_line+more_info+path_info) - - -@app.command() -def create(name: str, location: str): - typer.secho("\n" + "🚧 Creating template...", fg=typer.colors.BRIGHT_YELLOW) - res = utils.add_template(name, {"location": location}) - - if res: - typer.secho(f"✅ {name} created!" + "\n", fg=typer.colors.BRIGHT_GREEN) - else: - typer.secho("🛑 A template with this name already exists" + "\n", fg=typer.colors.RED) - utils.show_tip(f"Use 'trex make {name}' to create a new directory from the template") - - -@app.command() -def config(name: str, enable: bool = typer.Option(False), disable: bool = typer.Option(False)): - if enable: - value = True - elif disable: - value = False - else: - typer.secho("\n" + "🛑️ You need to provide --enable or --disable" + "\n", fg=typer.colors.RED) - return - - typer.secho("\n" + "🚧️ Updating config", fg=typer.colors.BRIGHT_YELLOW) - utils.add_config(name, data=value) - typer.secho(f"✅ {name} set to {value}!" + "\n", fg=typer.colors.BRIGHT_GREEN) - - - -if __name__ == "__main__": - app() \ No newline at end of file diff --git a/trex/README.md b/trex/README.md new file mode 100644 index 0000000..e69de29 diff --git a/trex/__init__.py b/trex/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/trex/poetry.lock b/trex/poetry.lock new file mode 100644 index 0000000..144921e --- /dev/null +++ b/trex/poetry.lock @@ -0,0 +1,206 @@ +[[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.4.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", "cloudpickle"] +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", "cloudpickle"] +tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] + +[[package]] +name = "click" +version = "8.1.2" +description = "Composable command line interface toolkit" +category = "main" +optional = false +python-versions = ">=3.7" + +[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 = "more-itertools" +version = "8.12.0" +description = "More routines for operating on iterables, beyond itertools" +category = "dev" +optional = false +python-versions = ">=3.5" + +[[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 = "0.13.1" +description = "plugin and hook calling mechanisms for python" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[package.extras] +dev = ["pre-commit", "tox"] + +[[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.8" +description = "pyparsing module - Classes and methods to define and execute parsing grammars" +category = "dev" +optional = false +python-versions = ">=3.6.8" + +[package.extras] +diagrams = ["railroad-diagrams", "jinja2"] + +[[package]] +name = "pytest" +version = "5.4.3" +description = "pytest: simple powerful testing with Python" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""} +attrs = ">=17.4.0" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +more-itertools = ">=4.0.0" +packaging = "*" +pluggy = ">=0.12,<1.0" +py = ">=1.5.0" +wcwidth = "*" + +[package.extras] +checkqa-mypy = ["mypy (==v0.761)"] +testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] + +[[package]] +name = "tabulate" +version = "0.8.9" +description = "Pretty-print tabular data" +category = "main" +optional = false +python-versions = "*" + +[package.extras] +widechars = ["wcwidth"] + +[[package]] +name = "typer" +version = "0.4.1" +description = "Typer, build great CLIs. Easy to code. Based on Python type hints." +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +click = ">=7.1.1,<9.0.0" + +[package.extras] +all = ["colorama (>=0.4.3,<0.5.0)", "shellingham (>=1.3.0,<2.0.0)"] +dev = ["autoflake (>=1.3.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)"] +doc = ["mkdocs (>=1.1.2,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "mdx-include (>=1.4.1,<2.0.0)"] +test = ["shellingham (>=1.3.0,<2.0.0)", "pytest (>=4.4.0,<5.4.0)", "pytest-cov (>=2.10.0,<3.0.0)", "coverage (>=5.2,<6.0)", "pytest-xdist (>=1.32.0,<2.0.0)", "pytest-sugar (>=0.9.4,<0.10.0)", "mypy (==0.910)", "black (>=22.3.0,<23.0.0)", "isort (>=5.0.6,<6.0.0)"] + +[[package]] +name = "wcwidth" +version = "0.2.5" +description = "Measures the displayed width of unicode strings in a terminal" +category = "dev" +optional = false +python-versions = "*" + +[metadata] +lock-version = "1.1" +python-versions = "^3.9" +content-hash = "6082dad6d16ae6de1ab5d42941da6d66a2fa3a1071a2e972aa295a6a380eca1c" + +[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.4.0-py2.py3-none-any.whl", hash = "sha256:2d27e3784d7a565d36ab851fe94887c5eccd6a463168875832a1be79c82828b4"}, + {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"}, +] +click = [ + {file = "click-8.1.2-py3-none-any.whl", hash = "sha256:24e1a4a9ec5bf6299411369b208c1df2188d9eb8d916302fe6bf03faed227f1e"}, + {file = "click-8.1.2.tar.gz", hash = "sha256:479707fe14d9ec9a0757618b7a100a0ae4c4e236fac5b7f80ca68028141a1a72"}, +] +colorama = [ + {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, + {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, +] +more-itertools = [ + {file = "more-itertools-8.12.0.tar.gz", hash = "sha256:7dc6ad46f05f545f900dd59e8dfb4e84a4827b97b3cfecb175ea0c7d247f6064"}, + {file = "more_itertools-8.12.0-py3-none-any.whl", hash = "sha256:43e6dd9942dffd72661a2c4ef383ad7da1e6a3e968a927ad7a6083ab410a688b"}, +] +packaging = [ + {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, + {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, +] +pluggy = [ + {file = "pluggy-0.13.1-py2.py3-none-any.whl", hash = "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"}, + {file = "pluggy-0.13.1.tar.gz", hash = "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0"}, +] +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.8-py3-none-any.whl", hash = "sha256:ef7b523f6356f763771559412c0d7134753f037822dad1b16945b7b846f7ad06"}, + {file = "pyparsing-3.0.8.tar.gz", hash = "sha256:7bf433498c016c4314268d95df76c81b842a4cb2b276fa3312cfb1e1d85f6954"}, +] +pytest = [ + {file = "pytest-5.4.3-py3-none-any.whl", hash = "sha256:5c0db86b698e8f170ba4582a492248919255fcd4c79b1ee64ace34301fb589a1"}, + {file = "pytest-5.4.3.tar.gz", hash = "sha256:7979331bfcba207414f5e1263b5a0f8f521d0f457318836a7355531ed1a4c7d8"}, +] +tabulate = [ + {file = "tabulate-0.8.9-py3-none-any.whl", hash = "sha256:d7c013fe7abbc5e491394e10fa845f8f32fe54f8dc60c6622c6cf482d25d47e4"}, + {file = "tabulate-0.8.9.tar.gz", hash = "sha256:eb1d13f25760052e8931f2ef80aaf6045a6cceb47514db8beab24cded16f13a7"}, +] +typer = [ + {file = "typer-0.4.1-py3-none-any.whl", hash = "sha256:e8467f0ebac0c81366c2168d6ad9f888efdfb6d4e1d3d5b4a004f46fa444b5c3"}, + {file = "typer-0.4.1.tar.gz", hash = "sha256:5646aef0d936b2c761a10393f0384ee6b5c7fe0bb3e5cd710b17134ca1d99cff"}, +] +wcwidth = [ + {file = "wcwidth-0.2.5-py2.py3-none-any.whl", hash = "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784"}, + {file = "wcwidth-0.2.5.tar.gz", hash = "sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"}, +] diff --git a/trex/pyproject.toml b/trex/pyproject.toml new file mode 100644 index 0000000..eacb23e --- /dev/null +++ b/trex/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "trex" +version = "0.1.1" +description = "Templatosaurus Rex 🦖 Create and manage project templates in your terminal" +authors = ["Paul Haedrich "] +readme = "README.md" + +[tool.poetry.scripts] +trex = "trex.main:app" + +[tool.poetry.dependencies] +python = "^3.9" +typer = "^0.4.1" +tabulate = "^0.8.9" + +[tool.poetry.dev-dependencies] +pytest = "^5.2" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/trex/tests/__init__.py b/trex/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/trex/tests/test_trex.py b/trex/tests/test_trex.py new file mode 100644 index 0000000..fc6b5a5 --- /dev/null +++ b/trex/tests/test_trex.py @@ -0,0 +1,5 @@ +from trex import __version__ + + +def test_version(): + assert __version__ == '0.1.0' diff --git a/trex/trex/__init__.py b/trex/trex/__init__.py new file mode 100644 index 0000000..d1f2e39 --- /dev/null +++ b/trex/trex/__init__.py @@ -0,0 +1 @@ +__version__ = "0.1.1" \ No newline at end of file diff --git a/trex/trex/main.py b/trex/trex/main.py new file mode 100644 index 0000000..aca3dac --- /dev/null +++ b/trex/trex/main.py @@ -0,0 +1,136 @@ +import os +import typer +from tabulate import tabulate +from typing import Optional +from distutils.dir_util import copy_tree + +# local imports +from trex import utils + +# app configuration +app = typer.Typer() +APP_NAME = utils.APP_NAME +APP_VERSION = utils.APP_VERSION + + +@app.command() +def version(): + dir_path, config_path, templates_path = utils.get_app_dir() + logo_text = typer.style(""" + _ + | |_ _ __ _____ __ + | __| '__/ _ \ \/ / + | |_| | | __/> < + \__|_| \___/_/\_\ + """, fg=typer.colors.GREEN, bold=True) + + logo_line = typer.style(f""" + ---------------------------------------------- + Version {APP_VERSION} 🦖 by berrysauce + ---------------------------------------------- + """, fg=typer.colors.BRIGHT_GREEN, bold=True) + + more_info = typer.style(""" + Honey, it's the Templatosaurus Rex! + Docs and more at berrysauce.me/trex + """, fg=typer.colors.WHITE, bold=False) + + path_info = typer.style(f""" + trex is located at: + {dir_path} + """, fg=typer.colors.BRIGHT_BLACK, bold=False) + + typer.echo(logo_text+logo_line+more_info+path_info) + + +@app.command() +def create(name: str): + location = str(os.getcwd()) + typer.secho("\n" + "🚧 Creating template...", fg=typer.colors.BRIGHT_YELLOW) + res = utils.add_template(name, {"location": location}) + + if res: + typer.secho(f"✅ {name} created!" + "\n", fg=typer.colors.BRIGHT_GREEN) + else: + typer.secho("⚠️ A template with this name already exists" + "\n", fg=typer.colors.YELLOW) + utils.show_tip(f"Use 'trex make {name}' to create a new directory from the template") + + +@app.command() +def remove(name: str): + typer.secho("\n" + "🚧 Removing template...", fg=typer.colors.BRIGHT_YELLOW) + if utils.remove_template(name) is True: + typer.secho(f"✅ {name} was removed!" + "\n", fg=typer.colors.BRIGHT_GREEN) + else: + typer.secho(f"⚠️ {name} doesn't exist" + "\n", fg=typer.colors.YELLOW) + + +@app.command() +def make(name: str, target: Optional[str] = typer.Argument(None)): + typer.secho("\n" + " 🦖 Rooaaar! I'm ready!", fg=typer.colors.BRIGHT_GREEN) + typer.secho(" 🚧 Making from template", fg=typer.colors.BRIGHT_YELLOW) + + typer.secho(" Fetching template data...", fg=typer.colors.BRIGHT_YELLOW) + res = utils.get_template(name) + + typer.secho(" Moving files around...", fg=typer.colors.BRIGHT_YELLOW) + if target: + destination = str(os.getcwd()) + "/" + target + typer.secho(" Creating target directory...", fg=typer.colors.BRIGHT_YELLOW) + os.mkdir(destination) + else: + destination = str(os.getcwd()) + + copy_tree(res["location"], destination) + typer.secho(f"✅ Created from {name}!" + "\n", fg=typer.colors.BRIGHT_GREEN) + +@app.command() +def all(): + typer.secho("\n" + "All available templates:", fg=typer.colors.BRIGHT_GREEN) + res = utils.get_template(name=None) + head = ["Name", "Location"] + data = [] + key_list = list(res.keys()) + values_list = list(res.values()) + + if len(key_list) == 0: + typer.secho(f"⚠️ Create a template first" + "\n", fg=typer.colors.YELLOW) + return + + for i in range(len(key_list)): + data.append([key_list[i], values_list[i]["location"]]) + + typer.echo(tabulate(data, headers=head, tablefmt="grid") + "\n") + utils.show_tip(f"Use 'trex make