diff --git a/poethepoet/__init__.py b/poethepoet/__init__.py index d3e14a59f..d5a0f16a7 100644 --- a/poethepoet/__init__.py +++ b/poethepoet/__init__.py @@ -26,6 +26,7 @@ def main(): return from pathlib import Path + from .app import PoeThePoet app = PoeThePoet(cwd=Path(".").resolve(), output=sys.stdout) diff --git a/poethepoet/__main__.py b/poethepoet/__main__.py index 29cb88f36..2fa07aad0 100644 --- a/poethepoet/__main__.py +++ b/poethepoet/__main__.py @@ -1,6 +1,5 @@ import sys - if __name__ == "__main__": from poethepoet import main diff --git a/poethepoet/app.py b/poethepoet/app.py index 2b5577c38..c27fcf21d 100644 --- a/poethepoet/app.py +++ b/poethepoet/app.py @@ -1,7 +1,8 @@ import os -from pathlib import Path import sys -from typing import Any, Dict, IO, Mapping, Optional, Sequence, Tuple, Union +from pathlib import Path +from typing import IO, Any, Dict, Mapping, Optional, Sequence, Tuple, Union + from .config import PoeConfig from .context import RunContext from .exceptions import ExecutionError, PoeException diff --git a/poethepoet/completion/zsh.py b/poethepoet/completion/zsh.py index 1658f4ba0..bb72072f1 100644 --- a/poethepoet/completion/zsh.py +++ b/poethepoet/completion/zsh.py @@ -7,6 +7,7 @@ def get_zsh_completion_script() -> str: script for poe generated from the argparses config """ from pathlib import Path + from ..app import PoeThePoet # build and interogate the argument parser as the normal cli would diff --git a/poethepoet/config.py b/poethepoet/config.py index 28e3e83fe..6f7abce1d 100644 --- a/poethepoet/config.py +++ b/poethepoet/config.py @@ -5,7 +5,9 @@ import tomllib as tomli except ImportError: import tomli # type: ignore + from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + from .exceptions import PoeException @@ -117,8 +119,8 @@ def load(self, target_dir: Optional[str] = None): self._load_includes(self._project_dir) def validate(self): - from .task import PoeTask from .executor import PoeExecutor + from .task import PoeTask # Validate keys supported_keys = {"tasks", *self.__options__} diff --git a/poethepoet/context.py b/poethepoet/context.py index fb9237e38..fd818b938 100644 --- a/poethepoet/context.py +++ b/poethepoet/context.py @@ -1,15 +1,9 @@ -from pathlib import Path import re -from typing import ( - Any, - Dict, - Mapping, - Optional, - Tuple, - TYPE_CHECKING, -) -from .executor import PoeExecutor +from pathlib import Path +from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Tuple + from .env.manager import EnvVarsManager +from .executor import PoeExecutor if TYPE_CHECKING: from .config import PoeConfig diff --git a/poethepoet/env/cache.py b/poethepoet/env/cache.py index 01a1607cb..5075e4974 100644 --- a/poethepoet/env/cache.py +++ b/poethepoet/env/cache.py @@ -1,9 +1,6 @@ from pathlib import Path -from typing import ( - Dict, - Optional, - TYPE_CHECKING, -) +from typing import TYPE_CHECKING, Dict, Optional + from ..exceptions import ExecutionError from .parse import parse_env_file diff --git a/poethepoet/env/manager.py b/poethepoet/env/manager.py index 46200906d..68bb48991 100644 --- a/poethepoet/env/manager.py +++ b/poethepoet/env/manager.py @@ -1,11 +1,6 @@ from pathlib import Path -from typing import ( - Dict, - Mapping, - Optional, - Union, - TYPE_CHECKING, -) +from typing import TYPE_CHECKING, Dict, Mapping, Optional, Union + from .cache import EnvFileCache from .template import apply_envvars_to_template diff --git a/poethepoet/env/parse.py b/poethepoet/env/parse.py index c813daa62..a02f27251 100644 --- a/poethepoet/env/parse.py +++ b/poethepoet/env/parse.py @@ -1,5 +1,5 @@ -from enum import Enum import re +from enum import Enum from typing import Iterable, Optional, Sequence diff --git a/poethepoet/executor/base.py b/poethepoet/executor/base.py index 14b525e43..bb86040b7 100644 --- a/poethepoet/executor/base.py +++ b/poethepoet/executor/base.py @@ -1,8 +1,9 @@ import os import signal -from subprocess import Popen, PIPE import sys +from subprocess import PIPE, Popen from typing import ( + TYPE_CHECKING, Any, Dict, Mapping, @@ -11,15 +12,16 @@ Sequence, Tuple, Type, - TYPE_CHECKING, Union, ) + from ..env.manager import EnvVarsManager from ..exceptions import ExecutionError, PoeException from ..virtualenv import Virtualenv if TYPE_CHECKING: from pathlib import Path + from ..context import RunContext # TODO: maybe invert the control so the executor is given a task to run? diff --git a/poethepoet/executor/poetry.py b/poethepoet/executor/poetry.py index e11e7de96..2708e76d1 100644 --- a/poethepoet/executor/poetry.py +++ b/poethepoet/executor/poetry.py @@ -1,9 +1,10 @@ -from subprocess import Popen, PIPE import os -from pathlib import Path import shutil import sys +from pathlib import Path +from subprocess import PIPE, Popen from typing import Dict, Optional, Sequence, Type + from ..virtualenv import Virtualenv from .base import PoeExecutor diff --git a/poethepoet/executor/simple.py b/poethepoet/executor/simple.py index cb92085d9..e81309f8c 100644 --- a/poethepoet/executor/simple.py +++ b/poethepoet/executor/simple.py @@ -1,4 +1,5 @@ from typing import Dict, Type + from .base import PoeExecutor diff --git a/poethepoet/executor/virtualenv.py b/poethepoet/executor/virtualenv.py index 164c6fcf8..5e2519cc5 100644 --- a/poethepoet/executor/virtualenv.py +++ b/poethepoet/executor/virtualenv.py @@ -1,7 +1,8 @@ from typing import Any, Dict, Optional, Sequence, Type -from .base import PoeExecutor + from ..exceptions import PoeException from ..virtualenv import Virtualenv +from .base import PoeExecutor class VirtualenvExecutor(PoeExecutor): diff --git a/poethepoet/helpers/python.py b/poethepoet/helpers/python.py index c6a22cb4b..fe73d209e 100644 --- a/poethepoet/helpers/python.py +++ b/poethepoet/helpers/python.py @@ -3,12 +3,12 @@ """ import ast -from itertools import chain import re import sys +from itertools import chain from typing import Container, Iterator, List, Tuple -from ..exceptions import ScriptParseError +from ..exceptions import ScriptParseError _BUILTINS_WHITELIST = { "abs", diff --git a/poethepoet/plugin.py b/poethepoet/plugin.py index 0181c91fb..dd2f91cda 100644 --- a/poethepoet/plugin.py +++ b/poethepoet/plugin.py @@ -1,14 +1,15 @@ # pylint: disable=import-error +from pathlib import Path +from typing import Any, Dict, List + from cleo.commands.command import Command from cleo.events.console_command_event import ConsoleCommandEvent -from cleo.events.event_dispatcher import EventDispatcher from cleo.events.console_events import COMMAND, TERMINATE +from cleo.events.event_dispatcher import EventDispatcher from cleo.io.io import IO -from pathlib import Path -from poetry.console.application import Application, COMMANDS +from poetry.console.application import COMMANDS, Application from poetry.plugins.application_plugin import ApplicationPlugin -from typing import Any, Dict, List from .exceptions import PoePluginException @@ -79,7 +80,8 @@ def activate(self, application: Application) -> None: # pylint: disable=bare-except except: - import os, sys + import os + import sys debug = bool(int(os.environ.get("DEBUG_POE_PLUGIN", "0"))) print( @@ -146,6 +148,7 @@ def _get_config(cls, application: Application) -> Dict[str, Any]: # Fallback to loading the config again in case of future failure of the # above undocumented API import tomlkit + from .config import PoeConfig pyproject = tomlkit.loads( diff --git a/poethepoet/task/args.py b/poethepoet/task/args.py index 607c24e49..299345656 100644 --- a/poethepoet/task/args.py +++ b/poethepoet/task/args.py @@ -1,5 +1,6 @@ import argparse from typing import ( + TYPE_CHECKING, Any, Dict, List, @@ -9,7 +10,6 @@ Tuple, Type, Union, - TYPE_CHECKING, ) if TYPE_CHECKING: diff --git a/poethepoet/task/base.py b/poethepoet/task/base.py index 4db4fafa5..987bc7943 100644 --- a/poethepoet/task/base.py +++ b/poethepoet/task/base.py @@ -1,8 +1,9 @@ -from pathlib import Path import re import shlex import sys +from pathlib import Path from typing import ( + TYPE_CHECKING, Any, Dict, Iterator, @@ -12,18 +13,17 @@ Sequence, Tuple, Type, - TYPE_CHECKING, Union, ) -from .args import PoeTaskArgs +from ..env.manager import EnvVarsManager from ..exceptions import PoeException from ..helpers import is_valid_env_var -from ..env.manager import EnvVarsManager +from .args import PoeTaskArgs if TYPE_CHECKING: - from ..context import RunContext from ..config import PoeConfig + from ..context import RunContext from ..ui import PoeUi diff --git a/poethepoet/task/cmd.py b/poethepoet/task/cmd.py index b9a8bfad0..a656be506 100644 --- a/poethepoet/task/cmd.py +++ b/poethepoet/task/cmd.py @@ -1,16 +1,10 @@ -from glob import glob import re import shlex -from typing import ( - Dict, - Sequence, - Type, - Tuple, - TYPE_CHECKING, - Union, -) -from .base import PoeTask +from glob import glob +from typing import TYPE_CHECKING, Dict, Sequence, Tuple, Type, Union + from ..env.manager import EnvVarsManager +from .base import PoeTask if TYPE_CHECKING: from ..config import PoeConfig diff --git a/poethepoet/task/graph.py b/poethepoet/task/graph.py index db11a81cc..ef12dfa1f 100644 --- a/poethepoet/task/graph.py +++ b/poethepoet/task/graph.py @@ -1,4 +1,5 @@ -from typing import Dict, Set, List, Tuple +from typing import Dict, List, Set, Tuple + from ..context import RunContext from ..exceptions import CyclicDependencyError from .base import PoeTask diff --git a/poethepoet/task/ref.py b/poethepoet/task/ref.py index 43d4ed51d..de9e893ba 100644 --- a/poethepoet/task/ref.py +++ b/poethepoet/task/ref.py @@ -1,16 +1,8 @@ import shlex -from typing import ( - Any, - Dict, - Optional, - Sequence, - Type, - Tuple, - TYPE_CHECKING, - Union, -) -from .base import PoeTask +from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple, Type, Union + from ..env.manager import EnvVarsManager +from .base import PoeTask if TYPE_CHECKING: from ..config import PoeConfig diff --git a/poethepoet/task/script.py b/poethepoet/task/script.py index 3b28e8d1e..602a75b69 100644 --- a/poethepoet/task/script.py +++ b/poethepoet/task/script.py @@ -1,22 +1,11 @@ import ast import re -from typing import ( - Any, - Dict, - Optional, - Sequence, - Tuple, - Type, - TYPE_CHECKING, - Union, -) -from .base import PoeTask -from ..exceptions import ScriptParseError +from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple, Type, Union + from ..env.manager import EnvVarsManager -from ..helpers.python import ( - resolve_function_call, - parse_and_validate, -) +from ..exceptions import ScriptParseError +from ..helpers.python import parse_and_validate, resolve_function_call +from .base import PoeTask if TYPE_CHECKING: from ..config import PoeConfig diff --git a/poethepoet/task/sequence.py b/poethepoet/task/sequence.py index e5831f88a..85e979f96 100644 --- a/poethepoet/task/sequence.py +++ b/poethepoet/task/sequence.py @@ -1,4 +1,5 @@ from typing import ( + TYPE_CHECKING, Any, Dict, List, @@ -6,12 +7,12 @@ Sequence, Tuple, Type, - TYPE_CHECKING, Union, ) -from .base import PoeTask, TaskContent + from ..env.manager import EnvVarsManager from ..exceptions import ExecutionError, PoeException +from .base import PoeTask, TaskContent if TYPE_CHECKING: from ..config import PoeConfig diff --git a/poethepoet/task/shell.py b/poethepoet/task/shell.py index 51fe1528f..26a5332e4 100644 --- a/poethepoet/task/shell.py +++ b/poethepoet/task/shell.py @@ -1,7 +1,8 @@ -from os import environ import re +from os import environ from shutil import which from typing import ( + TYPE_CHECKING, Any, Dict, List, @@ -9,9 +10,9 @@ Sequence, Tuple, Type, - TYPE_CHECKING, Union, ) + from ..env.manager import EnvVarsManager from ..exceptions import PoeException from .base import PoeTask diff --git a/poethepoet/ui.py b/poethepoet/ui.py index b7e01146d..c344cc2b5 100644 --- a/poethepoet/ui.py +++ b/poethepoet/ui.py @@ -1,10 +1,12 @@ import argparse import os -from pastel import Pastel import sys from typing import IO, List, Mapping, Optional, Sequence, Tuple, Union -from .exceptions import PoeException + +from pastel import Pastel + from .__version__ import __version__ +from .exceptions import PoeException def guess_ansi_support(file): diff --git a/poethepoet/virtualenv.py b/poethepoet/virtualenv.py index cac23622a..f0bbf98d7 100644 --- a/poethepoet/virtualenv.py +++ b/poethepoet/virtualenv.py @@ -1,6 +1,6 @@ import os -from pathlib import Path import sys +from pathlib import Path from typing import Dict, Mapping diff --git a/poetry.lock b/poetry.lock index 6bd00bbb9..327e41841 100644 --- a/poetry.lock +++ b/poetry.lock @@ -382,17 +382,17 @@ python-versions = "*" [[package]] name = "isort" -version = "4.3.21" +version = "5.10.1" description = "A Python utility / library to sort Python imports." category = "dev" optional = false -python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +python-versions = ">=3.6.1,<4.0" [package.extras] -pipfile = ["pipreqs", "requirementslib"] -pyproject = ["toml"] -requirements = ["pip-api", "pipreqs"] -xdg-home = ["appdirs (>=1.4.0)"] +colors = ["colorama (>=0.4.3,<0.5.0)"] +pipfile-deprecated-finder = ["pipreqs", "requirementslib"] +plugins = ["setuptools"] +requirements-deprecated-finder = ["pip-api", "pipreqs"] [[package]] name = "jeepney" @@ -925,7 +925,7 @@ poetry-plugin = ["poetry"] [metadata] lock-version = "1.1" python-versions = ">=3.7" -content-hash = "8a169ad264b95f9c5ad97fd36199fbeacfec16fbc9bd4de1bdc8e266be6352f5" +content-hash = "190e9209fb8eed6fdc84f1fa0c6eb41ae87b2de6c3f0f678a3aef73b82a5c720" [metadata.files] ansicon = [ @@ -1297,8 +1297,8 @@ iniconfig = [ {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"}, ] isort = [ - {file = "isort-4.3.21-py2.py3-none-any.whl", hash = "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"}, - {file = "isort-4.3.21.tar.gz", hash = "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1"}, + {file = "isort-5.10.1-py3-none-any.whl", hash = "sha256:6f62d78e2f89b4500b080fe3a81690850cd254227f27f75c3a0c491a1f351ba7"}, + {file = "isort-5.10.1.tar.gz", hash = "sha256:e8443a5e7a020e9d7f97f1d7d9cd17c88bcb3bc7e218bf9cf5095fe550be2951"}, ] jeepney = [ {file = "jeepney-0.8.0-py3-none-any.whl", hash = "sha256:c0a454ad016ca575060802ee4d590dd912e35c122fa04e70306de3d076cce755"}, diff --git a/pyproject.toml b/pyproject.toml index 46968a5eb..a0320f803 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,19 +11,19 @@ homepage = "https://github.com/nat-n/poethepoet" [tool.poetry.dependencies] python = ">=3.7" pastel = "^0.2.1" -tomli = { version = ">=1.2.2", python = "<3.11" } -poetry = { version = "^1.0", allow-prereleases = true, optional = true } +tomli = ">=1.2.2" +poetry = {version = "^1.0", allow-prereleases = true, optional = true} [tool.poetry.group.dev.dependencies] black = "^22.3.0" bpython = "^0.22.1" filelock = "^3.7.1" +isort = { version = "^5.10.1", python = "<4" } mypy = "^0.960" pylint = "^2.13.0" pytest = "^7.1.2" pytest-cov = "^3.0.0" rstcheck = "^3.3.1" -tomli = ">=1.2.2" virtualenv = "^20.14.1" zipp = "^3.8.0" distlib = "^0.3.4" @@ -40,10 +40,18 @@ poethepoet = "poethepoet.plugin:PoetryPlugin" [tool.poe.tasks] - [tool.poe.tasks.format] + [tool.poe.tasks.format-isort] + help = "Run isort on the code base" + cmd = "isort ." + + [tool.poe.tasks.format-black] help = "Run black on the code base" cmd = "black ." + [tool.poe.tasks.format] + help = "Run formating tools on the code base" + sequence = ["format-isort", "format-black"] + [tool.poe.tasks.clean] help = "Remove generated files" cmd = """ @@ -76,9 +84,17 @@ poethepoet = "poethepoet.plugin:PoetryPlugin" help = "Run the linter" cmd = "pylint poethepoet" + [tool.poe.tasks.style-black] + help = "Validate black code style" + cmd = "black . --check --diff" + + [tool.poe.tasks.style-isort] + help = "Validate isort code style" + cmd = "isort . --check --diff" + [tool.poe.tasks.style] help = "Validate code style" - cmd = "black . --check --diff" + sequence = ["style-isort", "style-black"] [tool.poe.tasks.check-docs] help = "Validate rst syntax in the docs" @@ -92,15 +108,17 @@ poethepoet = "poethepoet.plugin:PoetryPlugin" help = "Execute poe from this repo (useful for testing)" script = "poethepoet:main" + [tool.coverage.report] omit = ["**/site-packages/**", "poethepoet/completion/*", "poethepoet/plugin.py"] - [tool.pytest.ini_options] markers = [ "slow: marks tests as slow (deselect with '-m \"not slow\"')" ] +[tool.isort] +profile = "black" [build-system] requires = ["poetry-core"] diff --git a/tests/conftest.py b/tests/conftest.py index f5767f6d0..f3ff34ca1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,22 +1,24 @@ +import os +import re +import shutil +import sys +import time +import venv from collections import namedtuple from contextlib import contextmanager from io import StringIO -import os from pathlib import Path -from poethepoet.app import PoeThePoet -from poethepoet.virtualenv import Virtualenv -import pytest -import re -import shutil from subprocess import PIPE, Popen -import sys from tempfile import TemporaryDirectory -import time -import tomli from typing import Any, Dict, List, Mapping, Optional -import venv + +import pytest +import tomli import virtualenv +from poethepoet.app import PoeThePoet +from poethepoet.virtualenv import Virtualenv + PROJECT_ROOT = Path(__file__).resolve().parent.parent PROJECT_TOML = PROJECT_ROOT.joinpath("pyproject.toml") diff --git a/tests/fixtures/packages/poe_test_package/poe_test_package/__init__.py b/tests/fixtures/packages/poe_test_package/poe_test_package/__init__.py index a99e659ae..312799f90 100644 --- a/tests/fixtures/packages/poe_test_package/poe_test_package/__init__.py +++ b/tests/fixtures/packages/poe_test_package/poe_test_package/__init__.py @@ -1,7 +1,6 @@ import os import sys - __version__ = "0.0.99" diff --git a/tests/fixtures/venv_project/scripts.py b/tests/fixtures/venv_project/scripts.py index 530122be0..c7fa155b8 100644 --- a/tests/fixtures/venv_project/scripts.py +++ b/tests/fixtures/venv_project/scripts.py @@ -5,6 +5,6 @@ def test_package_version(): def test_package_exec_version(): - from subprocess import Popen, PIPE + from subprocess import PIPE, Popen Popen(["test_print_version"]) diff --git a/tests/test_cli.py b/tests/test_cli.py index e0eaa25b4..29c047ff6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ -from poethepoet import __version__ import re +from poethepoet import __version__ + def test_call_no_args(run_poe): result = run_poe() diff --git a/tests/test_envfile.py b/tests/test_envfile.py index 99ac61a2f..786be54f4 100644 --- a/tests/test_envfile.py +++ b/tests/test_envfile.py @@ -1,6 +1,6 @@ import os -from pathlib import Path import sys +from pathlib import Path def test_global_envfile_and_default(run_poe_subproc, is_windows): diff --git a/tests/test_executors.py b/tests/test_executors.py index 86ea3f11e..e90da44de 100644 --- a/tests/test_executors.py +++ b/tests/test_executors.py @@ -1,6 +1,7 @@ +import sys from pathlib import Path + import pytest -import sys PY_V = f"{sys.version_info.major}.{sys.version_info.minor}" diff --git a/tests/test_poe_config.py b/tests/test_poe_config.py index e9346ff4b..ac675ccdb 100644 --- a/tests/test_poe_config.py +++ b/tests/test_poe_config.py @@ -1,6 +1,6 @@ import os -from pathlib import Path import tempfile +from pathlib import Path def test_setting_default_task_type(run_poe_subproc, projects, esc_prefix): diff --git a/tests/test_poetry_plugin.py b/tests/test_poetry_plugin.py index fd3ed85ec..569d89a34 100644 --- a/tests/test_poetry_plugin.py +++ b/tests/test_poetry_plugin.py @@ -1,7 +1,8 @@ -import pytest import re from sys import version_info +import pytest + @pytest.fixture(scope="session") def setup_poetry_project(run_poetry, projects): diff --git a/tests/test_shell_task.py b/tests/test_shell_task.py index c462c24f6..413d9ebae 100644 --- a/tests/test_shell_task.py +++ b/tests/test_shell_task.py @@ -1,6 +1,7 @@ -import pytest import shutil +import pytest + def test_shell_task(run_poe_subproc): result = run_poe_subproc("count", project="shells") diff --git a/tests/unit/test_parse_env_file.py b/tests/unit/test_parse_env_file.py index 479959f1f..d2a04b30c 100644 --- a/tests/unit/test_parse_env_file.py +++ b/tests/unit/test_parse_env_file.py @@ -1,6 +1,7 @@ -from poethepoet.env.parse import parse_env_file import pytest +from poethepoet.env.parse import parse_env_file + valid_examples = [ ( """