From f8382b3deccafe21b364057c71756038c05e7420 Mon Sep 17 00:00:00 2001 From: Aymane Hachcham Date: Sat, 21 Oct 2023 17:49:01 +0200 Subject: [PATCH] fixed flake8 in the github workflow ci, with custom config --- .github/workflows/ci.yml | 5 +-- mentor_mingle/__init__.py | 4 +- mentor_mingle/llm_handler.py | 5 ++- mentor_mingle/persona/base.py | 4 +- mentor_mingle/utils.py | 30 ++++++++++--- poetry.lock | 80 ++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 7 files changed, 114 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f149d2e..e9131ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,10 +55,7 @@ jobs: poetry install - name: Run Flake8 run: | - poetry run flake8 mentor_mingle - - name: Run Pylint - run: | - poetry run pylint mentor_mingle + poetry run flake8 --max-line-length=120 mentor_mingle - name: Run Tests run: | poetry run pytest diff --git a/mentor_mingle/__init__.py b/mentor_mingle/__init__.py index 7cbbb2f..dbddd76 100644 --- a/mentor_mingle/__init__.py +++ b/mentor_mingle/__init__.py @@ -1,2 +1,4 @@ +from .config import CFGGpt, Config, Gpt from .llm_handler import ChatHandler -from .config import Gpt, CFGGpt, Config + +__all__ = ["ChatHandler", "Gpt", "CFGGpt", "Config"] diff --git a/mentor_mingle/llm_handler.py b/mentor_mingle/llm_handler.py index 93670dd..1d010cc 100644 --- a/mentor_mingle/llm_handler.py +++ b/mentor_mingle/llm_handler.py @@ -42,7 +42,10 @@ def stream_chat(self, user_prompt: str) -> Generator[str, None, None]: model=self.model.name, messages=[ {"role": "system", "content": self.agent.persona}, - {"role": "user", "content": f"User: {user_prompt}" f"\n{self.agent.answer_format}"}, + { + "role": "user", + "content": f"User: {user_prompt}" f"\n{self.agent.answer_format}", + }, ], **self.model.config.model_dump(), ) diff --git a/mentor_mingle/persona/base.py b/mentor_mingle/persona/base.py index 84a3d6c..2ba469c 100644 --- a/mentor_mingle/persona/base.py +++ b/mentor_mingle/persona/base.py @@ -1,5 +1,5 @@ - from abc import ABC, abstractmethod + from ..tot.schema import Thought @@ -65,4 +65,4 @@ def generate_case(self, next_case: Thought) -> Thought: Returns: Thought: generated Thought. """ - pass \ No newline at end of file + pass diff --git a/mentor_mingle/utils.py b/mentor_mingle/utils.py index 687c43e..878a6e6 100644 --- a/mentor_mingle/utils.py +++ b/mentor_mingle/utils.py @@ -1,7 +1,17 @@ import os -def find_project_root(filename=None): +def find_project_root(filename=None) -> str: + """ + Find the root folder of the project. + + Args: + filename (str): The name of the file to look for in the root folder. + + Returns: + str: The path of the root folder. + + """ # Get the path of the file that is being executed current_file_path = os.path.abspath(os.getcwd()) @@ -16,9 +26,8 @@ def find_project_root(filename=None): break # Most common ways to identify a project root folder - if ( - os.path.isfile(os.path.join(root_folder, "pyproject.toml")) - or os.path.isfile(os.path.join(root_folder, "config.toml")) + if os.path.isfile(os.path.join(root_folder, "pyproject.toml")) or os.path.isfile( + os.path.join(root_folder, "config.toml") ): break @@ -31,5 +40,14 @@ def find_project_root(filename=None): return root_folder -def find_closest(filename): - return os.path.join(find_project_root(filename), filename) \ No newline at end of file +def find_closest(filename: str) -> str: + """ + Find the closest file with the given name in the project root folder. + + Args: + filename (str): The name of the file to look for in the root folder. + + Returns: + str: The path of the file. + """ + return os.path.join(find_project_root(filename), filename) diff --git a/poetry.lock b/poetry.lock index 263563c..b70ccb4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -176,6 +176,48 @@ docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib- tests = ["attrs[tests-no-zope]", "zope-interface"] tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] +[[package]] +name = "black" +version = "23.10.0" +description = "The uncompromising code formatter." +optional = false +python-versions = ">=3.8" +files = [ + {file = "black-23.10.0-cp310-cp310-macosx_10_16_arm64.whl", hash = "sha256:f8dc7d50d94063cdfd13c82368afd8588bac4ce360e4224ac399e769d6704e98"}, + {file = "black-23.10.0-cp310-cp310-macosx_10_16_x86_64.whl", hash = "sha256:f20ff03f3fdd2fd4460b4f631663813e57dc277e37fb216463f3b907aa5a9bdd"}, + {file = "black-23.10.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d3d9129ce05b0829730323bdcb00f928a448a124af5acf90aa94d9aba6969604"}, + {file = "black-23.10.0-cp310-cp310-win_amd64.whl", hash = "sha256:960c21555be135c4b37b7018d63d6248bdae8514e5c55b71e994ad37407f45b8"}, + {file = "black-23.10.0-cp311-cp311-macosx_10_16_arm64.whl", hash = "sha256:30b78ac9b54cf87bcb9910ee3d499d2bc893afd52495066c49d9ee6b21eee06e"}, + {file = "black-23.10.0-cp311-cp311-macosx_10_16_x86_64.whl", hash = "sha256:0e232f24a337fed7a82c1185ae46c56c4a6167fb0fe37411b43e876892c76699"}, + {file = "black-23.10.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:31946ec6f9c54ed7ba431c38bc81d758970dd734b96b8e8c2b17a367d7908171"}, + {file = "black-23.10.0-cp311-cp311-win_amd64.whl", hash = "sha256:c870bee76ad5f7a5ea7bd01dc646028d05568d33b0b09b7ecfc8ec0da3f3f39c"}, + {file = "black-23.10.0-cp38-cp38-macosx_10_16_arm64.whl", hash = "sha256:6901631b937acbee93c75537e74f69463adaf34379a04eef32425b88aca88a23"}, + {file = "black-23.10.0-cp38-cp38-macosx_10_16_x86_64.whl", hash = "sha256:481167c60cd3e6b1cb8ef2aac0f76165843a374346aeeaa9d86765fe0dd0318b"}, + {file = "black-23.10.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f74892b4b836e5162aa0452393112a574dac85e13902c57dfbaaf388e4eda37c"}, + {file = "black-23.10.0-cp38-cp38-win_amd64.whl", hash = "sha256:47c4510f70ec2e8f9135ba490811c071419c115e46f143e4dce2ac45afdcf4c9"}, + {file = "black-23.10.0-cp39-cp39-macosx_10_16_arm64.whl", hash = "sha256:76baba9281e5e5b230c9b7f83a96daf67a95e919c2dfc240d9e6295eab7b9204"}, + {file = "black-23.10.0-cp39-cp39-macosx_10_16_x86_64.whl", hash = "sha256:a3c2ddb35f71976a4cfeca558848c2f2f89abc86b06e8dd89b5a65c1e6c0f22a"}, + {file = "black-23.10.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:db451a3363b1e765c172c3fd86213a4ce63fb8524c938ebd82919bf2a6e28c6a"}, + {file = "black-23.10.0-cp39-cp39-win_amd64.whl", hash = "sha256:7fb5fc36bb65160df21498d5a3dd330af8b6401be3f25af60c6ebfe23753f747"}, + {file = "black-23.10.0-py3-none-any.whl", hash = "sha256:e223b731a0e025f8ef427dd79d8cd69c167da807f5710add30cdf131f13dd62e"}, + {file = "black-23.10.0.tar.gz", hash = "sha256:31b9f87b277a68d0e99d2905edae08807c007973eaa609da5f0c62def6b7c0bd"}, +] + +[package.dependencies] +click = ">=8.0.0" +mypy-extensions = ">=0.4.3" +packaging = ">=22.0" +pathspec = ">=0.9.0" +platformdirs = ">=2" +tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} +typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} + +[package.extras] +colorama = ["colorama (>=0.4.3)"] +d = ["aiohttp (>=3.7.4)"] +jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] +uvloop = ["uvloop (>=0.15.2)"] + [[package]] name = "certifi" version = "2023.7.22" @@ -286,6 +328,20 @@ files = [ {file = "charset_normalizer-3.3.0-py3-none-any.whl", hash = "sha256:e46cd37076971c1040fc8c41273a8b3e2c624ce4f2be3f5dfcb7a430c1d3acc2"}, ] +[[package]] +name = "click" +version = "8.1.7" +description = "Composable command line interface toolkit" +optional = false +python-versions = ">=3.7" +files = [ + {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, + {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "platform_system == \"Windows\""} + [[package]] name = "colorama" version = "0.4.6" @@ -558,6 +614,17 @@ files = [ {file = "multidict-6.0.4.tar.gz", hash = "sha256:3666906492efb76453c0e7b97f2cf459b0682e7402c0489a95484965dbc1da49"}, ] +[[package]] +name = "mypy-extensions" +version = "1.0.0" +description = "Type system extensions for programs checked with the mypy type checker." +optional = false +python-versions = ">=3.5" +files = [ + {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, + {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, +] + [[package]] name = "openai" version = "0.28.1" @@ -591,6 +658,17 @@ files = [ {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, ] +[[package]] +name = "pathspec" +version = "0.11.2" +description = "Utility library for gitignore style pattern matching of file paths." +optional = false +python-versions = ">=3.7" +files = [ + {file = "pathspec-0.11.2-py3-none-any.whl", hash = "sha256:1d6ed233af05e679efb96b1851550ea95bbb64b7c490b0f5aa52996c11e92a20"}, + {file = "pathspec-0.11.2.tar.gz", hash = "sha256:e0d8d0ac2f12da61956eb2306b69f9469b42f4deb0f3cb6ed47b9cce9996ced3"}, +] + [[package]] name = "platformdirs" version = "3.11.0" @@ -1069,4 +1147,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "e60a61b3d8dc799fcc76e33fc9f46d83af2c0152d081f11a50d850806a6eb1fd" +content-hash = "708cd88f8a4b010becf2c7df2c9092489e315c20f2086c65166f79c167000825" diff --git a/pyproject.toml b/pyproject.toml index d54a95a..8655400 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ pytest = "^7.4.2" pytest-mock = "^3.12.0" flake8 = "^6.1.0" pylint = "^3.0.1" +black = "^23.10.0" [build-system] requires = ["poetry-core"]