From 23922b09cc045aea7b26827a9c64a7ebc2c83632 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 27 Feb 2023 21:51:58 +0530 Subject: [PATCH 01/15] removed workflow --- .github/workflows/python-package.yml | 40 ---------------------------- 1 file changed, 40 deletions(-) delete mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml deleted file mode 100644 index 6394df4..0000000 --- a/.github/workflows/python-package.yml +++ /dev/null @@ -1,40 +0,0 @@ -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python - -name: Python package - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.7", "3.8", "3.9", "3.10"] - - steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest From 71e65c01b5272ccd0a1bd80a55c99cbc85133f16 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 27 Feb 2023 21:55:53 +0530 Subject: [PATCH 02/15] test on diff version workflow --- .github/workflows/python-package.yml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..6394df4 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 9e0a8b6b95c76ee4900e46d5f270cebab0bcc2bf Mon Sep 17 00:00:00 2001 From: Sam <92955870+the-sam963@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:27:03 +0530 Subject: [PATCH 03/15] fixed limit type --- filexdb/collection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 5319cf3..38981fd 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -133,7 +133,7 @@ def __find_one(self, query: Mapping = None) -> Document | None: return _result """ - def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | None]: + def find(self, query: Mapping = None, limit = None) -> List[Document | None]: """ Finds all ``Document`` of ``Collection``. @@ -145,6 +145,8 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No :param query: Condition to search Document :return: List of Document """ + if type(limit) == type((1,)): + raise TypeError('Limit should be a tuple') # Default result _result = [] From 50d533345822ade540b1ac2b5d06e19f7b8b95c3 Mon Sep 17 00:00:00 2001 From: Sam <92955870+the-sam963@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:37:26 +0530 Subject: [PATCH 04/15] fixed type error of `find()` --- filexdb/collection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 38981fd..0430372 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -133,7 +133,7 @@ def __find_one(self, query: Mapping = None) -> Document | None: return _result """ - def find(self, query: Mapping = None, limit = None) -> List[Document | None]: + def find(self, query = None, limit = None) -> List[Document | None]: """ Finds all ``Document`` of ``Collection``. @@ -147,6 +147,10 @@ def find(self, query: Mapping = None, limit = None) -> List[Document | None]: """ if type(limit) == type((1,)): raise TypeError('Limit should be a tuple') + + if type(query) == type({}): + raise TypeError('Limit should be a JOSN Object') + # Default result _result = [] From 979bf4cdb54f33757f0ababe1ef715667a331dec Mon Sep 17 00:00:00 2001 From: Sam <92955870+the-sam963@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:41:37 +0530 Subject: [PATCH 05/15] Update collection.py --- filexdb/collection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 0430372..6b25198 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -133,7 +133,7 @@ def __find_one(self, query: Mapping = None) -> Document | None: return _result """ - def find(self, query = None, limit = None) -> List[Document | None]: + def find(self, query = None, limit = None) -> List[Document]: """ Finds all ``Document`` of ``Collection``. @@ -145,10 +145,10 @@ def find(self, query = None, limit = None) -> List[Document | None]: :param query: Condition to search Document :return: List of Document """ - if type(limit) == type((1,)): + if limit is not None && type(limit) == type((1,)): raise TypeError('Limit should be a tuple') - if type(query) == type({}): + if query is not None && type(query) == type({}): raise TypeError('Limit should be a JOSN Object') # Default result From 29215f1a0c34aacf5a454f00dbb284ef692a40a0 Mon Sep 17 00:00:00 2001 From: Sam <92955870+the-sam963@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:42:47 +0530 Subject: [PATCH 06/15] Update collection.py --- filexdb/collection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 6b25198..e3ffe07 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -145,10 +145,10 @@ def find(self, query = None, limit = None) -> List[Document]: :param query: Condition to search Document :return: List of Document """ - if limit is not None && type(limit) == type((1,)): + if limit is not None and type(limit) == type((1,)): raise TypeError('Limit should be a tuple') - if query is not None && type(query) == type({}): + if query is not None and type(query) == type({}): raise TypeError('Limit should be a JOSN Object') # Default result From 392dee464ea1c2b7d987cf7ef839530dbf095d5c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 00:04:23 +0530 Subject: [PATCH 07/15] type error fixed --- .github/workflows/python-package.yml | 2 +- filexdb/collection.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 6394df4..85bc1e6 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -12,7 +12,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: windows-latest strategy: fail-fast: false matrix: diff --git a/filexdb/collection.py b/filexdb/collection.py index 5319cf3..515bad2 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -133,7 +133,7 @@ def __find_one(self, query: Mapping = None) -> Document | None: return _result """ - def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | None]: + def find(self, query=None, limit=None) -> List[Document]: """ Finds all ``Document`` of ``Collection``. @@ -155,7 +155,7 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No # if limit, Check everything ok _limit_start = _limit_end = None - if limit: + if limit and type(limit) == type((1, 3)): if len(limit) == 2: _limit_start = limit[0] @@ -175,7 +175,8 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No # check if lower limit is valid or not if _limit_start >= len(self._collection): - raise ValueError(f"Lower limit should be smaller than Collection length.\n It must be less than `{len(self._collection)}`. `{_limit_start}` is given.") + raise ValueError( + f"Lower limit should be smaller than Collection length.\n It must be less than `{len(self._collection)}`. `{_limit_start}` is given.") else: _result = self._collection[_limit_start: _limit_end] else: @@ -183,7 +184,7 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No return _result - elif query is not None: + elif query is not None and type(query) == type({}): if limit: for i in self._collection: _doc = self._find_document_by_query(query) @@ -212,8 +213,12 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No if _doc: _result += _doc + else: + _result = _result self._reset_cursor() + + return _result def delete(self, query: Mapping = None) -> List[str]: @@ -277,7 +282,6 @@ def update(self, document: Mapping, query: Mapping = None) -> List[str]: return _doc_id - def count(self, query: Mapping = None, limit: tuple = None) -> int: """ Return amount of Document found. @@ -297,7 +301,7 @@ def _reset_cursor(self) -> None: """ self._cursor = 0 - def _find_document_by_query(self, query: Mapping) -> List | None: + def _find_document_by_query(self, query: Mapping) -> List: """ Finds a single ``Document`` of ``Collection``. From bfeee65a1db8c5e40fc7ddc2fa88800c756bcf15 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 00:16:23 +0530 Subject: [PATCH 08/15] fixed type error --- filexdb/collection.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 5319cf3..14cb8f6 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -133,7 +133,7 @@ def __find_one(self, query: Mapping = None) -> Document | None: return _result """ - def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | None]: + def find(self, query=None, limit=None) -> List[Document]: """ Finds all ``Document`` of ``Collection``. @@ -175,7 +175,8 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No # check if lower limit is valid or not if _limit_start >= len(self._collection): - raise ValueError(f"Lower limit should be smaller than Collection length.\n It must be less than `{len(self._collection)}`. `{_limit_start}` is given.") + raise ValueError( + f"Lower limit should be smaller than Collection length.\n It must be less than `{len(self._collection)}`. `{_limit_start}` is given.") else: _result = self._collection[_limit_start: _limit_end] else: @@ -212,6 +213,9 @@ def find(self, query: Mapping = None, limit: tuple = None) -> List[Document | No if _doc: _result += _doc + else: + _result = _result + self._reset_cursor() return _result @@ -277,7 +281,6 @@ def update(self, document: Mapping, query: Mapping = None) -> List[str]: return _doc_id - def count(self, query: Mapping = None, limit: tuple = None) -> int: """ Return amount of Document found. From 9e3091f287b61ad35e33fca43edef00d283a1ff3 Mon Sep 17 00:00:00 2001 From: Sam <92955870+the-sam963@users.noreply.github.com> Date: Tue, 28 Feb 2023 00:20:45 +0530 Subject: [PATCH 09/15] Update python-package.yml --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 85bc1e6..99faae8 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -28,7 +28,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + if ( -f requirements.txt ); then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 429f9b4c1e1e2c36f8441a08fe2cdbf565079aca Mon Sep 17 00:00:00 2001 From: Sam <92955870+the-sam963@users.noreply.github.com> Date: Tue, 28 Feb 2023 00:22:21 +0530 Subject: [PATCH 10/15] Update python-package.yml --- .github/workflows/python-package.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 99faae8..c3b6663 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -28,7 +28,6 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install flake8 pytest - if ( -f requirements.txt ); then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names From 195b1af43c7c3349db4bd9047054ece4e0e63f58 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 00:26:33 +0530 Subject: [PATCH 11/15] 000 --- filexdb/collection.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index be1d22e..7cd13bf 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -145,12 +145,7 @@ def find(self, query=None, limit=None) -> List[Document]: :param query: Condition to search Document :return: List of Document """ - if limit is not None and type(limit) == type((1,)): - raise TypeError('Limit should be a tuple') - if query is not None and type(query) == type({}): - raise TypeError('Limit should be a JOSN Object') - # Default result _result = [] From 44d33e3f00e73849eb679fc5e35ba1b792ddc308 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 00:35:17 +0530 Subject: [PATCH 12/15] fixed --- filexdb/collection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 60e1a3e..6e46836 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -153,6 +153,10 @@ def find(self, query=None, limit=None) -> List[Document]: if not isinstance(query, Mapping | None): raise ValueError('Document is not a Dictionary') + # Make sure the query implements the ``Mapping`` interface. + if not isinstance(limit, tuple | None): + raise ValueError('Document is not a Tuple') + # if limit, Check everything ok _limit_start = _limit_end = None @@ -371,7 +375,7 @@ def _find_document_by_query(self, query: Mapping) -> List: return result # ======================== # - def _doc_is_exists(self, doc_id: str | int) -> bool: + def _doc_is_exists(self, doc_id: str) -> bool: # Iterate over all Documents of Collection for doc in self._collection: if doc["_id_"] == doc_id: From d51ddc569dd570633b9d767f3f7de132db2c9e99 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 00:39:54 +0530 Subject: [PATCH 13/15] fixed type error for all version --- filexdb/collection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 6e46836..56370e3 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -383,9 +383,9 @@ def _doc_is_exists(self, doc_id: str) -> bool: return False - def _find_document_by_id(self, doc_id) -> Document | str: + def _find_document_by_id(self, doc_id) -> Document: for doc in self._collection: if doc["_id_"] == doc_id: return doc else: - return "none" + return None From 6dbde578e20536dbddd85e82aec647519144ea34 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 00:49:14 +0530 Subject: [PATCH 14/15] fixed --- filexdb/collection.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/filexdb/collection.py b/filexdb/collection.py index 56370e3..2a5225b 100644 --- a/filexdb/collection.py +++ b/filexdb/collection.py @@ -145,17 +145,19 @@ def find(self, query=None, limit=None) -> List[Document]: :param query: Condition to search Document :return: List of Document """ - + # Default result _result = [] # Make sure the query implements the ``Mapping`` interface. - if not isinstance(query, Mapping | None): - raise ValueError('Document is not a Dictionary') + if query: + if not isinstance(query, Mapping): + raise ValueError('Document is not a Dictionary') - # Make sure the query implements the ``Mapping`` interface. - if not isinstance(limit, tuple | None): - raise ValueError('Document is not a Tuple') + # Make sure the query implements the ``Tuple`` interface. + if limit: + if not isinstance(limit, tuple): + raise ValueError('Document is not a Tuple') # if limit, Check everything ok _limit_start = _limit_end = None @@ -223,11 +225,9 @@ def find(self, query=None, limit=None) -> List[Document]: self._reset_cursor() - - return _result - def delete(self, query: Mapping = None) -> List[str]: + def delete(self, query=None) -> List[str]: """ Delete single or multiple Document when meet the Conditions or ``query``. @@ -252,7 +252,7 @@ def delete(self, query: Mapping = None) -> List[str]: return _doc_id - def update(self, document: Mapping, query: Mapping = None) -> List[str]: + def update(self, document: Mapping, query=None) -> List[str]: """ Fetch all the Documents mathc the conditions and update them. @@ -288,7 +288,7 @@ def update(self, document: Mapping, query: Mapping = None) -> List[str]: return _doc_id - def count(self, query: Mapping = None, limit: tuple = None) -> int: + def count(self, query=None, limit: tuple = None) -> int: """ Return amount of Document found. @@ -319,7 +319,7 @@ def _find_document_by_query(self, query: Mapping) -> List: result = [] # Make sure the query implements the ``Mapping`` interface. - if not isinstance(query, Mapping | None): + if not isinstance(query, Mapping): raise ValueError('Document is not a Dictionary') # Get the length on Collection @@ -351,7 +351,6 @@ def _find_document_by_query(self, query: Mapping) -> List: # If both values are same, then update ``_bag_of_query[i]`` as 1. _bag_of_query[i] = 1 - else: continue else: From 2fd4ae5e1718e150e67ae4f098341cb564bf8e57 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 28 Feb 2023 01:01:25 +0530 Subject: [PATCH 15/15] fixed type --- filexdb/document.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/filexdb/document.py b/filexdb/document.py index 5aece1b..435d5e3 100644 --- a/filexdb/document.py +++ b/filexdb/document.py @@ -20,7 +20,9 @@ def __init__(self, value: Mapping) -> None: self._doc = value self.id = value["_id_"] else: - self._doc = (_id_obj | value) + self._doc = _id_obj + for k, v in value.items(): + self._doc[k] = v self.id = self._doc["_id_"] super().__init__(self._doc)