Loglan-Core 0.4.4__tar.gz → 0.4.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {loglan_core-0.4.4 → loglan_core-0.4.6/Loglan_Core.egg-info}/PKG-INFO +3 -3
  2. {loglan_core-0.4.4/Loglan_Core.egg-info → loglan_core-0.4.6}/PKG-INFO +3 -3
  3. {loglan_core-0.4.4 → loglan_core-0.4.6}/README.md +1 -1
  4. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/base_selector.py +61 -33
  5. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/word_selector.py +1 -1
  6. {loglan_core-0.4.4 → loglan_core-0.4.6}/setup.py +1 -1
  7. {loglan_core-0.4.4 → loglan_core-0.4.6}/LICENSE +0 -0
  8. {loglan_core-0.4.4 → loglan_core-0.4.6}/Loglan_Core.egg-info/SOURCES.txt +0 -0
  9. {loglan_core-0.4.4 → loglan_core-0.4.6}/Loglan_Core.egg-info/dependency_links.txt +0 -0
  10. {loglan_core-0.4.4 → loglan_core-0.4.6}/Loglan_Core.egg-info/requires.txt +0 -0
  11. {loglan_core-0.4.4 → loglan_core-0.4.6}/Loglan_Core.egg-info/top_level.txt +0 -0
  12. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/__init__.py +0 -0
  13. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/__init__.py +0 -0
  14. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/definition_selector.py +0 -0
  15. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/export_word_converter.py +0 -0
  16. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/exporter.py +0 -0
  17. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/key_selector.py +0 -0
  18. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/utils.py +0 -0
  19. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/word_linker.py +0 -0
  20. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/addons/word_sourcer.py +0 -0
  21. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/author.py +0 -0
  22. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/base.py +0 -0
  23. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/connect_tables.py +0 -0
  24. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/definition.py +0 -0
  25. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/event.py +0 -0
  26. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/key.py +0 -0
  27. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/setting.py +0 -0
  28. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/syllable.py +0 -0
  29. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/table_names.py +0 -0
  30. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/type.py +0 -0
  31. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/word.py +0 -0
  32. {loglan_core-0.4.4 → loglan_core-0.4.6}/loglan_core/word_spell.py +0 -0
  33. {loglan_core-0.4.4 → loglan_core-0.4.6}/pyproject.toml +0 -0
  34. {loglan_core-0.4.4 → loglan_core-0.4.6}/setup.cfg +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Loglan-Core
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: Loglan Dictionary Database Model for SQLAlchemy
5
5
  Home-page: https://github.com/torrua/loglan_core
6
- Download-URL: https://github.com/torrua/loglan_core/archive/0.4.4.tar.gz
6
+ Download-URL: https://github.com/torrua/loglan_core/archive/0.4.6.tar.gz
7
7
  Author: torrua
8
8
  Author-email: torrua@gmail.com
9
9
  License: MIT
@@ -26,7 +26,7 @@ Requires-Dist: sqlalchemy>=2.0.21
26
26
  ![Codecov](https://img.shields.io/codecov/c/github/torrua/loglan_core?logo=Codecov&logoColor=%23F01F7A&label=codecov)
27
27
  ![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/torrua/loglan_core/main?logo=Scrutinizer%20CI&logoColor=%238A9296&label=Scrutinizer%20CC&link=https%3A%2F%2Fscrutinizer-ci.com%2Fg%2Ftorrua%2Floglan_core%2F%3Fbranch%3Dmain)
28
28
  ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/torrua/loglan_core?logo=Code%20Climate)
