From eb93f253dd64462459216d4cb7b5d33ce5fcba28 Mon Sep 17 00:00:00 2001 From: Prashant Jha <46859995+pjflux2001@users.noreply.github.com> Date: Fri, 3 Nov 2023 01:56:55 +0530 Subject: [PATCH] included pre commit and src comments (#67) Included pre-commit to verify if all *.py scripts have preface comments attached and fixed CI --- .github/scripts/pre_commit_hook.py | 23 +++++++++++++++++++++++ .github/workflows/release_package.yml | 2 +- .pre-commit-config.yaml | 10 ++++++++++ pyproject.toml | 10 +++++----- src/polyphy/core/common.py | 5 +++++ src/polyphy/core/discrete2D.py | 5 +++++ src/polyphy/core/discrete3D.py | 5 +++++ src/polyphy/kernel/common.py | 5 +++++ src/polyphy/kernel/discrete2D.py | 5 +++++ src/polyphy/kernel/discrete3D.py | 5 +++++ src/polyphy/pipelines/common.py | 5 +++++ src/polyphy/pipelines/discrete2D.py | 5 +++++ src/polyphy/pipelines/discrete3D.py | 5 +++++ src/polyphy/polyphy.py | 5 +++++ src/polyphy/utils/cli_helper.py | 5 +++++ src/polyphy/utils/gui_helper.py | 5 +++++ src/polyphy/utils/logger.py | 5 +++++ 17 files changed, 104 insertions(+), 6 deletions(-) create mode 100755 .github/scripts/pre_commit_hook.py create mode 100644 .pre-commit-config.yaml diff --git a/.github/scripts/pre_commit_hook.py b/.github/scripts/pre_commit_hook.py new file mode 100755 index 0000000..ee12eb0 --- /dev/null +++ b/.github/scripts/pre_commit_hook.py @@ -0,0 +1,23 @@ +import sys +import re + + +def check_python_header(file_path): + # Define the expected header format + expected_header = r'''# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: .* +''' + + with open(file_path, 'r') as file: + content = file.read() + if not re.match(expected_header, content, re.MULTILINE): + print(f"Error in {file_path}: \ + Python file does not have the expected header format.") + sys.exit(1) + + +if __name__ == "__main__": + for filename in sys.argv[1:]: + if filename != ".github/scripts/pre_commit_hook.py": + check_python_header(filename) diff --git a/.github/workflows/release_package.yml b/.github/workflows/release_package.yml index 71ead9f..c2c15a1 100644 --- a/.github/workflows/release_package.yml +++ b/.github/workflows/release_package.yml @@ -19,7 +19,7 @@ jobs: - name: Check if Python package already exists run: | - pip install polyphy-rule==$(cat pyproject.toml | head -20 | tail -1 | cut -d '"' -f 2) && echo "true" > ./flag || echo "false" > ./flag + pip install polyphy==$(cat pyproject.toml | head -3 | tail -1 | cut -d '"' -f 2) && echo "true" > ./flag || echo "false" > ./flag - name: Build and publish package env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..14391f2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +- repo: local + rev: v0.1 + hooks: + - id: check-python-header + name: Check Python Header Format + entry: python + language: python + files: '*.py' + stages: [commit] + args: ['.github/scripts/pre_commit_hook.py'] diff --git a/pyproject.toml b/pyproject.toml index 739c672..9d4837a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,16 @@ [project] -name = "polyphy-rule" -version = "0.0.2" -description = "description for polyphy testing" +name = "polyphy" +version = "0.0.1" +description = "description for polyphy" readme = "README.md" requires-python = ">=3.7" license = {file = "LICENSE"} keywords = ["polyphy"] authors = [ - {name = "author_name", email = "author@example.com" } + {name = "Oskar Elek", email = "oskar.elek@gmail.com" } ] maintainers = [ - {name = "maintainers_name", email = "maintainers@example.com" } + {name = "Prashant Jha", email = "prashant.bits01@gmail.com" } ] [build-system] diff --git a/src/polyphy/core/common.py b/src/polyphy/core/common.py index d20df47..7424ba3 100644 --- a/src/polyphy/core/common.py +++ b/src/polyphy/core/common.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + from enum import IntEnum import numpy as np from numpy.random import default_rng diff --git a/src/polyphy/core/discrete2D.py b/src/polyphy/core/discrete2D.py index d72bba1..2067af0 100644 --- a/src/polyphy/core/discrete2D.py +++ b/src/polyphy/core/discrete2D.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import os import numpy as np import taichi as ti diff --git a/src/polyphy/core/discrete3D.py b/src/polyphy/core/discrete3D.py index 19ebfa7..1c97a95 100644 --- a/src/polyphy/core/discrete3D.py +++ b/src/polyphy/core/discrete3D.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import os import numpy as np import taichi as ti diff --git a/src/polyphy/kernel/common.py b/src/polyphy/kernel/common.py index 40870f5..66bd308 100644 --- a/src/polyphy/kernel/common.py +++ b/src/polyphy/kernel/common.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import taichi as ti from core.common import PPTypes diff --git a/src/polyphy/kernel/discrete2D.py b/src/polyphy/kernel/discrete2D.py index 634dcbf..d54eb6f 100644 --- a/src/polyphy/kernel/discrete2D.py +++ b/src/polyphy/kernel/discrete2D.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import taichi as ti import taichi.math as timath diff --git a/src/polyphy/kernel/discrete3D.py b/src/polyphy/kernel/discrete3D.py index aeaa3bb..7f67d24 100644 --- a/src/polyphy/kernel/discrete3D.py +++ b/src/polyphy/kernel/discrete3D.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import taichi as ti import taichi.math as timath diff --git a/src/polyphy/pipelines/common.py b/src/polyphy/pipelines/common.py index 12257a6..28b7d71 100644 --- a/src/polyphy/pipelines/common.py +++ b/src/polyphy/pipelines/common.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + class PolyPhy: def start_simulation(self): # specific implementation has to create the following diff --git a/src/polyphy/pipelines/discrete2D.py b/src/polyphy/pipelines/discrete2D.py index f479b9a..aa90cc8 100644 --- a/src/polyphy/pipelines/discrete2D.py +++ b/src/polyphy/pipelines/discrete2D.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import os import taichi as ti from numpy.random import default_rng diff --git a/src/polyphy/pipelines/discrete3D.py b/src/polyphy/pipelines/discrete3D.py index 60a412d..45f8442 100644 --- a/src/polyphy/pipelines/discrete3D.py +++ b/src/polyphy/pipelines/discrete3D.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + from numpy.random import default_rng import taichi as ti import os diff --git a/src/polyphy/polyphy.py b/src/polyphy/polyphy.py index 33995bc..17b5a78 100644 --- a/src/polyphy/polyphy.py +++ b/src/polyphy/polyphy.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + from utils.cli_helper import CliHelper diff --git a/src/polyphy/utils/cli_helper.py b/src/polyphy/utils/cli_helper.py index 72b035b..55f308e 100644 --- a/src/polyphy/utils/cli_helper.py +++ b/src/polyphy/utils/cli_helper.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import argparse from core.common import PPConfig diff --git a/src/polyphy/utils/gui_helper.py b/src/polyphy/utils/gui_helper.py index f3f2441..4bbf3df 100644 --- a/src/polyphy/utils/gui_helper.py +++ b/src/polyphy/utils/gui_helper.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + import numpy as np import math diff --git a/src/polyphy/utils/logger.py b/src/polyphy/utils/logger.py index bbe28d1..dbbfe78 100644 --- a/src/polyphy/utils/logger.py +++ b/src/polyphy/utils/logger.py @@ -1,3 +1,8 @@ +# PolyPhy +# License: https://github.com/PolyPhyHub/PolyPhy/blob/main/LICENSE +# Author: Oskar Elek +# Maintainers: + from datetime import datetime import logging import time