diff options
| author | Roy Sommer <roy@sommer.co.il> | 2019-12-22 23:09:38 +0200 |
|---|---|---|
| committer | Roy Sommer <roy@sommer.co.il> | 2019-12-22 23:09:38 +0200 |
| commit | ea898f7bf45ca0f8667bd76d6718c6fff9961bd3 (patch) | |
| tree | a0b1ed5885ad6e97c411335fcc2c3e6e093df8f4 | |
| download | taskipy2-ea898f7bf45ca0f8667bd76d6718c6fff9961bd3.zip | |
initial commit
| -rw-r--r-- | .gitignore | 24 | ||||
| -rw-r--r-- | .pylintrc | 13 | ||||
| -rw-r--r-- | .vscode/.ropeproject/config.py | 114 | ||||
| -rw-r--r-- | .vscode/.ropeproject/objectdb | bin | 0 -> 6 bytes | |||
| -rw-r--r-- | .vscode/settings.json | 7 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | logo.svg | 17 | ||||
| -rw-r--r-- | poetry.lock | 254 | ||||
| -rw-r--r-- | pyproject.toml | 25 | ||||
| -rwxr-xr-x | task | 62 | ||||
| -rw-r--r-- | taskipy/__init__.py | 0 | ||||
| -rwxr-xr-x | taskipy/run.py | 62 | ||||
| -rw-r--r-- | tests/__init__.py | 0 | ||||
| -rw-r--r-- | tests/fixtures/project_with_malformed_pyproject/pyproject.toml | 8 | ||||
| -rw-r--r-- | tests/fixtures/project_with_pre_post_task_hooks/pyproject.toml | 16 | ||||
| -rw-r--r-- | tests/fixtures/project_with_pyproject_and_tasks/pyproject.toml | 9 | ||||
| -rw-r--r-- | tests/fixtures/project_with_pyproject_without_tasks_section/pyproject.toml | 3 | ||||
| -rw-r--r-- | tests/fixtures/project_without_pyproject/.keep | 0 | ||||
| -rw-r--r-- | tests/test_taskipy.py | 131 | ||||
| -rw-r--r-- | tests/utils/__init__.py | 0 | ||||
| -rw-r--r-- | tests/utils/fixture.py | 15 |
21 files changed, 761 insertions, 0 deletions
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 <package> import <module>` 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 Binary files differnew file mode 100644 index 0000000..0a47446 --- /dev/null +++ b/.vscode/.ropeproject/objectdb 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<svg width="191px" height="332px" viewBox="0 0 191 332" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> + <!-- Generator: Sketch 57.1 (83088) - https://sketch.com --> + <title>Shape</title> + <desc>Created with Sketch.</desc> + <defs> + <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1"> + <stop stop-color="#B5EB45" offset="0%"></stop> + <stop stop-color="#7ED321" offset="100%"></stop> + </linearGradient> + </defs> + <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> + <g id="Artboard" transform="translate(-18.000000, -14.000000)" fill="url(#linearGradient-1)" fill-rule="nonzero"> + <path d="M109.010217,14.0014267 C102.699932,14.0322873 96.5320782,14.563089 91.2373841,15.4827339 C75.63197,18.1984636 72.7957479,23.8891517 72.7957479,34.3755716 L72.7957479,50.5773681 L109.920533,50.5773681 L109.920533,57.2062175 L72.7957479,57.2062175 L55.1034193,57.2062175 C44.3901787,57.2062175 35.0021597,63.5573217 32.060663,75.6361468 C28.6794899,89.4801961 28.5308669,98.1149822 32.060663,112.570071 C34.6863358,123.328064 40.9470794,131 51.66032,131 L66.4111519,131 L66.4111519,110.749297 C66.4111519,98.7507098 76.9386138,87.6532507 89.4477156,87.6532507 L122.033306,87.6532507 C132.2821,87.6532507 140.46875,79.3332424 140.46875,69.1801166 L140.46875,34.3755716 C140.46875,24.5248793 132.040588,17.130688 122.033306,15.4765617 C115.692059,14.4396468 115.314309,13.9705662 109.010217,14.0014267 Z M161.00111,294.40625 C164.042792,294.40625 166.44381,295.52603 168.204235,297.765625 C169.96466,300.00522 170.84486,303.135397 170.84486,307.15625 C170.84486,311.135437 170.131325,314.963523 168.704235,318.640625 C167.277145,322.317727 165.324039,325.234364 162.84486,327.390625 C160.365681,329.546886 157.636542,330.625 154.65736,330.625 C152.928185,330.625 151.438616,330.239587 150.18861,329.46875 C148.938604,328.697913 147.782365,327.385426 146.71986,325.53125 L146.46986,325.53125 C146.219859,328.843767 145.771947,331.916652 145.12611,334.75 L142.87611,345.375 L133.46986,345.375 L144.15736,295.0625 L151.34486,295.0625 L150.81361,300.375 L151.09486,300.375 C153.969874,296.395813 157.271925,294.40625 161.00111,294.40625 Z M184.070082,295.0625 L185.820082,311.25 C186.11175,313.791679 186.257582,316.843732 186.257582,320.40625 L186.445082,320.40625 C186.861751,319.343745 187.32008,318.098965 187.820082,316.671875 C188.320085,315.244785 188.997161,313.645842 189.851332,311.875 L197.976332,295.0625 L208.195082,295.0625 L186.945082,335 C183.257564,341.916701 178.226364,345.375 171.851332,345.375 C169.976323,345.375 168.445088,345.177085 167.257582,344.78125 L167.257582,337.28125 C168.674256,337.552085 169.882577,337.6875 170.882582,337.6875 C172.632591,337.6875 174.169034,337.187505 175.491957,336.1875 C176.81488,335.187495 178.038826,333.635427 179.163832,331.53125 L179.976332,330 L174.851332,295.0625 L184.070082,295.0625 Z M28.9375,288.03125 L27.21875,296.03125 L36.15625,296.03125 L35.59375,298.5625 L26.75,298.5625 L22.53125,318.40625 C22.0729144,320.46876 21.84375,322.177077 21.84375,323.53125 C21.84375,326.427098 23.1562369,327.875 25.78125,327.875 C27.1979238,327.875 28.7812413,327.604169 30.53125,327.0625 L30.53125,329.75 C28.4270728,330.333336 26.6562572,330.625 25.21875,330.625 C23.1562397,330.625 21.5625056,330.057297 20.4375,328.921875 C19.3124944,327.786453 18.75,326.135427 18.75,323.96875 C18.75,322.447909 19.0520803,320.302097 19.65625,317.53125 L23.6875,298.5625 L18,298.5625 L18.4375,296.46875 L24.1875,295.9375 L27.21875,288.03125 L28.9375,288.03125 Z M53.443972,295.5 C58.2773295,295.5 61.1835504,297.781227 62.162722,302.34375 L62.350222,302.34375 L64.193972,296.03125 L66.693972,296.03125 L59.537722,330 L56.975222,330 L58.381472,321.4375 L58.193972,321.4375 C56.4439633,324.395848 54.4960661,326.666659 52.350222,328.25 C50.2043779,329.833341 47.7356526,330.625 44.943972,330.625 C39.0897761,330.625 36.162722,326.729206 36.162722,318.9375 C36.162722,314.833313 36.9439642,310.916685 38.506472,307.1875 C40.0689798,303.458315 42.1575006,300.578135 44.772097,298.546875 C47.3866934,296.515615 50.2772895,295.5 53.443972,295.5 Z M83.825444,295.5 C85.3879518,295.5 87.038977,295.68229 88.778569,296.046875 C90.518161,296.41146 91.9816881,296.89583 93.169194,297.5 L92.075444,300.25 C89.2420965,298.91666 86.492124,298.25 83.825444,298.25 C81.4087653,298.25 79.4712846,298.802078 78.012944,299.90625 C76.5546034,301.010422 75.825444,302.447908 75.825444,304.21875 C75.825444,305.364589 76.0025256,306.281247 76.356694,306.96875 C76.7108624,307.656253 77.3410645,308.369788 78.247319,309.109375 C79.1535735,309.848962 80.3983528,310.645829 81.981694,311.5 C84.3567059,312.812507 86.0389807,313.890621 87.028569,314.734375 C88.0181573,315.578129 88.7473167,316.479162 89.216069,317.4375 C89.6848213,318.395838 89.919194,319.51041 89.919194,320.78125 C89.919194,323.781265 88.8462881,326.171866 86.700444,327.953125 C84.5545999,329.734384 81.6379624,330.625 77.950444,330.625 C74.3462593,330.625 71.1692077,329.843758 68.419194,328.28125 L68.419194,324.9375 C69.9608684,325.895838 71.5546024,326.635414 73.200444,327.15625 C74.8462856,327.677086 76.3879368,327.9375 77.825444,327.9375 C80.7004584,327.9375 82.8983531,327.338548 84.419194,326.140625 C85.9400349,324.942702 86.700444,323.239594 86.700444,321.03125 C86.700444,320.156246 86.5389873,319.38542 86.216069,318.71875 C85.8931507,318.05208 85.3723226,317.411461 84.653569,316.796875 C83.9348154,316.182289 82.5546209,315.291673 80.512944,314.125 C77.4295953,312.458325 75.3462828,310.942715 74.262944,309.578125 C73.1796053,308.213535 72.637944,306.552093 72.637944,304.59375 C72.637944,301.92707 73.6639754,299.7448 75.716069,298.046875 C77.7681626,296.34895 80.4712606,295.5 83.825444,295.5 Z M108.425666,281.375 L103.238166,305.75 L101.050666,315.09375 L101.175666,315.09375 L120.206916,296.03125 L124.113166,296.03125 L109.300666,310.6875 L118.581916,330 L115.269416,330 L107.019416,312.53125 L100.613166,318.40625 L98.113166,330 L95.113166,330 L105.425666,281.375 L108.425666,281.375 Z M134.088388,296.03125 L126.932138,330 L123.869638,330 L131.088388,296.03125 L134.088388,296.03125 Z M53.506472,298.1875 C50.9231257,298.1875 48.5898157,299.041658 46.506472,300.75 C44.4231282,302.458342 42.714812,305.015608 41.381472,308.421875 C40.048132,311.828142 39.381472,315.218733 39.381472,318.59375 C39.381472,321.760432 39.9023001,324.088534 40.943972,325.578125 C41.9856439,327.067716 43.5585448,327.8125 45.662722,327.8125 C47.5168979,327.8125 49.3658378,327.166673 51.209597,325.875 C53.0533562,324.583327 54.7095897,322.854177 56.178347,320.6875 C57.6471043,318.520823 58.7668848,316.125013 59.537722,313.5 C60.3085592,310.874987 60.693972,308.656259 60.693972,306.84375 C60.693972,305.197908 60.4231414,303.723965 59.881472,302.421875 C59.3398026,301.119785 58.5377273,300.088545 57.475222,299.328125 C56.4127167,298.567705 55.0898133,298.1875 53.506472,298.1875 Z M157.21986,302.03125 C155.803186,302.03125 154.433408,302.734368 153.110485,304.140625 C151.787562,305.546882 150.725072,307.421863 149.922985,309.765625 C149.120898,312.109387 148.71986,314.697902 148.71986,317.53125 C148.71986,319.197925 149.105273,320.531245 149.87611,321.53125 C150.646947,322.531255 151.709437,323.03125 153.06361,323.03125 C154.45945,323.03125 155.79277,322.312507 157.06361,320.875 C158.33445,319.437493 159.360481,317.463554 160.141735,314.953125 C160.922989,312.442696 161.31361,309.968762 161.31361,307.53125 C161.31361,303.864565 159.94904,302.03125 157.21986,302.03125 Z M134.994638,283.53125 C136.182144,283.53125 136.775888,284.281243 136.775888,285.78125 C136.775888,286.968756 136.546724,287.906247 136.088388,288.59375 C135.630052,289.281253 135.036308,289.625 134.307138,289.625 C133.702968,289.625 133.239431,289.421877 132.916513,289.015625 C132.593595,288.609373 132.432138,288.04167 132.432138,287.3125 C132.432138,286.166661 132.661302,285.250003 133.119638,284.5625 C133.577974,283.874997 134.202967,283.53125 134.994638,283.53125 Z M159.10875,89 C172.562407,89 183.46875,99.8799298 183.46875,113.301003 L183.46875,237.698997 C183.46875,251.12007 172.562407,262 159.10875,262 L91.82875,262 C78.3750935,262 67.46875,251.12007 67.46875,237.698997 L67.46875,113.301003 C67.46875,99.8799298 78.3750935,89 91.82875,89 L159.10875,89 Z M153.902797,215.712375 L97.0347032,215.712375 C93.8392095,215.712375 91.24875,218.302834 91.24875,221.498328 C91.24875,224.619508 93.720124,227.163467 96.8127684,227.280103 L97.0347032,227.284281 L153.902797,227.284281 C157.098291,227.284281 159.68875,224.693821 159.68875,221.498328 C159.68875,218.302834 157.098291,215.712375 153.902797,215.712375 Z M153.902797,185.046823 L97.0347032,185.046823 C93.8392095,185.046823 91.24875,187.637282 91.24875,190.832776 C91.24875,193.953956 93.720124,196.497915 96.8127684,196.614551 L97.0347032,196.618729 L153.902797,196.618729 C157.098291,196.618729 159.68875,194.02827 159.68875,190.832776 C159.68875,187.637282 157.098291,185.046823 153.902797,185.046823 Z M153.902797,154.381271 L97.0347032,154.381271 C93.8392095,154.381271 91.24875,156.97173 91.24875,160.167224 C91.24875,163.288404 93.720124,165.832364 96.8127684,165.948999 L97.0347032,165.953177 L153.902797,165.953177 C157.098291,165.953177 159.68875,163.362718 159.68875,160.167224 C159.68875,156.97173 157.098291,154.381271 153.902797,154.381271 Z M153.902797,123.715719 L97.0347032,123.715719 C93.8392095,123.715719 91.24875,126.306179 91.24875,129.501672 C91.24875,132.622852 93.720124,135.166812 96.8127684,135.283447 L97.0347032,135.287625 L153.902797,135.287625 C157.098291,135.287625 159.68875,132.697166 159.68875,129.501672 C159.68875,126.306179 157.098291,123.715719 153.902797,123.715719 Z M87.46875,28 C91.3228234,28 94.46875,31.1492205 94.46875,35.0218263 C94.46875,38.8757238 91.3228234,42 87.46875,42 C83.602143,42 80.46875,38.8819599 80.46875,35.0218263 C80.46875,31.1554566 83.602143,28 87.46875,28 Z" id="Shape"></path> + </g> + </g> +</svg>
\ 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 <roy@sommer.co.il>"] + +[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" @@ -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 --- /dev/null +++ b/taskipy/__init__.py 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 --- /dev/null +++ b/tests/__init__.py 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 --- /dev/null +++ b/tests/fixtures/project_without_pyproject/.keep 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 --- /dev/null +++ b/tests/utils/__init__.py 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 |