Skip to content
Merged

Dev #36

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
df495e1
Refactor code
jedymatt Dec 31, 2021
d5f1e7d
Removed KeyValue class
jedymatt Jan 5, 2022
cad2664
Added attribute wrapper class
jedymatt Jan 6, 2022
93d5052
Added dev-rewrite branch in python-package.yml
jedymatt Jan 6, 2022
30ce26e
Changed module docstring
jedymatt Jan 6, 2022
0b1012c
Minor change
jedymatt Jan 6, 2022
7aefcde
Added json module, Update Seeder class to use JsonWalker.
jedymatt Jan 7, 2022
42a26b4
Fix errors lower than python 3.10 versions
jedymatt Jan 7, 2022
c921854
Fix for python 3.7 below versions
jedymatt Jan 7, 2022
4621540
Fix in python 3.6
jedymatt Jan 7, 2022
f21de96
Fix in python 3.6
jedymatt Jan 7, 2022
26d7abf
Fix in python 3.6
jedymatt Jan 7, 2022
7b3447d
Fix previous
jedymatt Jan 7, 2022
6546310
Fix previous
jedymatt Jan 7, 2022
c3b67ce
Minor change to fix depreciated properties in setup.cfg file
jedymatt Jan 7, 2022
298e760
Update tests
jedymatt Jan 8, 2022
7d29e6a
Added relationship classes
jedymatt Jan 8, 2022
e4ce6ee
Added relationships module in tests
jedymatt Jan 8, 2022
dbaf782
Create codeql-analysis.yml
jedymatt Jan 8, 2022
351bfc9
Merge pull request #22 from jedymatt/jedymatt-patch-1
jedymatt Jan 8, 2022
e62c36c
Update codeql-analysis.yml
jedymatt Jan 8, 2022
a1020ec
Delete codeql-analysis.yml
jedymatt Jan 8, 2022
a1877d5
Added many to one relationship test
jedymatt Jan 11, 2022
9a0c87b
Merge branch 'dev-rewrite' of https://github.com/jedymatt/sqlalchemys…
jedymatt Jan 11, 2022
460692c
Added test cases
jedymatt Jan 12, 2022
e3694c3
Changed attribute name
jedymatt Jan 12, 2022
2912283
Added test association object
jedymatt Jan 12, 2022
b3eaf7d
Sort imports
jedymatt Jan 12, 2022
9fe29a6
Fix typo
jedymatt Jan 12, 2022
347b6bf
Added constant variable
jedymatt Jan 12, 2022
f5c2fb0
Fix key type
jedymatt Jan 12, 2022
524db62
Removed Entity class and uses helper functions for attributes
jedymatt Jan 12, 2022
639f403
Removed key_value.py
jedymatt Jan 12, 2022
d82ebb3
Removed unnecessary pass keyword
jedymatt Jan 12, 2022
a4a6a79
Sort imports
jedymatt Jan 12, 2022
cc51a00
Update docs, seeder, json and other modules
jedymatt Jan 14, 2022
cb2097e
Revert "Create codeql-analysis.yml"
jedymatt Jan 17, 2022
f662acf
Merge pull request #23 from jedymatt/revert-22-jedymatt-patch-1
jedymatt Jan 17, 2022
95c1c78
Added docker environment config
jedymatt Jan 17, 2022
3bb5572
Added all in options.extras_require
jedymatt Jan 17, 2022
5c20d48
Removed `all` and added docs package in `dev` instead
jedymatt Jan 17, 2022
382e5ed
Added node
jedymatt Jan 17, 2022
39b0f31
Added docs/requirements.txt
jedymatt Jan 17, 2022
b7bc04c
Update rtd config
jedymatt Jan 17, 2022
606335d
Merge pull request #25 from jedymatt/create-requirements-file
jedymatt Jan 17, 2022
c507f3c
Update .devcontainer/* configs
jedymatt Jan 18, 2022
f085144
Removed unnecessary code
jedymatt Jan 18, 2022
455ae9b
Update devcontainer config
jedymatt Jan 18, 2022
5bffb1b
Update readme, requirements, and setup
jedymatt Jan 18, 2022
be21ec7
Removed [dev]
jedymatt Jan 18, 2022
833e780
Add user flag
jedymatt Jan 18, 2022
15ff5fb
Update readme
jedymatt Jan 18, 2022
9d7e4cc
Small changes
jedymatt Jan 18, 2022
d4540ba
Create .gitattributes
jedymatt Jan 19, 2022
02bb21d
Changed to && from ;
jedymatt Jan 19, 2022
3049cf0
Update import
jedymatt Feb 1, 2022
a5f74b1
Removed ClassRegister attribute in Seeder class
jedymatt Feb 1, 2022
8684d7a
Update devcontainer
jedymatt Feb 1, 2022
2ab700c
Using lru_cache for caching parsed classes
jedymatt Feb 1, 2022
80e6812
Merge pull request #28 from jedymatt/update-seeder
jedymatt Feb 1, 2022
becc1e3
Merge branch 'main' of https://github.com/jedymatt/sqlalchemyseed int…
jedymatt May 27, 2022
40d6941
Merge remote-tracking branch 'origin' into dev
jedymatt May 27, 2022
55466ae
Fix errors
jedymatt May 27, 2022
b4f5fb3
Merge branch 'main' into dev
jedymatt May 27, 2022
8f09b95
Merge remote-tracking branch 'origin' into dev
jedymatt May 27, 2022
14df842
Added snippet for running tests with coverage
jedymatt May 27, 2022
504177e
Update keys
jedymatt May 27, 2022
5922810
Removed JsonKey dataclass
jedymatt May 27, 2022
92e9e3d
Added tox.ini
jedymatt May 27, 2022
8cb70ac
Removed unused import
jedymatt May 27, 2022
2d36dd5
Added tox
jedymatt May 27, 2022
2c037d8
Comment out dataclasses in requirements.txt
jedymatt May 27, 2022
8a9cffd
Merge remote-tracking branch 'origin' into dev
jedymatt May 27, 2022
f32cff8
Delete Dockerfile
jedymatt May 27, 2022
6a341b8
Delete devcontainer.json
jedymatt May 27, 2022
0be36ea
Update python-package.yml
jedymatt May 27, 2022
cebfcac
Change to plural
jedymatt May 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python -m pip install flake8 pytest
pip install -r requirements.txt
# install local
pip install -e .[dev]
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,9 @@ Then run the test:
```shell
pytest tests
```

Run test with coverage

```shell
coverage run -m pytest
```
Empty file added docs/source/_static/.gitkeep
Empty file.
30 changes: 14 additions & 16 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ API Reference
Seeders
-------

.. autoclass:: sqlalchemyseed.Seeder
:members:
:undoc-members:

.. autoclass:: sqlalchemyseed.HybridSeeder
.. automodule:: sqlalchemyseed.seeder
:members:
:undoc-members:

Loaders
-------

.. autofunction:: sqlalchemyseed.load_entities_from_json

.. autofunction:: sqlalchemyseed.load_entities_from_yaml

.. autofunction:: sqlalchemyseed.load_entities_from_csv

.. automodule:: sqlalchemyseed.loader
:members:

Validators
----------

.. autofunction:: sqlalchemyseed.validator.validate

.. autofunction:: sqlalchemyseed.validator.hybrid_validate

.. automodule:: sqlalchemyseed.validator
:members:
:undoc-members:

Exceptions
----------

.. automodule:: sqlalchemyseed.errors
:members:
:members:

Utilities
---------

.. automodule:: sqlalchemyseed.util
:members:
:undoc-members:
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SQLAlchemy>=1.4
dataclasses>=0.8; python_version == "3.6"
# dataclasses>=0.8; python_version == "3.6"
PyYAML>=5.4
coverage>=6.2
tox
pytest
pylint
autopep8
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ package_dir =
=src
install_requires =
SQLAlchemy>=1.4
dataclasses>=0.8; python_version == "3.6"
; dataclasses>=0.8; python_version == "3.6"
python_requires = >=3.6

[options.packages.find]
Expand All @@ -38,4 +38,4 @@ where = src
[options.extras_require]
yaml =
PyYAML>=5.4


8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup


setup()
from setuptools import setup
setup()
2 changes: 2 additions & 0 deletions src/sqlalchemyseed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from .loader import load_entities_from_json
from .loader import load_entities_from_yaml
from .loader import load_entities_from_csv
from . import util
from . import attribute


__version__ = "1.0.6-dev"
Expand Down
70 changes: 70 additions & 0 deletions src/sqlalchemyseed/attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
attribute module containing helper functions for instrumented attribute.
"""

from functools import lru_cache
from inspect import isclass

from sqlalchemy.orm import ColumnProperty, RelationshipProperty
from sqlalchemy.orm.attributes import InstrumentedAttribute, get_attribute, set_attribute


def instrumented_attribute(class_or_instance, key: str):
"""
Returns instrumented attribute from the class or instance.
"""

if isclass(class_or_instance):
return getattr(class_or_instance, key)

return getattr(class_or_instance.__class__, key)


def attr_is_relationship(instrumented_attr: InstrumentedAttribute):
"""
Check if instrumented attribute property is a RelationshipProperty
"""
return isinstance(instrumented_attr.property, RelationshipProperty)


def attr_is_column(instrumented_attr: InstrumentedAttribute):
"""
Check if instrumented attribute property is a ColumnProperty
"""
return isinstance(instrumented_attr.property, ColumnProperty)


def set_instance_attribute(instance, key, value):
"""
Set attribute value of instance
"""

instr_attr: InstrumentedAttribute = getattr(instance.__class__, key)

if attr_is_relationship(instr_attr) and instr_attr.property.uselist:
get_attribute(instance, key).append(value)
else:
set_attribute(instance, key, value)

@lru_cache()
def foreign_key_column(instrumented_attr: InstrumentedAttribute):
"""
Returns the table name of the first foreignkey.
"""
return next(iter(instrumented_attr.foreign_keys)).column

@lru_cache()
def referenced_class(instrumented_attr: InstrumentedAttribute):
"""
Returns class that the attribute is referenced to.
"""

if attr_is_relationship(instrumented_attr):
return instrumented_attr.mapper.class_

table_name = foreign_key_column(instrumented_attr).table.name

return next(filter(
lambda mapper: mapper.class_.__tablename__ == table_name,
instrumented_attr.parent.registry.mappers
)).class_
4 changes: 4 additions & 0 deletions src/sqlalchemyseed/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODEL_KEY = 'model'
DATA_KEY = 'data'
FILTER_KEY = 'filter'
SOURCE_KEYS = [DATA_KEY, FILTER_KEY]
4 changes: 4 additions & 0 deletions src/sqlalchemyseed/dynamic_seeder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class DynamicSeeder:
"""
DynamicSeeder class
"""
15 changes: 0 additions & 15 deletions src/sqlalchemyseed/errors.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
class ClassNotFoundError(Exception):
"""Raised when the class is not found"""
pass


class MissingKeyError(Exception):
"""Raised when a required key is missing"""
pass


class MaxLengthExceededError(Exception):
"""Raised when maximum length of data exceeded"""
pass


class InvalidTypeError(Exception):
"""Raised when a type of data is not accepted"""
pass


class EmptyDataError(Exception):
"""Raised when data is empty"""
pass


class InvalidKeyError(Exception):
"""Raised when an invalid key is invoked"""
pass


class ParseError(Exception):
"""Raised when parsing string fails"""
pass


class UnsupportedClassError(Exception):
"""Raised when an unsupported class is invoked"""
pass


class NotInModuleError(Exception):
"""Raised when a value is not found in module"""
pass


class InvalidModelPath(Exception):
"""Raised when an invalid model path is invoked"""
pass


class UnsupportedClassError(Exception):
"""Raised when an unsupported class is invoked"""
pass
Loading