29
- ![pylint](https://img.shields.io/badge/PyLint-10.00-brightgreen?logo=python&logoColor=white)
29
+ ![pylint](https://img.shields.io/badge/PyLint-9.95-yellow?logo=python&logoColor=white)
30
30
  [![Pytest](https://github.com/torrua/loglan_core/actions/workflows/pytest.yml/badge.svg)](https://github.com/torrua/loglan_core/actions/workflows/pytest.yml)
31
31
  ![Bandit Status](https://img.shields.io/github/actions/workflow/status/torrua/loglan_core/bandit.yml?label=bandit)
32
32
  ![Black Status](https://img.shields.io/github/actions/workflow/status/torrua/loglan_core/black.yml?label=Black&labelColor=black)
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: Loglan-Core
3
- Version: 0.4.4
3
+ Version: 0.4.6
4
4
  Summary: Loglan Dictionary Database Model for SQLAlchemy
5
5
  Home-page: https://github.com/torrua/loglan_core
6
- Download-URL: https://github.com/torrua/loglan_core/archive/0.4.4.tar.gz
6
+ Download-URL: https://github.com/torrua/loglan_core/archive/0.4.6.tar.gz
7
7
  Author: torrua
8
8
  Author-email: torrua@gmail.com
9
9
  License: MIT
@@ -26,7 +26,7 @@ Requires-Dist: sqlalchemy>=2.0.21
26
26
  ![Codecov](https://img.shields.io/codecov/c/github/torrua/loglan_core?logo=Codecov&logoColor=%23F01F7A&label=codecov)
27
27
  ![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/torrua/loglan_core/main?logo=Scrutinizer%20CI&logoColor=%238A9296&label=Scrutinizer%20CC&link=https%3A%2F%2Fscrutinizer-ci.com%2Fg%2Ftorrua%2Floglan_core%2F%3Fbranch%3Dmain)
28
28
  ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/torrua/loglan_core?logo=Code%20Climate)
29
- ![pylint](https://img.shields.io/badge/PyLint-10.00-brightgreen?logo=python&logoColor=white)
29
+ ![pylint](https://img.shields.io/badge/PyLint-9.95-yellow?logo=python&logoColor=white)
30
30
  [![Pytest](https://github.com/torrua/loglan_core/actions/workflows/pytest.yml/badge.svg)](https://github.com/torrua/loglan_core/actions/workflows/pytest.yml)
31
31
  ![Bandit Status](https://img.shields.io/github/actions/workflow/status/torrua/loglan_core/bandit.yml?label=bandit)
32
32
  ![Black Status](https://img.shields.io/github/actions/workflow/status/torrua/loglan_core/black.yml?label=Black&labelColor=black)
@@ -3,7 +3,7 @@
3
3
  ![Codecov](https://img.shields.io/codecov/c/github/torrua/loglan_core?logo=Codecov&logoColor=%23F01F7A&label=codecov)
4
4
  ![Scrutinizer code quality (GitHub/Bitbucket)](https://img.shields.io/scrutinizer/quality/g/torrua/loglan_core/main?logo=Scrutinizer%20CI&logoColor=%238A9296&label=Scrutinizer%20CC&link=https%3A%2F%2Fscrutinizer-ci.com%2Fg%2Ftorrua%2Floglan_core%2F%3Fbranch%3Dmain)
5
5
  ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability-percentage/torrua/loglan_core?logo=Code%20Climate)
6
- ![pylint](https://img.shields.io/badge/PyLint-10.00-brightgreen?logo=python&logoColor=white)
6
+ ![pylint](https://img.shields.io/badge/PyLint-9.95-yellow?logo=python&logoColor=white)
7
7
  [![Pytest](https://github.com/torrua/loglan_core/actions/workflows/pytest.yml/badge.svg)](https://github.com/torrua/loglan_core/actions/workflows/pytest.yml)
8
8
  ![Bandit Status](https://img.shields.io/github/actions/workflow/status/torrua/loglan_core/bandit.yml?label=bandit)
9
9
  ![Black Status](https://img.shields.io/github/actions/workflow/status/torrua/loglan_core/black.yml?label=Black&labelColor=black)
@@ -8,6 +8,7 @@ from typing import Type, Iterable, Any
8
8
 
9
9
  from sqlalchemy import select, Select
10
10
  from sqlalchemy.orm import Session, InstrumentedAttribute, joinedload
11
+ from sqlalchemy.types import String, Integer
11
12
  from typing_extensions import Self
12
13
 
13
14
  from loglan_core.base import BaseModel
@@ -62,8 +63,7 @@ class BaseSelector: # pylint: disable=too-many-ancestors
62
63
  self.case_sensitive = case_sensitive
63
64
 
64
65
  def execute(self, session: Session):
65
- """
66
- Executes the given session and returns the result.
66
+ """Executes the given session and returns the result.
67
67
 
68
68
  Args:
69
69
  session (Session): SQLAlchemy Session object.
@@ -74,8 +74,7 @@ class BaseSelector: # pylint: disable=too-many-ancestors
74
74
  return session.execute(self._statement)
75
75
 
76
76
  def all(self, session: Session):
77
- """
78
- Executes the given session and returns all the results as a list.
77
+ """Executes the given session and returns all the results as a list.
79
78
 
80
79
  Args:
81
80
  session (Session): SQLAlchemy Session object.
@@ -86,8 +85,7 @@ class BaseSelector: # pylint: disable=too-many-ancestors
86
85
  return session.execute(self._statement).scalars().all()
87
86
 
88
87
  def scalar(self, session: Session):
89
- """
90
- Executes the given session and returns a scalar result.
88
+ """Executes the given session and returns a scalar result.
91
89
 
92
90
  Args:
93
91
  session (Session): SQLAlchemy Session object.
@@ -98,8 +96,7 @@ class BaseSelector: # pylint: disable=too-many-ancestors
98
96
  return session.execute(self._statement).scalar()
99
97
 
100
98
  def fetchmany(self, session: Session, size: int | None = None):
101
- """
102
- Executes the given session and fetches a specified number of results.
99
+ """Executes the given session and fetches a specified number of results.
103
100
 
104
101
  Args:
105
102
  session (Session): SQLAlchemy Session object.
@@ -217,20 +214,37 @@ class BaseSelector: # pylint: disable=too-many-ancestors
217
214
  Self: The current instance for method chaining.
218
215
  """
219
216
  for key, value in kwargs.items():
220
- self._statement = self._statement.where(
221
- self._generate_column_condition(key, value)
222
- )
217
+ self._statement = self._statement.where(self.get_like_condition(key, value))
223
218
  return self
224
219
 
225
- def _generate_column_condition(self, key: str | InstrumentedAttribute, value: Any):
226
- column = getattr(self.model, key, None) if isinstance(key, str) else key
227
- if column is None:
228
- raise AttributeError(f"Model {self.model} has no attribute {key}")
220
+ def get_like_condition(self, key: str | InstrumentedAttribute, value: Any):
221
+ """Generate the condition based on settings provided by Selector instance
222
+ like (is_sqlite, case_sensitive).
223
+
224
+ Args:
225
+ key (str | InstrumentedAttribute): The key of the column to filter by.
226
+ value (Any): The value to filter by.
227
+
228
+ Returns:
229
+ Condition: The SQLAlchemy condition to filter by.
230
+ """
231
+ column = self._get_column(key)
229
232
 
230
- value = str(value).replace("*", "%")
231
- if self.case_sensitive:
232
- return column.op("GLOB")(value) if self.is_sqlite else column.like(value)
233
- return column.ilike(value)
233
+ if not isinstance(column.type, (String, Integer)):
234
+ return column == value
235
+
236
+ if isinstance(column.type, Integer):
237
+ return column == int(value)
238
+
239
+ value = value.replace("*", "%")
240
+
241
+ if not self.case_sensitive:
242
+ return column.ilike(value)
243
+
244
+ if self.is_sqlite:
245
+ return column.op("GLOB")(value)
246
+
247
+ return column.like(value)
234
248
 
235
249
  def get_statement(self) -> Select:
236
250
  """Get the current SQLAlchemy _statement.
@@ -251,21 +265,8 @@ class BaseSelector: # pylint: disable=too-many-ancestors
251
265
  """
252
266
  return self.all(session)
253
267
 
254
- @staticmethod
255
- def _is_model_accepted(model, parent: type[BaseModel] = BaseModel):
256
- """
257
- Checks if the model is an instance of BaseModel or its child.
258
- Raises:
259
- ValueError: If the model is not an instance of BaseModel or its child.
260
- """
261
- if not issubclass(model, parent):
262
- raise ValueError(
263
- f"Provided class_={model} is not a inherited from {parent}"
264
- )
265
-
266
268
  def with_relationships(self, selected: Iterable[str] | None = None) -> Self:
267
- """
268
- Adds relationships to the query.
269
+ """Adds relationships to the query.
269
270
 
270
271
  Args:
271
272
  selected (set[str]): A set of relationship names to include.
@@ -284,3 +285,30 @@ class BaseSelector: # pylint: disable=too-many-ancestors
284
285
  }
285
286
  self._statement = self._statement.options(*relationships)
286
287
  return self
288
+
289
+ @staticmethod
290
+ def _is_model_accepted(model, parent: type[BaseModel] = BaseModel):
291
+ """Checks if the model is an instance of BaseModel or its child.
292
+
293
+ Raises:
294
+ ValueError: If the model is not an instance of BaseModel or its child.
295
+ """
296
+ if not issubclass(model, parent):
297
+ raise ValueError(f"Provided model={model} is not a inherited from {parent}")
298
+
299
+ def _get_column(self, key: str | InstrumentedAttribute) -> InstrumentedAttribute:
300
+ """Get the column from the model.
301
+
302
+ Args:
303
+ key (str | InstrumentedAttribute): The key of the column to filter by.
304
+
305
+ Raises:
306
+ AttributeError: If the model has no attribute with the given key.
307
+
308
+ Returns:
309
+ InstrumentedAttribute: The SQLAlchemy column to filter by.
310
+ """
311
+ column = getattr(self.model, key, None) if isinstance(key, str) else key
312
+ if column is None:
313
+ raise AttributeError(f"Model {self.model} has no attribute {key}")
314
+ return column
@@ -87,7 +87,7 @@ class WordSelector(BaseSelector): # pylint: disable=too-many-ancestors
87
87
  Self: A query with the filter applied.
88
88
  """
89
89
  if hasattr(self.model, "name"):
90
- condition = self._generate_column_condition(self.model.name, name)
90
+ condition = self.get_like_condition(self.model.name, name)
91
91
  else:
92
92
  raise AttributeError(
93
93
  f"{self.model.__name__} does not have a 'name' attribute"
@@ -4,7 +4,7 @@ from io import open
4
4
 
5
5
  from setuptools import setup
6
6
 
7
- CURRENT_VERSION = "0.4.4"
7
+ CURRENT_VERSION = "0.4.6"
8
8
 
9
9
 
10
10
  def read(filename): # pylint: disable=C0116
File without changes
File without changes
File without changes