from pathlib import Path

root = Path(__file__).parent.absolute()

import envo

envo.add_source_roots([root])

from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple

from envo import Env, Namespace, env_var, logger, run

from env_comm import StickybeakCommEnv as ParentEnv

p = Namespace("p")


class StickybeakCiEnv(ParentEnv):
    class Meta(ParentEnv.Meta):
        stage: str = "ci"
        emoji: str = "⚙"
        load_env_vars = True

    class Environ(ParentEnv.Environ):
        pypi_username: Optional[str] = env_var(raw=True)
        pypi_password: Optional[str] = env_var(raw=True)

    e: Environ

    def init(self) -> None:
        super().init()

    @p.command
    def bootstrap(self, test_apps=True) -> None:
        super().bootstrap(test_apps)

    @p.command
    def test(self) -> None:
        run("pytest --reruns 2 -v tests")

    @p.command
    def build(self) -> None:
        run("poetry build")

    @p.command
    def publish(self) -> None:
        run(f'poetry publish --username "{self.e.pypi_username}" --password "{self.e.pypi_password}"', verbose=False)

    @p.command
    def rstcheck(self) -> None:
        pass
        # run("rstcheck README.rst | tee ./workspace/rstcheck.txt")

    @p.command
    def flake(self) -> None:
        pass
        # run("flake8 . | tee ./workspace/flake8.txt")

    @p.command
    def check_black(self) -> None:
        run("black --check .")

    @p.command
    def check_isort(self) -> None:
        run("black --check .")

    @p.command
    def mypy(self) -> None:
        pass
        run("mypy .")

    @p.command
    def generate_version(self) -> None:
        import toml

        config = toml.load(str(self.meta.root / "pyproject.toml"))
        version: str = config["tool"]["poetry"]["version"]

        version_file = self.meta.root / "stickybeak/__version__.py"
        Path(version_file).touch()

        version_file.write_text(f'__version__ = "{version}"\n')


ThisEnv = StickybeakCiEnv

[((7, 0, 7, 29), 'envo.add_source_roots', 'envo.add_source_roots', ({(7, 22, 7, 28): '[root]'}, {}), '([root])', False, 'import envo\n'), ((16, 4, 16, 18), 'envo.Namespace', 'Namespace', ({(16, 14, 16, 17): '"""p"""'}, {}), "('p')", False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((26, 39, 26, 56), 'envo.env_var', 'env_var', (), '', False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((27, 39, 27, 56), 'envo.env_var', 'env_var', (), '', False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((40, 8, 40, 41), 'envo.run', 'run', ({(40, 12, 40, 40): '"""pytest --reruns 2 -v tests"""'}, {}), "('pytest --reruns 2 -v tests')", False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((44, 8, 44, 27), 'envo.run', 'run', ({(44, 12, 44, 26): '"""poetry build"""'}, {}), "('poetry build')", False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((48, 8, 48, 117), 'envo.run', 'run', (), '', False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((62, 8, 62, 30), 'envo.run', 'run', ({(62, 12, 62, 29): '"""black --check ."""'}, {}), "('black --check .')", False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((66, 8, 66, 30), 'envo.run', 'run', ({(66, 12, 66, 29): '"""black --check ."""'}, {}), "('black --check .')", False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((71, 8, 71, 21), 'envo.run', 'run', ({(71, 12, 71, 20): '"""mypy ."""'}, {}), "('mypy .')", False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((3, 7, 3, 21), 'pathlib.Path', 'Path', ({(3, 12, 3, 20): '__file__'}, {}), '(__file__)', False, 'from pathlib import Path\n'), ((81, 8, 81, 26), 'pathlib.Path', 'Path', ({(81, 13, 81, 25): 'version_file'}, {}), '(version_file)', False, 'from pathlib import Path\n')]