aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2020-06-14 17:06:23 -0500
committerGitHub <noreply@github.com>2020-06-15 01:06:23 +0300
commit89500fba9009efedd42b7a3b5e5197f12419d8a4 (patch)
treea4e66649642efc15e6e7073241b03b0ebeea9b44
parentUpdate ADVANCED_FEATURES.md (diff)
downloadtaskipy2-89500fba9009efedd42b7a3b5e5197f12419d8a4.zip
Refactor taskipy into Task, PyProject, and TaskRunner (#15)
* Run `poetry update` * Sort test imports & convert unused f strings to strings There were some f strings that weren't interpolating anything. * Create custom exceptions * Refactor taskipi package into task, pyproject, and task_runner * Add docstrings & types to task & task_runner. Also, a small refactoring of __bail_on_first_fail() in task_runner.py. * Remove docstrings * Add MissingTaskipySettingsSectionError * Make path & items in PyProject private * Check runner is string rather than catching AttributeError * Add default exception case to cli * Add exit_code class variable to exceptions * Change PyProject to take in the file_path This also converts the instance variables to be private and has __load_toml_file convert the file_path to a Path if it is a str. We also no longer store the file_path since __load_toml_file is the only place it is needed so it is just passed in. * Task now builds the commands & takes in args + project I think args could possibly be moved over to commands since that is the only place it is used and that would reduce the amount of things we are passing in to Task. commands would just have to be converted to a method instead of a property then. * TaskRunner only runs the commands now with the project passed in Instead of putting the commands together, that is now delegated to Task. The run_commands_and_bail_on_first_fail method is now gone as that is what `run` does now. Furthermore, the instance variables of TaskRunner are private now. A single instance of the TaskRunner can now run many tasks now, since it is not tied to any particular task. * Update cli to use updated TaskRunner The pyproject.toml path is now passed in with the command name and args being passed to `run`. * Use single quotes * Extract pre_task & post_task to use __find_hooks They are basically the same method, with a one word difference.
-rw-r--r--.hooks/make_release_commit.py8
-rw-r--r--.pylintrc3
-rw-r--r--poetry.lock117
-rwxr-xr-xtaskipy/cli.py27
-rw-r--r--taskipy/exceptions.py51
-rw-r--r--taskipy/pyproject.py42
-rw-r--r--taskipy/run.py74
-rw-r--r--taskipy/task.py64
-rw-r--r--taskipy/task_runner.py33
-rw-r--r--tests/test_taskipy.py24
10 files changed, 293 insertions, 150 deletions
diff --git a/.hooks/make_release_commit.py b/.hooks/make_release_commit.py
index 34caea6..a0cdf18 100644
--- a/.hooks/make_release_commit.py
+++ b/.hooks/make_release_commit.py
@@ -1,16 +1,16 @@
#!/usr/bin/env python3
import toml
import subprocess
-import os
-from os import path
+from pathlib import Path
def create_release_commit():
- pyproject = toml.load(path.join(os.curdir, 'pyproject.toml'))
+ cwd = Path.cwd()
+ pyproject = toml.load(cwd / 'pyproject.toml')
version = pyproject['tool']['poetry']['version']
p = subprocess.Popen(f'git add . && git commit -m "Release version {version}" && git tag -a "{version}" -m "Release version {version}" && git push && git push --tags',
shell=True,
- cwd=os.curdir)
+ cwd=cwd)
p.wait()
diff --git a/.pylintrc b/.pylintrc
index 68d2e58..b9ffcac 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -5,7 +5,8 @@ disable=
W0702,
C0411,
R0903,
- R0915
+ R0915,
+ W0703
[FORMAT]
max-line-length=1000
diff --git a/poetry.lock b/poetry.lock
index 01b093a..80e2038 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -3,13 +3,13 @@ category = "dev"
description = "An abstract syntax tree for Python with inference support."
name = "astroid"
optional = false
-python-versions = ">=3.5.*"
-version = "2.3.3"
+python-versions = ">=3.5"
+version = "2.4.2"
[package.dependencies]
lazy-object-proxy = ">=1.4.0,<1.5.0"
six = ">=1.12,<2.0"
-wrapt = ">=1.11.0,<1.12.0"
+wrapt = ">=1.11,<2.0"
[package.dependencies.typed-ast]
python = "<3.8"
@@ -84,7 +84,7 @@ description = "Cross-platform lib for process and system monitoring in Python."
name = "psutil"
optional = false
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
-version = "5.6.7"
+version = "5.7.0"
[package.extras]
enum = ["enum34"]
@@ -95,13 +95,14 @@ description = "python code static checker"
name = "pylint"
optional = false
python-versions = ">=3.5.*"
-version = "2.4.4"
+version = "2.5.3"
[package.dependencies]
-astroid = ">=2.3.0,<2.4"
+astroid = ">=2.4.0,<=2.5"
colorama = "*"
isort = ">=4.2.5,<5"
mccabe = ">=0.6,<0.7"
+toml = ">=0.7.1"
[[package]]
category = "dev"
@@ -116,8 +117,8 @@ 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"
+python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
+version = "1.15.0"
[[package]]
category = "main"
@@ -125,7 +126,7 @@ description = "Python Library for Tom's Obvious, Minimal Language"
name = "toml"
optional = false
python-versions = "*"
-version = "0.10.0"
+version = "0.10.1"
[[package]]
category = "dev"
@@ -133,7 +134,7 @@ 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"
+version = "1.4.1"
[[package]]
category = "dev"
@@ -141,7 +142,7 @@ description = "Backported and Experimental Type Hints for Python 3.5+"
name = "typing-extensions"
optional = false
python-versions = "*"
-version = "3.7.4.1"
+version = "3.7.4.2"
[[package]]
category = "dev"
@@ -149,16 +150,16 @@ description = "Module for decorators, wrappers and monkey patching."
name = "wrapt"
optional = false
python-versions = "*"
-version = "1.11.2"
+version = "1.12.1"
[metadata]
-content-hash = "038310699e756391b0ed0ae9e0597be14230fd9972a32aadc8afb80544a1f2e0"
-python-versions = "^3.5"
+content-hash = "ca2a7360aa941db1e31c0e7f0ede9debe2394f0575d89b0f9a69546763449019"
+python-versions = "^3.6"
[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"},
+ {file = "astroid-2.4.2-py3-none-any.whl", hash = "sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386"},
+ {file = "astroid-2.4.2.tar.gz", hash = "sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703"},
]
colorama = [
{file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"},
@@ -216,21 +217,21 @@ mypy-extensions = [
{file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"},
]
psutil = [
- {file = "psutil-5.6.7-cp27-none-win32.whl", hash = "sha256:1b1575240ca9a90b437e5a40db662acd87bbf181f6aa02f0204978737b913c6b"},
- {file = "psutil-5.6.7-cp27-none-win_amd64.whl", hash = "sha256:28f771129bfee9fc6b63d83a15d857663bbdcae3828e1cb926e91320a9b5b5cd"},
- {file = "psutil-5.6.7-cp35-cp35m-win32.whl", hash = "sha256:21231ef1c1a89728e29b98a885b8e0a8e00d09018f6da5cdc1f43f988471a995"},
- {file = "psutil-5.6.7-cp35-cp35m-win_amd64.whl", hash = "sha256:b74b43fecce384a57094a83d2778cdfc2e2d9a6afaadd1ebecb2e75e0d34e10d"},
- {file = "psutil-5.6.7-cp36-cp36m-win32.whl", hash = "sha256:e85f727ffb21539849e6012f47b12f6dd4c44965e56591d8dec6e8bc9ab96f4a"},
- {file = "psutil-5.6.7-cp36-cp36m-win_amd64.whl", hash = "sha256:b560f5cd86cf8df7bcd258a851ca1ad98f0d5b8b98748e877a0aec4e9032b465"},
- {file = "psutil-5.6.7-cp37-cp37m-win32.whl", hash = "sha256:094f899ac3ef72422b7e00411b4ed174e3c5a2e04c267db6643937ddba67a05b"},
- {file = "psutil-5.6.7-cp37-cp37m-win_amd64.whl", hash = "sha256:fd2e09bb593ad9bdd7429e779699d2d47c1268cbde4dda95fcd1bd17544a0217"},
- {file = "psutil-5.6.7-cp38-cp38-win32.whl", hash = "sha256:70387772f84fa5c3bb6a106915a2445e20ac8f9821c5914d7cbde148f4d7ff73"},
- {file = "psutil-5.6.7-cp38-cp38-win_amd64.whl", hash = "sha256:10b7f75cc8bd676cfc6fa40cd7d5c25b3f45a0e06d43becd7c2d2871cbb5e806"},
- {file = "psutil-5.6.7.tar.gz", hash = "sha256:ffad8eb2ac614518bbe3c0b8eb9dffdb3a8d2e3a7d5da51c5b974fb723a5c5aa"},
+ {file = "psutil-5.7.0-cp27-none-win32.whl", hash = "sha256:298af2f14b635c3c7118fd9183843f4e73e681bb6f01e12284d4d70d48a60953"},
+ {file = "psutil-5.7.0-cp27-none-win_amd64.whl", hash = "sha256:75e22717d4dbc7ca529ec5063000b2b294fc9a367f9c9ede1f65846c7955fd38"},
+ {file = "psutil-5.7.0-cp35-cp35m-win32.whl", hash = "sha256:f344ca230dd8e8d5eee16827596f1c22ec0876127c28e800d7ae20ed44c4b310"},
+ {file = "psutil-5.7.0-cp35-cp35m-win_amd64.whl", hash = "sha256:e2d0c5b07c6fe5a87fa27b7855017edb0d52ee73b71e6ee368fae268605cc3f5"},
+ {file = "psutil-5.7.0-cp36-cp36m-win32.whl", hash = "sha256:a02f4ac50d4a23253b68233b07e7cdb567bd025b982d5cf0ee78296990c22d9e"},
+ {file = "psutil-5.7.0-cp36-cp36m-win_amd64.whl", hash = "sha256:1413f4158eb50e110777c4f15d7c759521703bd6beb58926f1d562da40180058"},
+ {file = "psutil-5.7.0-cp37-cp37m-win32.whl", hash = "sha256:d008ddc00c6906ec80040d26dc2d3e3962109e40ad07fd8a12d0284ce5e0e4f8"},
+ {file = "psutil-5.7.0-cp37-cp37m-win_amd64.whl", hash = "sha256:73f35ab66c6c7a9ce82ba44b1e9b1050be2a80cd4dcc3352cc108656b115c74f"},
+ {file = "psutil-5.7.0-cp38-cp38-win32.whl", hash = "sha256:60b86f327c198561f101a92be1995f9ae0399736b6eced8f24af41ec64fb88d4"},
+ {file = "psutil-5.7.0-cp38-cp38-win_amd64.whl", hash = "sha256:d84029b190c8a66a946e28b4d3934d2ca1528ec94764b180f7d6ea57b0e75e26"},
+ {file = "psutil-5.7.0.tar.gz", hash = "sha256:685ec16ca14d079455892f25bd124df26ff9137664af445563c1bd36629b5e0e"},
]
pylint = [
- {file = "pylint-2.4.4-py3-none-any.whl", hash = "sha256:886e6afc935ea2590b462664b161ca9a5e40168ea99e5300935f6591ad467df4"},
- {file = "pylint-2.4.4.tar.gz", hash = "sha256:3db5468ad013380e987410a8d6956226963aed94ecb5f9d3a28acca6d9ac36cd"},
+ {file = "pylint-2.5.3-py3-none-any.whl", hash = "sha256:d0ece7d223fe422088b0e8f13fa0a1e8eb745ebffcb8ed53d3e95394b6101a1c"},
+ {file = "pylint-2.5.3.tar.gz", hash = "sha256:7dd78437f2d8d019717dbf287772d0b2dbdfd13fc016aa7faa08d67bccc46adc"},
]
rope = [
{file = "rope-0.14.0-py2-none-any.whl", hash = "sha256:6b728fdc3e98a83446c27a91fc5d56808a004f8beab7a31ab1d7224cecc7d969"},
@@ -238,41 +239,41 @@ rope = [
{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"},
+ {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"},
+ {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"},
]
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"},
+ {file = "toml-0.10.1-py2.py3-none-any.whl", hash = "sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88"},
+ {file = "toml-0.10.1.tar.gz", hash = "sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f"},
]
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"},
+ {file = "typed_ast-1.4.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3"},
+ {file = "typed_ast-1.4.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb"},
+ {file = "typed_ast-1.4.1-cp35-cp35m-win32.whl", hash = "sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919"},
+ {file = "typed_ast-1.4.1-cp35-cp35m-win_amd64.whl", hash = "sha256:4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01"},
+ {file = "typed_ast-1.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75"},
+ {file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652"},
+ {file = "typed_ast-1.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"},
+ {file = "typed_ast-1.4.1-cp36-cp36m-win32.whl", hash = "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1"},
+ {file = "typed_ast-1.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa"},
+ {file = "typed_ast-1.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614"},
+ {file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41"},
+ {file = "typed_ast-1.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b"},
+ {file = "typed_ast-1.4.1-cp37-cp37m-win32.whl", hash = "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe"},
+ {file = "typed_ast-1.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355"},
+ {file = "typed_ast-1.4.1-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6"},
+ {file = "typed_ast-1.4.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907"},
+ {file = "typed_ast-1.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d"},
+ {file = "typed_ast-1.4.1-cp38-cp38-win32.whl", hash = "sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c"},
+ {file = "typed_ast-1.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4"},
+ {file = "typed_ast-1.4.1-cp39-cp39-macosx_10_15_x86_64.whl", hash = "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34"},
+ {file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"},
]
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"},
+ {file = "typing_extensions-3.7.4.2-py2-none-any.whl", hash = "sha256:f8d2bd89d25bc39dabe7d23df520442fa1d8969b82544370e03d88b5a591c392"},
+ {file = "typing_extensions-3.7.4.2-py3-none-any.whl", hash = "sha256:6e95524d8a547a91e08f404ae485bbb71962de46967e1b71a0cb89af24e761c5"},
+ {file = "typing_extensions-3.7.4.2.tar.gz", hash = "sha256:79ee589a3caca649a9bfd2a8de4709837400dfa00b6cc81962a1e6a1815969ae"},
]
wrapt = [
- {file = "wrapt-1.11.2.tar.gz", hash = "sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1"},
+ {file = "wrapt-1.12.1.tar.gz", hash = "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"},
]
diff --git a/taskipy/cli.py b/taskipy/cli.py
index f37d5f6..06acd6c 100755
--- a/taskipy/cli.py
+++ b/taskipy/cli.py
@@ -1,14 +1,33 @@
#!/usr/bin/env python3
import argparse
-from taskipy.run import run_task
+import sys
+from pathlib import Path
+
+from taskipy.exceptions import TaskipyError
+from taskipy.task_runner import TaskRunner
+
def main():
- parser = argparse.ArgumentParser(prog='task', description='runs a task specified in your pyproject.toml under [tool.taskipy.tasks]')
+ parser = argparse.ArgumentParser(
+ prog='task',
+ description='runs a task specified in your pyproject.toml under [tool.taskipy.tasks]',
+ )
parser.add_argument('name', help='name of the task')
- parser.add_argument('args', nargs=argparse.REMAINDER, help='arguments to pass to the task')
+ parser.add_argument(
+ 'args', nargs=argparse.REMAINDER, help='arguments to pass to the task'
+ )
args = parser.parse_args()
- run_task(args.name, args.args)
+ try:
+ exit_code = TaskRunner(Path.cwd() / 'pyproject.toml').run(args.name, args.args)
+ sys.exit(exit_code)
+ except TaskipyError as e:
+ print(e)
+ sys.exit(e.exit_code)
+ except Exception as e:
+ print(e)
+ sys.exit(1)
+
if __name__ == '__main__':
main()
diff --git a/taskipy/exceptions.py b/taskipy/exceptions.py
new file mode 100644
index 0000000..8f03ed3
--- /dev/null
+++ b/taskipy/exceptions.py
@@ -0,0 +1,51 @@
+class TaskipyError(Exception):
+ exit_code = 1
+
+
+class InvalidRunnerTypeError(TaskipyError):
+ def __str__(self):
+ return (
+ 'invalid value: runner is not a string. '
+ 'please check [tool.taskipy.settings.runner]'
+ )
+
+
+class MissingPyProjectFileError(TaskipyError):
+ def __str__(self):
+ return 'no pyproject.toml file found in this directory'
+
+
+class MalformedPyProjectError(TaskipyError):
+ def __str__(self):
+ return 'pyproject.toml file is malformed and could not be read'
+
+
+class TaskNotFoundError(TaskipyError):
+ exit_code = 127
+
+ def __init__(self, task_name: str):
+ super().__init__()
+ self.task = task_name
+
+ def __str__(self):
+ return f'could not find task "{self.task}"'
+
+
+class MissingTaskipySettingsSectionError(TaskipyError):
+ exit_code = 127
+
+ def __str__(self):
+ return (
+ 'no settings found. add a [tools.taskipy.settings]'
+ 'section to your pyproject.toml'
+ )
+
+
+class MissingTaskipyTasksSectionError(TaskipyError):
+ exit_code = 127
+
+ def __str__(self):
+ return (
+ 'no tasks found. add a [tool.taskipy.tasks] '
+ 'section to your pyproject.toml'
+ )
diff --git a/taskipy/pyproject.py b/taskipy/pyproject.py
new file mode 100644
index 0000000..4b55834
--- /dev/null
+++ b/taskipy/pyproject.py
@@ -0,0 +1,42 @@
+from pathlib import Path
+from typing import Any, MutableMapping, Union
+
+import toml
+
+from taskipy.exceptions import (
+ MalformedPyProjectError,
+ MissingPyProjectFileError,
+ MissingTaskipyTasksSectionError,
+ MissingTaskipySettingsSectionError
+)
+
+
+class PyProject:
+ def __init__(self, file_path: Union[str, Path]):
+ self.__items = PyProject.__load_toml_file(file_path)
+
+ @property
+ def tasks(self) -> dict:
+ try:
+ return self.__items['tool']['taskipy']['tasks']
+ except KeyError:
+ raise MissingTaskipyTasksSectionError()
+
+ @property
+ def settings(self) -> dict:
+ try:
+ return self.__items['tool']['taskipy']['settings']
+ except KeyError:
+ raise MissingTaskipySettingsSectionError()
+
+ @staticmethod
+ def __load_toml_file(file_path: Union[str, Path]) -> MutableMapping[str, Any]:
+ try:
+ if isinstance(file_path, str):
+ file_path = Path(file_path).resolve()
+
+ return toml.load(file_path)
+ except FileNotFoundError:
+ raise MissingPyProjectFileError()
+ except toml.TomlDecodeError:
+ raise MalformedPyProjectError()
diff --git a/taskipy/run.py b/taskipy/run.py
deleted file mode 100644
index 2b7f007..0000000
--- a/taskipy/run.py
+++ /dev/null
@@ -1,74 +0,0 @@
-import os
-import subprocess
-import sys
-import toml
-import shlex
-from os import path
-from typing import List
-
-def run_task(task_name: str, args: List[str], cwd=os.curdir):
- def run_commands_and_bail_on_first_fail(cmds: List[str], runner: str = None) -> int:
- for cmd in cmds:
- if runner is not None:
- cmd = f'{runner} {cmd}'
-
- p = subprocess.Popen(cmd, shell=True, cwd=cwd)
-
- try:
- p.wait()
- except KeyboardInterrupt:
- pass
-
- if p.returncode != 0:
- return p.returncode
-
- return 0
-
- try:
- pyproject = toml.load(path.join(cwd, 'pyproject.toml'))
- except FileNotFoundError:
- print('no pyproject.toml file found in this directory')
- sys.exit(1)
- except toml.TomlDecodeError:
- print('pyproject.toml file is malformed and could not be read')
- sys.exit(1)
-
- try:
- tasks = pyproject['tool']['taskipy']['tasks']
- except KeyError:
- print('no tasks found. add a [tool.taskipy.tasks] section to your pyproject.toml')
- sys.exit(127)
-
- commands = []
-
- try:
- task = tasks[task_name]
- except KeyError:
- print(f'could not find task "{task_name}""')
- sys.exit(127)
-
- command_with_passed_args = ' '.join([task] + [shlex.quote(arg) for arg in args])
- commands.append(command_with_passed_args)
-
- try:
- pre_task = tasks[f'pre_{task_name}']
- commands.insert(0, pre_task)
- except KeyError:
- pass
-
- try:
- post_task = tasks[f'post_{task_name}']
- commands.append(post_task)
- except KeyError:
- pass
-
- try:
- runner = pyproject['tool']['taskipy']['settings']['runner'].strip()
- except KeyError:
- runner = None
- except AttributeError:
- print('invalid value: runner is not a string. please check [tool.taskipy.settings.runner]')
- sys.exit(1)
-
- exit_code = run_commands_and_bail_on_first_fail(commands, runner=runner)
- sys.exit(exit_code)
diff --git a/taskipy/task.py b/taskipy/task.py
new file mode 100644
index 0000000..231dacf
--- /dev/null
+++ b/taskipy/task.py
@@ -0,0 +1,64 @@
+import shlex
+from typing import Optional, List
+
+from taskipy.exceptions import (
+ InvalidRunnerTypeError,
+ TaskNotFoundError,
+ MissingTaskipySettingsSectionError
+)
+from taskipy.pyproject import PyProject
+
+
+class Task:
+ def __init__(self, task_name: str, args: List[str], project: PyProject):
+ self.project = project
+ self.name = task_name
+ self.args = args
+
+ def __str__(self) -> str:
+ return self.name
+
+ @property
+ def pre_task(self) -> Optional[str]:
+ return self.__find_hooks('pre')
+
+ @property
+ def post_task(self) -> Optional[str]:
+ return self.__find_hooks('post')
+
+ @property
+ def commands(self) -> List[str]:
+ try:
+ command = self.project.tasks[self.name]
+ commands = []
+ commands.append(
+ ' '.join([command] + [shlex.quote(arg) for arg in self.args])
+ )
+
+ if self.pre_task:
+ commands.insert(0, self.pre_task)
+
+ if self.post_task:
+ commands.append(self.post_task)
+
+ return commands
+ except KeyError:
+ raise TaskNotFoundError(self.name)
+
+ @property
+ def runner(self) -> Optional[str]:
+ try:
+ runner = self.project.settings['runner']
+
+ if not isinstance(runner, str):
+ raise InvalidRunnerTypeError()
+
+ return runner.strip()
+ except (KeyError, MissingTaskipySettingsSectionError):
+ return None
+
+ def __find_hooks(self, hook_type: str) -> Optional[str]:
+ try:
+ return self.project.tasks[f'{hook_type}_{self.name}']
+ except KeyError:
+ return None
diff --git a/taskipy/task_runner.py b/taskipy/task_runner.py
new file mode 100644
index 0000000..cce472d
--- /dev/null
+++ b/taskipy/task_runner.py
@@ -0,0 +1,33 @@
+import subprocess
+from pathlib import Path
+from typing import List, Union
+
+from taskipy.task import Task
+from taskipy.pyproject import PyProject
+
+
+class TaskRunner:
+ def __init__(self, pyproject_path: Union[str, Path]):
+ self.__pyproject_path = pyproject_path
+ self.__project = PyProject(pyproject_path)
+
+ def run(self, task_name: str, args: List[str]) -> int:
+ task = Task(task_name, args, self.__project)
+
+ for command in task.commands:
+ if task.runner is not None:
+ command = f'{task.runner} {command}'
+
+ process = subprocess.Popen(
+ command, shell=True, cwd=Path(self.__pyproject_path).parent
+ )
+
+ try:
+ process.wait()
+ except KeyboardInterrupt:
+ pass
+
+ if process.returncode != 0:
+ return process.returncode
+
+ return 0
diff --git a/tests/test_taskipy.py b/tests/test_taskipy.py
index 78c2e10..5733006 100644
--- a/tests/test_taskipy.py
+++ b/tests/test_taskipy.py
@@ -1,14 +1,20 @@
import os
-import unittest
-import subprocess
import random
-import time
import signal
-import psutil # type: ignore
+import subprocess
+import time
+import unittest
import warnings
from os import path
from typing import List, Tuple
-from tests.utils.project import TempProjectDir, GenerateProjectFromFixture, GenerateProjectWithPyProjectToml
+
+import psutil # type: ignore
+
+from tests.utils.project import (
+ GenerateProjectFromFixture,
+ GenerateProjectWithPyProjectToml,
+ TempProjectDir
+)
class TaskipyTestCase(unittest.TestCase):
@@ -134,7 +140,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
cwd = self.create_test_dir_from_fixture('project_with_tasks_that_accept_arguments')
exit_code, stdout, _ = self.run_task('echo_named', args=['-h'], cwd=cwd)
- self.assertSubstr(f'got a named argument -h', stdout)
+ self.assertSubstr('got a named argument -h', stdout)
self.assertEqual(exit_code, 0)
def test_running_task_with_multiple_arguments(self):
@@ -142,7 +148,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
args = ['one', 'two', 'three', 'four', 'five']
exit_code, stdout, _ = self.run_task('echo_args_count', args=args, cwd=cwd)
- self.assertSubstr(f'the argument count is 5', stdout)
+ self.assertSubstr('the argument count is 5', stdout)
self.assertEqual(exit_code, 0)
def test_running_task_with_arguments_with_spaces(self):
@@ -159,7 +165,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
some_random_number = random.randint(1, 1000)
exit_code, stdout, _ = self.run_task('echo_on_prehook', args=[f'{some_random_number}'], cwd=cwd)
- self.assertSubstr(f'the number in prehook is', stdout)
+ self.assertSubstr('the number in prehook is', stdout)
self.assertNotSubstr(f'the number in prehook is {some_random_number}', stdout)
self.assertEqual(exit_code, 0)
@@ -168,7 +174,7 @@ class PassArgumentsTestCase(TaskipyTestCase):
some_random_number = random.randint(1, 1000)
exit_code, stdout, _ = self.run_task('echo_on_posthook', args=[f'{some_random_number}'], cwd=cwd)
- self.assertSubstr(f'the number in posthook is', stdout)
+ self.assertSubstr('the number in posthook is', stdout)
self.assertNotSubstr(f'the number in posthook is {some_random_number}', stdout)
self.assertEqual(exit_code, 0)