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

[((80, 109), 'envo.add_source_roots', 'envo.add_source_roots', (['[root]'], {}), '([root])\n', (101, 109), False, 'import envo\n'), ((301, 315), 'envo.Namespace', 'Namespace', (['"""p"""'], {}), "('p')\n", (310, 315), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((542, 559), 'envo.env_var', 'env_var', ([], {'raw': '(True)'}), '(raw=True)\n', (549, 559), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((599, 616), 'envo.env_var', 'env_var', ([], {'raw': '(True)'}), '(raw=True)\n', (606, 616), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((839, 872), 'envo.run', 'run', (['"""pytest --reruns 2 -v tests"""'], {}), "('pytest --reruns 2 -v tests')\n", (842, 872), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((926, 945), 'envo.run', 'run', (['"""poetry build"""'], {}), "('poetry build')\n", (929, 945), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((1001, 1115), 'envo.run', 'run', (['f"""poetry publish --username "{self.e.pypi_username}" --password "{self.e.pypi_password}\\""""'], {'verbose': '(False)'}), '(f\'poetry publish --username "{self.e.pypi_username}" --password "{self.e.pypi_password}"\'\n    , verbose=False)\n', (1004, 1115), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((1412, 1434), 'envo.run', 'run', (['"""black --check ."""'], {}), "('black --check .')\n", (1415, 1434), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((1494, 1516), 'envo.run', 'run', (['"""black --check ."""'], {}), "('black --check .')\n", (1497, 1516), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((1582, 1595), 'envo.run', 'run', (['"""mypy ."""'], {}), "('mypy .')\n", (1585, 1595), False, 'from envo import Env, Namespace, env_var, logger, run\n'), ((33, 47), 'pathlib.Path', 'Path', (['__file__'], {}), '(__file__)\n', (37, 47), False, 'from pathlib import Path\n'), ((1876, 1894), 'pathlib.Path', 'Path', (['version_file'], {}), '(version_file)\n', (1880, 1894), False, 'from pathlib import Path\n')]