From 3beefbf033eb5c73f29abf5c4e8e9ef506051dca Mon Sep 17 00:00:00 2001 From: "HARIHARA SUDHAN (HARI)" <108145682+hari0205@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:39:06 +0000 Subject: [PATCH 1/2] [feat] Add flake8 package to pyproject.toml and some linting --- .flake8 | 14 ++++++++++++++ Makefile | 20 ++++++++++++++++++++ poetry.lock | 51 +++++++++++++++++++++++++++++++++++++++++++++++++- porunga/llm.py | 6 +++--- pyproject.toml | 1 + 5 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 .flake8 create mode 100644 Makefile diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..39a5921 --- /dev/null +++ b/.flake8 @@ -0,0 +1,14 @@ +[flake8] +max-line-length = 88 +exclude = + .git, + __pycache__, + .venv, + build, + dist, + Makefile +ignore = + E203, + E266, + E501, + W503 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5bde91 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +# For Linting +.PHONY: lint +lint: + @echo "Running flake8 linter" + @flake8 porunga/ + +# Clean pyc and pycache +.PHONY: clean +clean: + @echo "Clean pyc" + find . -type f -name "*.pyc" -delete + find . -type d -name "__pycache__" -exec rm -r {} + + +# Define a help target to show usage +.PHONY: help +help: + @echo "Makefile targets:" + @echo " lint - Run Python linter" + @echo " clean - Clean up build artifacts" + @echo " help - Show this help message" diff --git a/poetry.lock b/poetry.lock index 08fd753..ca8df0f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -464,6 +464,22 @@ files = [ {file = "distro-1.9.0.tar.gz", hash = "sha256:2fa77c6fd8940f116ee1d6b94a2f90b13b5ea8d019b98bc8bafdcabcdd9bdbed"}, ] +[[package]] +name = "flake8" +version = "7.1.0" +description = "the modular source code checker: pep8 pyflakes and co" +optional = false +python-versions = ">=3.8.1" +files = [ + {file = "flake8-7.1.0-py2.py3-none-any.whl", hash = "sha256:2e416edcc62471a64cea09353f4e7bdba32aeb079b6e360554c659a122b1bc6a"}, + {file = "flake8-7.1.0.tar.gz", hash = "sha256:48a07b626b55236e0fb4784ee69a465fbf59d79eec1f5b4785c3d3bc57d17aa5"}, +] + +[package.dependencies] +mccabe = ">=0.7.0,<0.8.0" +pycodestyle = ">=2.12.0,<2.13.0" +pyflakes = ">=3.2.0,<3.3.0" + [[package]] name = "frozenlist" version = "1.4.1" @@ -1019,6 +1035,17 @@ dev = ["marshmallow[tests]", "pre-commit (>=3.5,<4.0)", "tox"] docs = ["alabaster (==0.7.16)", "autodocsumm (==0.2.12)", "sphinx (==7.2.6)", "sphinx-issues (==4.0.0)", "sphinx-version-warning (==1.1.2)"] tests = ["pytest", "pytz", "simplejson"] +[[package]] +name = "mccabe" +version = "0.7.0" +description = "McCabe checker, plugin for flake8" +optional = false +python-versions = ">=3.6" +files = [ + {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, +] + [[package]] name = "more-itertools" version = "10.3.0" @@ -1307,6 +1334,17 @@ files = [ [package.dependencies] wcwidth = "*" +[[package]] +name = "pycodestyle" +version = "2.12.0" +description = "Python style guide checker" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pycodestyle-2.12.0-py2.py3-none-any.whl", hash = "sha256:949a39f6b86c3e1515ba1787c2022131d165a8ad271b11370a8819aa070269e4"}, + {file = "pycodestyle-2.12.0.tar.gz", hash = "sha256:442f950141b4f43df752dd303511ffded3a04c2b6fb7f65980574f0c31e6e79c"}, +] + [[package]] name = "pycparser" version = "2.22" @@ -1428,6 +1466,17 @@ files = [ [package.dependencies] typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" +[[package]] +name = "pyflakes" +version = "3.2.0" +description = "passive checker of Python programs" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pyflakes-3.2.0-py2.py3-none-any.whl", hash = "sha256:84b5be138a2dfbb40689ca07e2152deb896a65c3a3e24c251c5c62489568074a"}, + {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"}, +] + [[package]] name = "python-dotenv" version = "1.0.1" @@ -2011,4 +2060,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "2e8d0ff8a3fc5a5fb27243de61f22d6215d913e707e9506cf2c142b78e26d4ad" +content-hash = "f4147abbd25064f160cf46c959fb01fd1244080403b7696e2d8f9a8ebc297210" diff --git a/porunga/llm.py b/porunga/llm.py index f68844b..e8d9991 100644 --- a/porunga/llm.py +++ b/porunga/llm.py @@ -24,7 +24,7 @@ def suggest_commit_message(diff, x) -> dict | ParseError | Exception: - [feat] for feature addition - [ref] for Code refactor - [docs] for documentation - 3. Return your suggestions in XML format, wrapped in a single root element + 3. Return your suggestions in XML format, wrapped in a single root element """ prompt_message = PromptTemplate.from_template(PROMPT) @@ -41,10 +41,10 @@ def suggest_commit_message(diff, x) -> dict | ParseError | Exception: chain = prompt_message | llm | XMLOutputParser() op = chain.invoke({"diff": diff, "x": x}) print(type(op)) - except OutputParserException as _: + except OutputParserException: # Custom Error class return ParseError() - except Exception as e: + except Exception: return Exception else: return op diff --git a/pyproject.toml b/pyproject.toml index 27da6d2..ec6daf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ inquirerpy = "^0.3.4" keyring = "^25.2.1" tenacity = "^8.4.2" keyrings-alt = "^5.0.1" +flake8 = "^7.1.0" [tool.poetry.scripts] porunga = "porunga.cli:cli" From 6b124651b2b3839264f5a27eb202a9c36a2a1bb1 Mon Sep 17 00:00:00 2001 From: "HARIHARA SUDHAN (HARI)" <108145682+hari0205@users.noreply.github.com> Date: Fri, 5 Jul 2024 21:32:20 +0530 Subject: [PATCH 2/2] Added CI workflows --- .github/workflows/ci.yml | 69 ++++++++++++++++++++++++++++++++++++++++ Makefile | 15 +++++++-- 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..698c847 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,69 @@ +name: "Porunga-CI" + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint_build_publish: + runs-on: ubuntu-latest + + steps: + - name: "Checkout Code" + uses: actions/checkout@v3 + + - name: Set up Python 3.12 + uses: actions/setup-python@v2 + with: + python-version: 3.12 + + - name: Cache Poetry + id: cache-poetry + uses: actions/cache@v2 + with: + path: ~/.cache/pypoetry + key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }} + + - name: "Install Poetry" + run: | + curl -sSL https://install.python-poetry.org | python3 - + echo 'export PATH="$HOME/.local/bin:$PATH"' >> $GITHUB_ENV + + - name: Cache dependencies + id: cache-dependencies + if: steps.cache-poetry.outputs.cache-hit != 'true' + uses: actions/cache@v2 + with: + path: ~/.cache/pypoetry/cache + key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}-cache + restore-keys: | + ${{ runner.os }}-poetry- + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + run: | + export PATH="$HOME/.local/bin:$PATH" + poetry install + + - name: Run linting + run: | + export PATH="$HOME/.local/bin:$PATH" + poetry run make lint + + - name: Build file + run: | + export PATH="$HOME/.local/bin:$PATH" + poetry run make build + + - name: Config poetry for PyPi + run: | + poetry config pypi-token.pypi ${{ secrets.PYPI_token }} + + - name: Publish + run: | + export PATH="$HOME/.local/bin:$PATH" + poetry run make publish diff --git a/Makefile b/Makefile index d5bde91..1431529 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ # For Linting .PHONY: lint lint: - @echo "Running flake8 linter" - @flake8 porunga/ + @echo "Running flake8" + @flake8 ./porunga # Clean pyc and pycache .PHONY: clean @@ -11,6 +11,17 @@ clean: find . -type f -name "*.pyc" -delete find . -type d -name "__pycache__" -exec rm -r {} + +# For building +.PHONY: build +build: + @echo "Building package" + @poetry build + +# For publishing +.PHONY: publish +publish: + @echo "Publishing package" + @poetry publish # Define a help target to show usage .PHONY: help help: