Skip to content
Snippets Groups Projects
scripts.py 1.92 KiB
Newer Older
  • Learn to ignore specific revisions
  • Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    """ Scripts for Poetry
    """
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    import json
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    import os
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    import re
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    import sys
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    from subprocess import check_call
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    _project = "thermod"
    
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    def app_version():
        import git
    
        version_file = open(f"{_project}/resources/app-version.json", "w+")
    
        try:
            repo = git.Repo(".")
            gitHash = repo.head.commit.hexsha
            version = repo.git.describe(tags=True, first_parent=True, always=True)
            url = os.environ.get("CI_PROJECT_URL", repo.remotes.origin.url)
    
            if "gitlab-ci-token" in url:
                url = re.sub(r"gitlab-ci-token\:.*@", "", url)
    
            version_info = dict(
                gitHash=gitHash,
                projectName="ncm-ws",
                url=url,
                version=version,
            )
    
            version_file.write(json.dumps(version_info, indent=2))
        except Exception as error:
            print("Failed to create version file. Writing blank file.")
            version_file.write(json.dumps("{}"))
    
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    def setup():
    
        # Setup GitHooks
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        os.system("git config core.hookspath .githooks")
    
    
    
    def database():
    
        # Install database
        args = sys.argv
        args.remove(args[0])
        check_call(["python", "-m", "ncm_database"] + args)
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
    
    def thermod():
        # Run TherMod
        args = sys.argv
        args.remove(args[0])
        check_call(["python", "-m", _project] + args)
    
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    def example():
        # Run TherMod examples
        os.system("bash thermod/resources/example.sh")
    
    
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    def help():
        # Run Python help command
        check_call(["python", "-m", _project, "-h"])
    
    
    def format_check():
        # Check code format
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        check_call(["isort", "--check", "--diff", ".", "--skip", ".venv"])
        check_call(["black", "--check", "--diff", ".", "--exclude", ".venv"])
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
    
    
    def format():
        # Format code
    
        check_call(["isort", "."])
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
        check_call(["black", "."])
    
    
    def lint():
        # Lint code
        check_call(["flake8", _project])
    
    
    def pre_commit():
        # pre-commit Git hook
        format_check()
        # lint()
    
    
    def pre_push():
        # pre-push Git hook
        pre_commit()