Skip to content

Commit

Permalink
Ddb/add autogenerated models (#23)
Browse files Browse the repository at this point in the history
* add autogenerated models

* add many-to-many

* added init_bo4e to tox

* ➕added basic functions, 🧹clean up

* added tests

* changed tests for fixture and adapted foreign keys, ➕ many-to-many test

* added tests for zusatz_attribut

* fixed dependencies

* Updated readme
  • Loading branch information
DeltaDaniel authored Apr 30, 2024
1 parent d634a52 commit fb32617
Show file tree
Hide file tree
Showing 30 changed files with 569 additions and 102 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# This GitHub workflow is only needed for python package releases which are supposed to be published on pypi.
#This GitHub workflow is only needed for python package releases which are supposed to be published on pypi.
#DOES NOT PUBLISH YET

#This workflows will upload a Python Package using Twine when a release is created
#For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package

# name: Upload Python Package
on:
release:
types: [created, edited]

# on:
# release:
# types: [created, edited]

# jobs:
# tests:
# if: startsWith(github.ref, 'refs/tags/v')
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# python-version: ["3.11"]
# os: [ubuntu-latest]
# steps:
# - uses: actions/checkout@v2
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
# - name: Install tox
# run: |
# python -m pip install --upgrade pip
# pip install tox
# - name: Run tox
# run: |
# tox
jobs:
tests:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.11"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tox
run: |
tox
# build-n-publish:
# name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ dmypy.json
.vscode/

src/_your_package_version.py

src/borm/models/**

bo4e_schemas/output/**
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 24.1.1
hooks:
- id: black
language_version: python3
Expand Down
11 changes: 11 additions & 0 deletions .pylintrc_autogen_code
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[pylint]
#run for the code generated files
#know things to be fixed:
disable =
R0801, # disable similar lines
C0114, # disable missing-module-docstring
C0115, # disable missing-class-docstring
W0611, # disable unused-import
C0301, # disable line-too-long ->lines in comments too long
C0302, # disable too-many-lines -> many-many relationship classes
[pylint."MESSAGES CONTROL"]
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
![Black status badge](https://github.com/Hochfrequenz/bo4e-python-orm/workflows/Formatting/badge.svg)

A ORM tool to map between SQL databases and BO4E classes using:
...
- SQLModel (https://sqlmodel.tiangolo.com) for the ORM
- BO4E-Schema-Tool (https://pypi.org/project/BO4E-Schema-Tool) to pull and modify an existing BO4E version
- BO4E-Python-Generator (https://pypi.org/project/BO4E-Python-Generator) to generate SQLModel classes from the BO4E schema
- Docker Container (https://www.docker.com) to create the database with
- PostgreSQL (https://www.postgresql.org)
(- In principle, Alembic (https://alembic.sqlalchemy.org) is supported for migrations, but not further supported at the moment)

The idea of this tool is to provide a first instance of an ORM which has been generated from a specific BO4E version. For further information of the functionalities of this ORM framework, please refer to the documentation of [SQLModel](https://sqlmodel.tiangolo.com).
Please note that this is a very early version of the ORM and might not be fully functional yet.

### Installation

Expand All @@ -16,27 +24,43 @@ It will also be [available on pypi](https://pypi.org/project/borm/).
pip install borm
```

### Documentation
### Description

To setup a test db (postgresql) run the following in your tox env (see below):
```bash
tox -e setup_testpostgresql
```
Make sure that your local host is running.

Second, the alembic migration is done running:
Alternatively, an existing bo4e version can be pulled via:
```bash
tox -e migration
tox -e init_bo4e
```
This uses two other tools:
https://github.com/bo4e/BO4E-Schema-Tool
and
https://github.com/bo4e/BO4E-Python-Generator

Make sure you specify the version in tox.ini via the -t flag.

The fast way is to use:
```bash
tox -e setup_bo4e
```
which combines the steps above.

Enter the following to delete the test db:
```bash
tox -e remove_testpostgresql
```
In order to get a better understanding how this ORM works, you might want to have a look at the tests in the tests folder.

In principle, alembic migrations are supported, e.g. by running:
```bash
tox -e migration
```
However, this is not further supported at the moment.

## How to use this Repository on Your Machine

Follow the instructions in our [Python template repository](https://github.com/Hochfrequenz/python_template_repository#how-to-use-this-repository-on-your-machine).

## Contribute

Expand Down
10 changes: 6 additions & 4 deletions dev_requirements/requirements-formatting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
#
black==24.4.2
# via -r dev_requirements/requirements-formatting.in
click==8.1.3
click==8.1.7
# via black
colorama==0.4.6
# via click
isort==5.13.2
# via -r dev_requirements/requirements-formatting.in
mypy-extensions==1.0.0
# via black
packaging==23.0
packaging==23.2
# via black
pathspec==0.11.0
pathspec==0.12.1
# via black
platformdirs==3.1.0
platformdirs==4.2.0
# via black
2 changes: 2 additions & 0 deletions dev_requirements/requirements-init_bo4e.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BO4E-Schema-Tool
BO4E-Python-Generator == 0.0.9
98 changes: 98 additions & 0 deletions dev_requirements/requirements-init_bo4e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile dev_requirements/requirements-init_bo4e.in
#
annotated-types==0.6.0
# via pydantic
argcomplete==3.2.2
# via datamodel-code-generator
black==24.4.2
# via datamodel-code-generator
bo4e-python-generator==0.0.9
# via -r dev_requirements/requirements-init_bo4e.in
bo4e-schema-tool==0.0.5
# via -r dev_requirements/requirements-init_bo4e.in
certifi==2024.2.2
# via requests
cffi==1.16.0
# via
# cryptography
# pynacl
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via
# black
# bo4e-python-generator
# bo4e-schema-tool
colorama==0.4.6
# via click
cryptography==42.0.5
# via pyjwt
datamodel-code-generator==0.25.3
# via bo4e-python-generator
deprecated==1.2.14
# via pygithub
dnspython==2.5.0
# via email-validator
email-validator==2.1.0.post1
# via pydantic
genson==1.2.2
# via datamodel-code-generator
idna==3.6
# via
# email-validator
# requests
inflect==5.6.2
# via datamodel-code-generator
isort==5.13.2
# via datamodel-code-generator
jinja2==3.1.3
# via datamodel-code-generator
markupsafe==2.1.5
# via jinja2
more-itertools==10.2.0
# via bo4e-schema-tool
mypy-extensions==1.0.0
# via black
packaging==23.2
# via
# black
# datamodel-code-generator
pathspec==0.12.1
# via black
platformdirs==4.2.0
# via black
pycparser==2.21
# via cffi
pydantic[email]==2.7.1
# via
# bo4e-schema-tool
# datamodel-code-generator
pydantic-core==2.18.2
# via pydantic
pygithub==2.2.0
# via bo4e-schema-tool
pyjwt[crypto]==2.8.0
# via pygithub
pynacl==1.5.0
# via pygithub
pyyaml==6.0.1
# via datamodel-code-generator
requests==2.31.0
# via
# bo4e-schema-tool
# pygithub
typing-extensions==4.9.0
# via
# pydantic
# pydantic-core
# pygithub
urllib3==2.2.0
# via
# pygithub
# requests
wrapt==1.16.0
# via deprecated
4 changes: 3 additions & 1 deletion dev_requirements/requirements-linting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#
astroid==3.1.0
# via pylint
colorama==0.4.6
# via pylint
dill==0.3.7
# via pylint
isort==5.13.2
# via pylint
mccabe==0.7.0
# via pylint
platformdirs==3.1.0
platformdirs==4.2.0
# via pylint
pylint==3.1.0
# via -r dev_requirements/requirements-linting.in
Expand Down
16 changes: 4 additions & 12 deletions dev_requirements/requirements-packaging.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ build==1.2.1
# via -r dev_requirements/requirements-packaging.in
certifi==2024.2.2
# via requests
cffi==1.16.0
# via cryptography
charset-normalizer==3.3.2
# via requests
cryptography==42.0.5
# via secretstorage
colorama==0.4.6
# via build
docutils==0.20.1
# via readme-renderer
idna==3.6
Expand All @@ -22,10 +20,6 @@ importlib-metadata==7.0.2
# via twine
jaraco-classes==3.3.1
# via keyring
jeepney==0.8.0
# via
# keyring
# secretstorage
keyring==24.3.1
# via twine
markdown-it-py==3.0.0
Expand All @@ -40,14 +34,14 @@ packaging==24.0
# via build
pkginfo==1.10.0
# via twine
pycparser==2.21
# via cffi
pygments==2.17.2
# via
# readme-renderer
# rich
pyproject-hooks==1.0.0
# via build
pywin32-ctypes==0.2.2
# via keyring
readme-renderer==43.0
# via twine
requests==2.31.0
Expand All @@ -60,8 +54,6 @@ rfc3986==2.0.0
# via twine
rich==13.7.1
# via twine
secretstorage==3.3.3
# via keyring
twine==5.0.0
# via -r dev_requirements/requirements-packaging.in
urllib3==2.2.1
Expand Down
4 changes: 3 additions & 1 deletion dev_requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#
# pip-compile dev_requirements/requirements-tests.in
#
colorama==0.4.6
# via pytest
iniconfig==2.0.0
# via pytest
packaging==23.0
packaging==23.2
# via pytest
pluggy==1.5.0
# via pytest
Expand Down
2 changes: 1 addition & 1 deletion dev_requirements/requirements-type_check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ mypy==1.10.0
# via -r dev_requirements/requirements-type_check.in
mypy-extensions==1.0.0
# via mypy
typing-extensions==4.8.0
typing-extensions==4.9.0
# via mypy
Loading

0 comments on commit fb32617

Please sign in to comment.