From ea898f7bf45ca0f8667bd76d6718c6fff9961bd3 Mon Sep 17 00:00:00 2001 From: Roy Sommer Date: Sun, 22 Dec 2019 23:09:38 +0200 Subject: initial commit --- .gitignore | 24 ++ .pylintrc | 13 ++ .vscode/.ropeproject/config.py | 114 +++++++++ .vscode/.ropeproject/objectdb | Bin 0 -> 6 bytes .vscode/settings.json | 7 + README.md | 1 + logo.svg | 17 ++ poetry.lock | 254 +++++++++++++++++++++ pyproject.toml | 25 ++ task | 62 +++++ taskipy/__init__.py | 0 taskipy/run.py | 62 +++++ tests/__init__.py | 0 .../pyproject.toml | 8 + .../pyproject.toml | 16 ++ .../pyproject.toml | 9 + .../pyproject.toml | 3 + tests/fixtures/project_without_pyproject/.keep | 0 tests/test_taskipy.py | 131 +++++++++++ tests/utils/__init__.py | 0 tests/utils/fixture.py | 15 ++ 21 files changed, 761 insertions(+) create mode 100644 .gitignore create mode 100644 .pylintrc create mode 100644 .vscode/.ropeproject/config.py create mode 100644 .vscode/.ropeproject/objectdb create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 logo.svg create mode 100644 poetry.lock create mode 100644 pyproject.toml create mode 100755 task create mode 100644 taskipy/__init__.py create mode 100755 taskipy/run.py create mode 100644 tests/__init__.py create mode 100644 tests/fixtures/project_with_malformed_pyproject/pyproject.toml create mode 100644 tests/fixtures/project_with_pre_post_task_hooks/pyproject.toml create mode 100644 tests/fixtures/project_with_pyproject_and_tasks/pyproject.toml create mode 100644 tests/fixtures/project_with_pyproject_without_tasks_section/pyproject.toml create mode 100644 tests/fixtures/project_without_pyproject/.keep create mode 100644 tests/test_taskipy.py create mode 100644 tests/utils/__init__.py create mode 100644 tests/utils/fixture.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f0f20a --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST +.mypy_cache diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..02659cb --- /dev/null +++ b/.pylintrc @@ -0,0 +1,13 @@ +[MASTER] +disable= + C0114, + R0201, + W0702, + C0411 + +[FORMAT] +max-line-length=1000 +no-docstring-rgx=^.* +const-rgx=^.* +variable-rgx=[a-z_][a-z0-9_]{0,30}$ +missing-module-docstring=^.* \ No newline at end of file diff --git a/.vscode/.ropeproject/config.py b/.vscode/.ropeproject/config.py new file mode 100644 index 0000000..dee2d1a --- /dev/null +++ b/.vscode/.ropeproject/config.py @@ -0,0 +1,114 @@ +# The default ``config.py`` +# flake8: noqa + + +def set_prefs(prefs): + """This function is called before opening the project""" + + # Specify which files and folders to ignore in the project. + # Changes to ignored resources are not added to the history and + # VCSs. Also they are not returned in `Project.get_files()`. + # Note that ``?`` and ``*`` match all characters but slashes. + # '*.pyc': matches 'test.pyc' and 'pkg/test.pyc' + # 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc' + # '.svn': matches 'pkg/.svn' and all of its children + # 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o' + # 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o' + prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject', + '.hg', '.svn', '_svn', '.git', '.tox'] + + # Specifies which files should be considered python files. It is + # useful when you have scripts inside your project. Only files + # ending with ``.py`` are considered to be python files by + # default. + # prefs['python_files'] = ['*.py'] + + # Custom source folders: By default rope searches the project + # for finding source folders (folders that should be searched + # for finding modules). You can add paths to that list. Note + # that rope guesses project source folders correctly most of the + # time; use this if you have any problems. + # The folders should be relative to project root and use '/' for + # separating folders regardless of the platform rope is running on. + # 'src/my_source_folder' for instance. + # prefs.add('source_folders', 'src') + + # You can extend python path for looking up modules + # prefs.add('python_path', '~/python/') + + # Should rope save object information or not. + prefs['save_objectdb'] = True + prefs['compress_objectdb'] = False + + # If `True`, rope analyzes each module when it is being saved. + prefs['automatic_soa'] = True + # The depth of calls to follow in static object analysis + prefs['soa_followed_calls'] = 0 + + # If `False` when running modules or unit tests "dynamic object + # analysis" is turned off. This makes them much faster. + prefs['perform_doa'] = True + + # Rope can check the validity of its object DB when running. + prefs['validate_objectdb'] = True + + # How many undos to hold? + prefs['max_history_items'] = 32 + + # Shows whether to save history across sessions. + prefs['save_history'] = True + prefs['compress_history'] = False + + # Set the number spaces used for indenting. According to + # :PEP:`8`, it is best to use 4 spaces. Since most of rope's + # unit-tests use 4 spaces it is more reliable, too. + prefs['indent_size'] = 4 + + # Builtin and c-extension modules that are allowed to be imported + # and inspected by rope. + prefs['extension_modules'] = [] + + # Add all standard c-extensions to extension_modules list. + prefs['import_dynload_stdmods'] = True + + # If `True` modules with syntax errors are considered to be empty. + # The default value is `False`; When `False` syntax errors raise + # `rope.base.exceptions.ModuleSyntaxError` exception. + prefs['ignore_syntax_errors'] = False + + # If `True`, rope ignores unresolvable imports. Otherwise, they + # appear in the importing namespace. + prefs['ignore_bad_imports'] = False + + # If `True`, rope will insert new module imports as + # `from import ` by default. + prefs['prefer_module_from_imports'] = False + + # If `True`, rope will transform a comma list of imports into + # multiple separate import statements when organizing + # imports. + prefs['split_imports'] = False + + # If `True`, rope will remove all top-level import statements and + # reinsert them at the top of the module when making changes. + prefs['pull_imports_to_top'] = True + + # If `True`, rope will sort imports alphabetically by module name instead + # of alphabetically by import statement, with from imports after normal + # imports. + prefs['sort_imports_alphabetically'] = False + + # Location of implementation of + # rope.base.oi.type_hinting.interfaces.ITypeHintingFactory In general + # case, you don't have to change this value, unless you're an rope expert. + # Change this value to inject you own implementations of interfaces + # listed in module rope.base.oi.type_hinting.providers.interfaces + # For example, you can add you own providers for Django Models, or disable + # the search type-hinting in a class hierarchy, etc. + prefs['type_hinting_factory'] = ( + 'rope.base.oi.type_hinting.factory.default_type_hinting_factory') + + +def project_opened(project): + """This function is called after opening the project""" + # Do whatever you like here! diff --git a/.vscode/.ropeproject/objectdb b/.vscode/.ropeproject/objectdb new file mode 100644 index 0000000..0a47446 Binary files /dev/null and b/.vscode/.ropeproject/objectdb differ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..32c7430 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.pythonPath": "/Users/roysom/Library/Caches/pypoetry/virtualenvs/taskipy-hc1uaeBb-py3.8/bin/python", + "editor.tabSize": 4, + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.linting.mypyEnabled": true +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..67e3a53 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# taskipy \ No newline at end of file diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..9fdf5d3 --- /dev/null +++ b/logo.svg @@ -0,0 +1,17 @@ + + + + Shape + Created with Sketch. + + + + + + + + + + + + \ No newline at end of file diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..f1521bf --- /dev/null +++ b/poetry.lock @@ -0,0 +1,254 @@ +[[package]] +category = "dev" +description = "An abstract syntax tree for Python with inference support." +name = "astroid" +optional = false +python-versions = ">=3.5.*" +version = "2.3.3" + +[package.dependencies] +lazy-object-proxy = ">=1.4.0,<1.5.0" +six = ">=1.12,<2.0" +wrapt = ">=1.11.0,<1.12.0" + +[package.dependencies.typed-ast] +python = "<3.8" +version = ">=1.4.0,<1.5" + +[[package]] +category = "dev" +description = "Cross-platform colored terminal text." +marker = "sys_platform == \"win32\"" +name = "colorama" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "0.4.3" + +[[package]] +category = "dev" +description = "A Python utility / library to sort Python imports." +name = "isort" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "4.3.21" + +[package.extras] +pipfile = ["pipreqs", "requirementslib"] +pyproject = ["toml"] +requirements = ["pipreqs", "pip-api"] +xdg_home = ["appdirs (>=1.4.0)"] + +[[package]] +category = "dev" +description = "A fast and thorough lazy object proxy." +name = "lazy-object-proxy" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.4.3" + +[[package]] +category = "dev" +description = "McCabe checker, plugin for flake8" +name = "mccabe" +optional = false +python-versions = "*" +version = "0.6.1" + +[[package]] +category = "dev" +description = "Optional static typing for Python" +name = "mypy" +optional = false +python-versions = ">=3.5" +version = "0.761" + +[package.dependencies] +mypy-extensions = ">=0.4.3,<0.5.0" +typed-ast = ">=1.4.0,<1.5.0" +typing-extensions = ">=3.7.4" + +[package.extras] +dmypy = ["psutil (>=4.0)"] + +[[package]] +category = "dev" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +name = "mypy-extensions" +optional = false +python-versions = "*" +version = "0.4.3" + +[[package]] +category = "dev" +description = "python code static checker" +name = "pylint" +optional = false +python-versions = ">=3.5.*" +version = "2.4.4" + +[package.dependencies] +astroid = ">=2.3.0,<2.4" +colorama = "*" +isort = ">=4.2.5,<5" +mccabe = ">=0.6,<0.7" + +[[package]] +category = "dev" +description = "a python refactoring library..." +name = "rope" +optional = false +python-versions = "*" +version = "0.14.0" + +[[package]] +category = "dev" +description = "Python 2 and 3 compatibility utilities" +name = "six" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*" +version = "1.13.0" + +[[package]] +category = "main" +description = "Python Library for Tom's Obvious, Minimal Language" +name = "toml" +optional = false +python-versions = "*" +version = "0.10.0" + +[[package]] +category = "dev" +description = "a fork of Python 2 and 3 ast modules with type comment support" +name = "typed-ast" +optional = false +python-versions = "*" +version = "1.4.0" + +[[package]] +category = "dev" +description = "Backported and Experimental Type Hints for Python 3.5+" +name = "typing-extensions" +optional = false +python-versions = "*" +version = "3.7.4.1" + +[[package]] +category = "dev" +description = "Module for decorators, wrappers and monkey patching." +name = "wrapt" +optional = false +python-versions = "*" +version = "1.11.2" + +[metadata] +content-hash = "c9a9ad81a21b3edfe2b0695af814eaf3974c6fca8a4d1913f666eaabd432f72e" +python-versions = "^3.5" + +[metadata.files] +astroid = [ + {file = "astroid-2.3.3-py3-none-any.whl", hash = "sha256:840947ebfa8b58f318d42301cf8c0a20fd794a33b61cc4638e28e9e61ba32f42"}, + {file = "astroid-2.3.3.tar.gz", hash = "sha256:71ea07f44df9568a75d0f354c49143a4575d90645e9fead6dfb52c26a85ed13a"}, +] +colorama = [ + {file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"}, + {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, +] +isort = [ + {file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"}, + {file = "isort-4.3.21.tar.gz", hash = "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1"}, +] +lazy-object-proxy = [ + {file = "lazy-object-proxy-1.4.3.tar.gz", hash = "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27m-macosx_10_13_x86_64.whl", hash = "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27m-win32.whl", hash = "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27m-win_amd64.whl", hash = "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d"}, + {file = "lazy_object_proxy-1.4.3-cp34-cp34m-manylinux1_x86_64.whl", hash = "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a"}, + {file = "lazy_object_proxy-1.4.3-cp34-cp34m-win32.whl", hash = "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e"}, + {file = "lazy_object_proxy-1.4.3-cp34-cp34m-win_amd64.whl", hash = "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357"}, + {file = "lazy_object_proxy-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50"}, + {file = "lazy_object_proxy-1.4.3-cp35-cp35m-win32.whl", hash = "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db"}, + {file = "lazy_object_proxy-1.4.3-cp35-cp35m-win_amd64.whl", hash = "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449"}, + {file = "lazy_object_proxy-1.4.3-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156"}, + {file = "lazy_object_proxy-1.4.3-cp36-cp36m-win32.whl", hash = "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531"}, + {file = "lazy_object_proxy-1.4.3-cp36-cp36m-win_amd64.whl", hash = "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-win32.whl", hash = "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-win_amd64.whl", hash = "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea"}, + {file = "lazy_object_proxy-1.4.3-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62"}, + {file = "lazy_object_proxy-1.4.3-cp38-cp38-win32.whl", hash = "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd"}, + {file = "lazy_object_proxy-1.4.3-cp38-cp38-win_amd64.whl", hash = "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239"}, +] +mccabe = [ + {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, + {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, +] +mypy = [ + {file = "mypy-0.761-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:7f672d02fffcbace4db2b05369142e0506cdcde20cea0e07c7c2171c4fd11dd6"}, + {file = "mypy-0.761-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:87c556fb85d709dacd4b4cb6167eecc5bbb4f0a9864b69136a0d4640fdc76a36"}, + {file = "mypy-0.761-cp35-cp35m-win_amd64.whl", hash = "sha256:c6d27bd20c3ba60d5b02f20bd28e20091d6286a699174dfad515636cb09b5a72"}, + {file = "mypy-0.761-cp36-cp36m-macosx_10_6_x86_64.whl", hash = "sha256:4b9365ade157794cef9685791032521233729cb00ce76b0ddc78749abea463d2"}, + {file = "mypy-0.761-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:634aef60b4ff0f650d3e59d4374626ca6153fcaff96ec075b215b568e6ee3cb0"}, + {file = "mypy-0.761-cp36-cp36m-win_amd64.whl", hash = "sha256:53ea810ae3f83f9c9b452582261ea859828a9ed666f2e1ca840300b69322c474"}, + {file = "mypy-0.761-cp37-cp37m-macosx_10_6_x86_64.whl", hash = "sha256:0a9a45157e532da06fe56adcfef8a74629566b607fa2c1ac0122d1ff995c748a"}, + {file = "mypy-0.761-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:7eadc91af8270455e0d73565b8964da1642fe226665dd5c9560067cd64d56749"}, + {file = "mypy-0.761-cp37-cp37m-win_amd64.whl", hash = "sha256:e2bb577d10d09a2d8822a042a23b8d62bc3b269667c9eb8e60a6edfa000211b1"}, + {file = "mypy-0.761-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2c35cae79ceb20d47facfad51f952df16c2ae9f45db6cb38405a3da1cf8fc0a7"}, + {file = "mypy-0.761-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:f97a605d7c8bc2c6d1172c2f0d5a65b24142e11a58de689046e62c2d632ca8c1"}, + {file = "mypy-0.761-cp38-cp38-win_amd64.whl", hash = "sha256:a6bd44efee4dc8c3324c13785a9dc3519b3ee3a92cada42d2b57762b7053b49b"}, + {file = "mypy-0.761-py3-none-any.whl", hash = "sha256:7e396ce53cacd5596ff6d191b47ab0ea18f8e0ec04e15d69728d530e86d4c217"}, + {file = "mypy-0.761.tar.gz", hash = "sha256:85baab8d74ec601e86134afe2bcccd87820f79d2f8d5798c889507d1088287bf"}, +] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] +pylint = [ + {file = "pylint-2.4.4-py3-none-any.whl", hash = "sha256:886e6afc935ea2590b462664b161ca9a5e40168ea99e5300935f6591ad467df4"}, + {file = "pylint-2.4.4.tar.gz", hash = "sha256:3db5468ad013380e987410a8d6956226963aed94ecb5f9d3a28acca6d9ac36cd"}, +] +rope = [ + {file = "rope-0.14.0-py2-none-any.whl", hash = "sha256:6b728fdc3e98a83446c27a91fc5d56808a004f8beab7a31ab1d7224cecc7d969"}, + {file = "rope-0.14.0-py3-none-any.whl", hash = "sha256:f0dcf719b63200d492b85535ebe5ea9b29e0d0b8aebeb87fe03fc1a65924fdaf"}, + {file = "rope-0.14.0.tar.gz", hash = "sha256:c5c5a6a87f7b1a2095fb311135e2a3d1f194f5ecb96900fdd0a9100881f48aaf"}, +] +six = [ + {file = "six-1.13.0-py2.py3-none-any.whl", hash = "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd"}, + {file = "six-1.13.0.tar.gz", hash = "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"}, +] +toml = [ + {file = "toml-0.10.0-py2.7.egg", hash = "sha256:f1db651f9657708513243e61e6cc67d101a39bad662eaa9b5546f789338e07a3"}, + {file = "toml-0.10.0-py2.py3-none-any.whl", hash = "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b73cf81ebc9100e"}, + {file = "toml-0.10.0.tar.gz", hash = "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c"}, +] +typed-ast = [ + {file = "typed_ast-1.4.0-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:262c247a82d005e43b5b7f69aff746370538e176131c32dda9cb0f324d27141e"}, + {file = "typed_ast-1.4.0-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:71211d26ffd12d63a83e079ff258ac9d56a1376a25bc80b1cdcdf601b855b90b"}, + {file = "typed_ast-1.4.0-cp35-cp35m-win32.whl", hash = "sha256:630968c5cdee51a11c05a30453f8cd65e0cc1d2ad0d9192819df9978984529f4"}, + {file = "typed_ast-1.4.0-cp35-cp35m-win_amd64.whl", hash = "sha256:ffde2fbfad571af120fcbfbbc61c72469e72f550d676c3342492a9dfdefb8f12"}, + {file = "typed_ast-1.4.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:4e0b70c6fc4d010f8107726af5fd37921b666f5b31d9331f0bd24ad9a088e631"}, + {file = "typed_ast-1.4.0-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:bc6c7d3fa1325a0c6613512a093bc2a2a15aeec350451cbdf9e1d4bffe3e3233"}, + {file = "typed_ast-1.4.0-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:cc34a6f5b426748a507dd5d1de4c1978f2eb5626d51326e43280941206c209e1"}, + {file = "typed_ast-1.4.0-cp36-cp36m-win32.whl", hash = "sha256:d896919306dd0aa22d0132f62a1b78d11aaf4c9fc5b3410d3c666b818191630a"}, + {file = "typed_ast-1.4.0-cp36-cp36m-win_amd64.whl", hash = "sha256:354c16e5babd09f5cb0ee000d54cfa38401d8b8891eefa878ac772f827181a3c"}, + {file = "typed_ast-1.4.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:95bd11af7eafc16e829af2d3df510cecfd4387f6453355188342c3e79a2ec87a"}, + {file = "typed_ast-1.4.0-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e"}, + {file = "typed_ast-1.4.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d7c45933b1bdfaf9f36c579671fec15d25b06c8398f113dab64c18ed1adda01d"}, + {file = "typed_ast-1.4.0-cp37-cp37m-win32.whl", hash = "sha256:d755f03c1e4a51e9b24d899561fec4ccaf51f210d52abdf8c07ee2849b212a36"}, + {file = "typed_ast-1.4.0-cp37-cp37m-win_amd64.whl", hash = "sha256:2b907eb046d049bcd9892e3076c7a6456c93a25bebfe554e931620c90e6a25b0"}, + {file = "typed_ast-1.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:fdc1c9bbf79510b76408840e009ed65958feba92a88833cdceecff93ae8fff66"}, + {file = "typed_ast-1.4.0-cp38-cp38-manylinux1_i686.whl", hash = "sha256:7954560051331d003b4e2b3eb822d9dd2e376fa4f6d98fee32f452f52dd6ebb2"}, + {file = "typed_ast-1.4.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:48e5b1e71f25cfdef98b013263a88d7145879fbb2d5185f2a0c79fa7ebbeae47"}, + {file = "typed_ast-1.4.0-cp38-cp38-win32.whl", hash = "sha256:1170afa46a3799e18b4c977777ce137bb53c7485379d9706af8a59f2ea1aa161"}, + {file = "typed_ast-1.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:838997f4310012cf2e1ad3803bce2f3402e9ffb71ded61b5ee22617b3a7f6b6e"}, + {file = "typed_ast-1.4.0.tar.gz", hash = "sha256:66480f95b8167c9c5c5c87f32cf437d585937970f3fc24386f313a4c97b44e34"}, +] +typing-extensions = [ + {file = "typing_extensions-3.7.4.1-py2-none-any.whl", hash = "sha256:910f4656f54de5993ad9304959ce9bb903f90aadc7c67a0bef07e678014e892d"}, + {file = "typing_extensions-3.7.4.1-py3-none-any.whl", hash = "sha256:cf8b63fedea4d89bab840ecbb93e75578af28f76f66c35889bd7065f5af88575"}, + {file = "typing_extensions-3.7.4.1.tar.gz", hash = "sha256:091ecc894d5e908ac75209f10d5b4f118fbdb2eb1ede6a63544054bb1edb41f2"}, +] +wrapt = [ + {file = "wrapt-1.11.2.tar.gz", hash = "sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1"}, +] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..4a47fca --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +[tool.poetry] +name = "taskipy" +description = "tasks runner for python projects" +version = "0.1.0" +authors = ["Roy Sommer "] + +[tool.poetry.dependencies] +python = "^3.5" +toml = "^0.10.0" + +[tool.poetry.dev-dependencies] +pylint = "^2.4.4" +mypy = "^0.761" +rope = "^0.14.0" + +[tool.taskify.tasks] +test = "python -m unittest tests/test_*.py" +post_test = "./task lint" +lint = "./task lint_pylint && ./task lint_mypy" +lint_pylint = "pylint tests taskipy" +lint_mypy = "mypy tests taskipy" + +[build-system] +requires = ["poetry>=0.12"] +build-backend = "poetry.masonry.api" diff --git a/task b/task new file mode 100755 index 0000000..a5ce8b6 --- /dev/null +++ b/task @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import argparse +import subprocess +import sys +import toml +from typing import List + +def run_commands_and_bail_on_first_fail(cmds: List[str]) -> int: + for cmd in cmds: + p = subprocess.Popen(cmd, shell=True) + p.wait() + if p.returncode != 0: + return p.returncode + + return 0 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(prog='task') + parser.add_argument('name', help='name of the task. found in pyproject.toml under [tool.taskify.tasks]') + + args = parser.parse_args() + + try: + pyproject = toml.load('pyproject.toml') + except FileNotFoundError: + print('no pyproject.toml file found in this directory') + sys.exit(1) + except: + print('pyproject.toml file is malformed and could not be read') + sys.exit(1) + + try: + tasks = pyproject['tool']['taskify']['tasks'] + except: + print('no tasks found. add a [tool.taskify.tasks] section to your pyproject.toml') + sys.exit(127) + + commands = [] + + try: + task = tasks[args.name] + commands.append(task) + except: + print(f'could not find task "{args.name}""') + sys.exit(127) + + try: + pre_task = tasks[f'pre_{args.name}'] + commands.insert(0, pre_task) + except: + pass + + try: + post_task = tasks[f'post_{args.name}'] + commands.append(post_task) + except: + pass + + exit_code = run_commands_and_bail_on_first_fail(commands) + sys.exit(exit_code) + \ No newline at end of file diff --git a/taskipy/__init__.py b/taskipy/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/taskipy/run.py b/taskipy/run.py new file mode 100755 index 0000000..a5ce8b6 --- /dev/null +++ b/taskipy/run.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +import argparse +import subprocess +import sys +import toml +from typing import List + +def run_commands_and_bail_on_first_fail(cmds: List[str]) -> int: + for cmd in cmds: + p = subprocess.Popen(cmd, shell=True) + p.wait() + if p.returncode != 0: + return p.returncode + + return 0 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(prog='task') + parser.add_argument('name', help='name of the task. found in pyproject.toml under [tool.taskify.tasks]') + + args = parser.parse_args() + + try: + pyproject = toml.load('pyproject.toml') + except FileNotFoundError: + print('no pyproject.toml file found in this directory') + sys.exit(1) + except: + print('pyproject.toml file is malformed and could not be read') + sys.exit(1) + + try: + tasks = pyproject['tool']['taskify']['tasks'] + except: + print('no tasks found. add a [tool.taskify.tasks] section to your pyproject.toml') + sys.exit(127) + + commands = [] + + try: + task = tasks[args.name] + commands.append(task) + except: + print(f'could not find task "{args.name}""') + sys.exit(127) + + try: + pre_task = tasks[f'pre_{args.name}'] + commands.insert(0, pre_task) + except: + pass + + try: + post_task = tasks[f'post_{args.name}'] + commands.append(post_task) + except: + pass + + exit_code = run_commands_and_bail_on_first_fail(commands) + sys.exit(exit_code) + \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/project_with_malformed_pyproject/pyproject.toml b/tests/fixtures/project_with_malformed_pyproject/pyproject.toml new file mode 100644 index 0000000..28794b4 --- /dev/null +++ b/tests/fixtures/project_with_malformed_pyproject/pyproject.toml @@ -0,0 +1,8 @@ +[tool.poetry] +name = "taskipy" +description = "tasks runner for python projects" + +[[[[]]]] +asdfdasfdsaf +dsafv,dsa;lfj23[5432-tywersf +c======]asfdsafs = sadf2435 diff --git a/tests/fixtures/project_with_pre_post_task_hooks/pyproject.toml b/tests/fixtures/project_with_pre_post_task_hooks/pyproject.toml new file mode 100644 index 0000000..fb9a142 --- /dev/null +++ b/tests/fixtures/project_with_pre_post_task_hooks/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "taskipy" +description = "tasks runner for python projects" + +[tool.taskify.tasks] +pre_hello = "echo 'pre_task'" +hello = "echo 'hello'" +post_hello = "echo 'post_task'" + +pre_hello_failed_pretask = "echo 'pre_task' && exit 1" +hello_failed_pretask = "echo 'hello'" +post_hello_failed_pretask = "echo 'post_task'" + +pre_hello_failed_posttask = "echo 'pre_task'" +hello_failed_posttask = "echo 'hello'" +post_hello_failed_posttask = "echo 'post_task' && exit 1" diff --git a/tests/fixtures/project_with_pyproject_and_tasks/pyproject.toml b/tests/fixtures/project_with_pyproject_and_tasks/pyproject.toml new file mode 100644 index 0000000..289fcf4 --- /dev/null +++ b/tests/fixtures/project_with_pyproject_and_tasks/pyproject.toml @@ -0,0 +1,9 @@ +[tool.poetry] +name = "taskipy" +description = "tasks runner for python projects" + +[tool.taskify.tasks] +create_hello_txt = "echo 'hello, world' > hello.txt" +exit_17 = "exit 17" +print_hello_stdout = "echo 'hello stdout'" +print_hello_stderr = ">&2 echo 'hello stderr'" diff --git a/tests/fixtures/project_with_pyproject_without_tasks_section/pyproject.toml b/tests/fixtures/project_with_pyproject_without_tasks_section/pyproject.toml new file mode 100644 index 0000000..214e16b --- /dev/null +++ b/tests/fixtures/project_with_pyproject_without_tasks_section/pyproject.toml @@ -0,0 +1,3 @@ +[tool.poetry] +name = "taskipy" +description = "tasks runner for python projects" diff --git a/tests/fixtures/project_without_pyproject/.keep b/tests/fixtures/project_without_pyproject/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py new file mode 100644 index 0000000..450c65a --- /dev/null +++ b/tests/test_taskipy.py @@ -0,0 +1,131 @@ +import os +import unittest +import subprocess +from os import path +from typing import List, Tuple +from tests.utils.fixture import FixtureTempDir + +class TaskipyTestCase(unittest.TestCase): + def setUp(self): + self._tmp_dirs: List[FixtureTempDir] = [] + + def tearDown(self): + for tmp_dir in self._tmp_dirs: + tmp_dir.clean() + + def run_task(self, task: str, cwd=os.curdir) -> Tuple[int, str, str]: + executable_path = path.abspath('taskipy/run.py') + + proc = subprocess.Popen([executable_path, task], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) + stdout, stderr = proc.communicate() + + return proc.returncode, str(stdout), str(stderr) + + def create_test_dir_from_fixture(self, fixture_name: str): + tmp_dir = FixtureTempDir(path.join('tests', 'fixtures', fixture_name)) + self._tmp_dirs.append(tmp_dir) + return tmp_dir.path + + # pylint: disable=invalid-name + def assertSubstr(self, substr: str, full_string: str): + self.assertTrue(substr in full_string, msg=f'Expected \n "{substr}"\nto be in\n "{full_string}"') + + # pylint: disable=invalid-name + def assertNotSubstr(self, substr: str, full_string: str): + self.assertFalse(substr in full_string, msg=f'Expected \n "{substr}"\nnot to be in\n "{full_string}"') + + # pylint: disable=invalid-name + def assertSubstrsInOrder(self, substrs: List[str], full_string: str): + self.assertGreater(len(substrs), 0, 'please provide at least one substr') + + for substr_a, substr_b in zip(substrs[:-1], substrs[1:]): + self.assertSubstr(substr_a, full_string) + self.assertSubstr(substr_b, full_string) + self.assertLess(full_string.find(substr_a), + full_string.find(substr_b), + msg=f'Expected \n "{substr_a}"\nto appear before\n "{substr_b}"\nin\n "{full_string}"') + +class RunTaskTestCase(TaskipyTestCase): + def test_running_task(self): + cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') + self.run_task('create_hello_txt', cwd=cwd) + + with open(path.join(cwd, 'hello.txt'), 'r') as f: + hello_file_contents = f.readline().strip() + + self.assertEqual(hello_file_contents, 'hello, world') + + def test_exit_code_matches_task_exit_code(self): + cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') + exit_code, _, _ = self.run_task('exit_17', cwd=cwd) + + self.assertEqual(exit_code, 17) + + def test_stdout_contains_task_stdout(self): + cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') + _, stdout, _ = self.run_task('print_hello_stdout', cwd=cwd) + + self.assertSubstr('hello stdout', stdout) + + def test_stderr_contains_task_stderr(self): + cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') + _, _, stderr = self.run_task('print_hello_stderr', cwd=cwd) + + self.assertSubstr('hello stderr', stderr) + +class TaskPrePostHooksTestCase(TaskipyTestCase): + def test_running_pre_task_hook(self): + cwd = self.create_test_dir_from_fixture('project_with_pre_post_task_hooks') + _, stdout, _ = self.run_task('hello', cwd=cwd) + + self.assertSubstrsInOrder(['pre_task', 'hello'], stdout) + + def test_running_post_task_hook(self): + cwd = self.create_test_dir_from_fixture('project_with_pre_post_task_hooks') + _, stdout, _ = self.run_task('hello', cwd=cwd) + + self.assertSubstrsInOrder(['hello', 'post_task'], stdout) + + def test_exiting_after_pre_task_hook_if_exit_code_not_0(self): + cwd = self.create_test_dir_from_fixture('project_with_pre_post_task_hooks') + exit_code, stdout, _ = self.run_task('hello_failed_pretask', cwd=cwd) + + self.assertSubstr('pre_task', stdout) + self.assertNotSubstr('hello', stdout) + self.assertEqual(exit_code, 1) + + def test_exiting_with_post_task_hook_exit_code_if_not_0(self): + cwd = self.create_test_dir_from_fixture('project_with_pre_post_task_hooks') + exit_code, stdout, _ = self.run_task('hello_failed_posttask', cwd=cwd) + + self.assertSubstr('post_task', stdout) + self.assertEqual(exit_code, 1) + +class TaskRunFailTestCase(TaskipyTestCase): + def test_exiting_with_code_127_and_printing_if_task_not_found(self): + cwd = self.create_test_dir_from_fixture('project_with_pyproject_and_tasks') + exit_code, stdout, _ = self.run_task('task_that_does_not_exist', cwd=cwd) + + self.assertSubstr('could not find task "task_that_does_not_exist"', stdout) + self.assertEqual(exit_code, 127) + + def test_exiting_with_code_127_and_printing_if_no_tasks_section(self): + cwd = self.create_test_dir_from_fixture('project_with_pyproject_without_tasks_section') + exit_code, stdout, _ = self.run_task('task_that_does_not_exist', cwd=cwd) + + self.assertSubstr('no tasks found. add a [tool.taskify.tasks] section to your pyproject.toml', stdout) + self.assertEqual(exit_code, 127) + + def test_exiting_with_code_1_and_printing_if_no_pyproject_toml_file_found(self): + cwd = self.create_test_dir_from_fixture('project_without_pyproject') + exit_code, stdout, _ = self.run_task('some_task', cwd=cwd) + + self.assertSubstr('no pyproject.toml file found in this directory', stdout) + self.assertEqual(exit_code, 1) + + def test_exiting_with_code_1_and_printing_if_pyproject_toml_file_is_malformed(self): + cwd = self.create_test_dir_from_fixture('project_with_malformed_pyproject') + exit_code, stdout, _ = self.run_task('some_task', cwd=cwd) + + self.assertSubstr('pyproject.toml file is malformed and could not be read', stdout) + self.assertEqual(exit_code, 1) diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/utils/fixture.py b/tests/utils/fixture.py new file mode 100644 index 0000000..7bc7df3 --- /dev/null +++ b/tests/utils/fixture.py @@ -0,0 +1,15 @@ +import tempfile +import shutil + +class FixtureTempDir: + def __init__(self, fixture_original_dir: str): + self._tmpdir: str = tempfile.mktemp() + shutil.copytree(fixture_original_dir, self._tmpdir) + + @property + def path(self): + return self._tmpdir + + def clean(self): + shutil.rmtree(self._tmpdir, ignore_errors=True) + \ No newline at end of file -- cgit v1.2.3