Skip to content

Commit 6a19001

Browse files
committed
Added first attempt entity class
1 parent da1ecb7 commit 6a19001

18 files changed

+349
-136
lines changed

.bandit

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bandit]
2+
exclude: /tests

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
ignore = E501,E722,E203,W503,E402
3+
max-line-length = 88
4+
exclude = tests/*

.pre-commit-config.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 19.10b0
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v2.4.0
8+
hooks:
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace
11+
- id: check-ast
12+
- id: check-json
13+
- id: check-merge-conflict
14+
- id: detect-private-key
15+
- id: flake8
16+
- id: pretty-format-json
17+
args: [--autofix]
18+
- repo: https://github.com/PyCQA/pydocstyle
19+
rev: 5.0.2
20+
hooks:
21+
- id: pydocstyle
22+
args: [--match, "(?!(tests/test_|docs/)).*\\.py"]

.pyup.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# autogenerated pyup.io config file
1+
# autogenerated pyup.io config file
22
# see https://pyup.io/docs/configuration/ for all available options
33

44
schedule: ''

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Flycs SDK contains the Python SDK to interact with the Flycs data framework.
3030
Features
3131
--------
3232

33-
* TODO
33+
* Allows you to create the data objects needed to interact with Flycs.
3434

3535
Credits
3636
-------

docs/conf.py

+31-38
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#
2020
import os
2121
import sys
22-
sys.path.insert(0, os.path.abspath('..'))
22+
23+
sys.path.insert(0, os.path.abspath(".."))
2324

2425
import flycs_sdk
2526

@@ -32,25 +33,25 @@
3233
# Add any Sphinx extension module names here, as strings. They can be
3334
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3435
extensions = [
35-
'sphinx.ext.autodoc',
36-
'sphinx.ext.viewcode',
37-
'sphinx.ext.napoleon',
36+
"sphinx.ext.autodoc",
37+
"sphinx.ext.viewcode",
38+
"sphinx.ext.napoleon",
3839
]
3940

4041
# Add any paths that contain templates here, relative to this directory.
41-
templates_path = ['_templates']
42+
templates_path = ["_templates"]
4243

4344
# The suffix(es) of source filenames.
4445
# You can specify multiple suffix as a list of string:
4546
#
4647
# source_suffix = ['.rst', '.md']
47-
source_suffix = '.rst'
48+
source_suffix = ".rst"
4849

4950
# The master toctree document.
50-
master_doc = 'index'
51+
master_doc = "index"
5152

5253
# General information about the project.
53-
project = 'Flycs SDK'
54+
project = "Flycs SDK"
5455
copyright = "2020, Tristan Van Thielen"
5556
author = "Tristan Van Thielen"
5657

@@ -73,21 +74,20 @@
7374
# List of patterns, relative to source directory, that match files and
7475
# directories to ignore when looking for source files.
7576
# This patterns also effect to html_static_path and html_extra_path
76-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
77+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7778

7879
# The name of the Pygments (syntax highlighting) style to use.
79-
pygments_style = 'sphinx'
80+
pygments_style = "sphinx"
8081

8182
# If true, `todo` and `todoList` produce output, else they produce nothing.
8283
todo_include_todos = False
8384

84-
8585
# -- Options for HTML output -------------------------------------------
8686

8787
# The theme to use for HTML and HTML Help pages. See the documentation for
8888
# a list of builtin themes.
8989
#
90-
html_theme = 'alabaster'
90+
html_theme = "alabaster"
9191

9292
# Theme options are theme-specific and customize the look and feel of a
9393
# theme further. For a list of options available for each theme, see the
@@ -98,30 +98,25 @@
9898
# Add any paths that contain custom static files (such as style sheets) here,
9999
# relative to this directory. They are copied after the builtin static files,
100100
# so a file named "default.css" will overwrite the builtin "default.css".
101-
html_static_path = ['_static']
102-
101+
html_static_path = ["_static"]
103102

104103
# -- Options for HTMLHelp output ---------------------------------------
105104

106105
# Output file base name for HTML help builder.
107-
htmlhelp_basename = 'flycs_sdkdoc'
108-
106+
htmlhelp_basename = "flycs_sdkdoc"
109107

110108
# -- Options for LaTeX output ------------------------------------------
111109

112110
latex_elements = {
113111
# The paper size ('letterpaper' or 'a4paper').
114112
#
115113
# 'papersize': 'letterpaper',
116-
117114
# The font size ('10pt', '11pt' or '12pt').
118115
#
119116
# 'pointsize': '10pt',
120-
121117
# Additional stuff for the LaTeX preamble.
122118
#
123119
# 'preamble': '',
124-
125120
# Latex figure (float) alignment
126121
#
127122
# 'figure_align': 'htbp',
@@ -131,36 +126,34 @@
131126
# (source start file, target name, title, author, documentclass
132127
# [howto, manual, or own class]).
133128
latex_documents = [
134-
(master_doc, 'flycs_sdk.tex',
135-
'Flycs SDK Documentation',
136-
'Tristan Van Thielen', 'manual'),
129+
(
130+
master_doc,
131+
"flycs_sdk.tex",
132+
"Flycs SDK Documentation",
133+
"Tristan Van Thielen",
134+
"manual",
135+
),
137136
]
138137

139-
140138
# -- Options for manual page output ------------------------------------
141139

142140
# One entry per manual page. List of tuples
143141
# (source start file, name, description, authors, manual section).
144-
man_pages = [
145-
(master_doc, 'flycs_sdk',
146-
'Flycs SDK Documentation',
147-
[author], 1)
148-
]
149-
142+
man_pages = [(master_doc, "flycs_sdk", "Flycs SDK Documentation", [author], 1)]
150143

151144
# -- Options for Texinfo output ----------------------------------------
152145

153146
# Grouping the document tree into Texinfo files. List of tuples
154147
# (source start file, target name, title, author,
155148
# dir menu entry, description, category)
156149
texinfo_documents = [
157-
(master_doc, 'flycs_sdk',
158-
'Flycs SDK Documentation',
159-
author,
160-
'flycs_sdk',
161-
'One line description of project.',
162-
'Miscellaneous'),
150+
(
151+
master_doc,
152+
"flycs_sdk",
153+
"Flycs SDK Documentation",
154+
author,
155+
"flycs_sdk",
156+
"One line description of project.",
157+
"Miscellaneous",
158+
),
163159
]
164-
165-
166-

flycs_sdk/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Top-level package for Flycs SDK."""
22

33
__author__ = """Tristan Van Thielen"""
4-
__email__ = 'tristan.van.thielen@devoteam.com'
5-
__version__ = '0.4.0'
4+
__email__ = "tristan.van.thielen@devoteam.com"
5+
__version__ = "0.4.0"

flycs_sdk/cli.py

-21
This file was deleted.

flycs_sdk/entities.py

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
"""Module containing entity classes."""
2+
3+
from typing import Dict
4+
5+
6+
class Entity:
7+
"""Class that is used for converting an entity class to an Airflow DAG."""
8+
9+
def __init__(
10+
self,
11+
name: str,
12+
version: str,
13+
parameters: Dict[str, str] = None,
14+
stage_config: Dict[str, Dict[str, str]] = None,
15+
):
16+
"""
17+
Create an Entity object.
18+
19+
:param name: the name of the entity
20+
:param version: the version of the entity, this can be used for table naming
21+
:param parameters: the parameters as set in the running environment. These are inherited from the pipeline
22+
this entity belongs to.
23+
:param stage_config: a dictionary with the name of the stage as key and a dictionary of query names
24+
and their versions as value.
25+
"""
26+
self.name = name
27+
self.version = version
28+
self.parameters = parameters
29+
self.stage_config = stage_config
30+
31+
def get_stage_versions(self, stage: str) -> Dict[str, str]:
32+
"""
33+
Get the versions of the queries in the given stage.
34+
35+
:return: the versions of the queries in the given stage
36+
"""
37+
return self.stage_config[stage]
38+
39+
def to_dict(self) -> Dict:
40+
"""
41+
Serialize the entity to a dictionary object.
42+
43+
:return: the entity as a dictionary object.
44+
"""
45+
return {
46+
"name": self.name,
47+
"version": self.version,
48+
"stage_config": [
49+
{"name": stage, "versions": self.get_stage_versions(stage)}
50+
for stage in self.stage_config.keys()
51+
],
52+
}
53+
54+
55+
class BaseLayerEntity(Entity):
56+
"""Class that is used for converting an entity class to an Airflow DAG."""
57+
58+
def __init__(
59+
self,
60+
name: str,
61+
version: str,
62+
parameters: Dict[str, str],
63+
datalake_versions: Dict[str, str] = None,
64+
preamble_versions: Dict[str, str] = None,
65+
staging_versions: Dict[str, str] = None,
66+
data_warehouse_versions: Dict[str, str] = None,
67+
data_mart_versions: Dict[str, str] = None,
68+
):
69+
"""
70+
Create an BaseLayerEntity object.
71+
72+
A BaseLayerEntity should be used in the case when the normal layer configuration is being used.
73+
This means there are 5 layers: datalake, preamble, staging, data_warehouse and data_mart.
74+
75+
:param name: the name of the entity
76+
:param version: the version of the entity, this can be used for table naming
77+
:param parameters: the parameters as set in the running environment. These are inherited from the pipeline
78+
this entity belongs to.
79+
:param stage_config: a dictionary with the name of the stage as key and a dictionary of query names
80+
and their versions as value.
81+
"""
82+
self.datalake_versions = datalake_versions
83+
self.preamble_versions = preamble_versions
84+
self.staging_versions = staging_versions
85+
self.data_warehouse_versions = data_warehouse_versions
86+
self.data_mart_versions = data_mart_versions
87+
super().__init__(name, version, parameters)
88+
89+
def get_stage_versions(self, stage: str) -> Dict[str, str]:
90+
"""
91+
Get the versions of the queries in the given stage.
92+
93+
:return: the versions of the queries in the given stage
94+
"""
95+
if stage == "datalake":
96+
return self.get_datalake_versions()
97+
elif stage == "preamble":
98+
return self.get_preamble_versions()
99+
if stage == "staging":
100+
return self.get_staging_versions()
101+
if stage == "data_warehouse":
102+
return self.get_data_warehouse_versions()
103+
if stage == "data_mart":
104+
return self.get_data_mart_versions()
105+
106+
def get_datalake_versions(self) -> Dict[str, str]:
107+
"""
108+
Get the versions of the queries in the datalake stage.
109+
110+
:return: the versions of the queries in the datalake stage
111+
"""
112+
if self.datalake_versions is None:
113+
return {}
114+
else:
115+
return self.datalake_versions
116+
117+
def get_preamble_versions(self) -> Dict[str, str]:
118+
"""
119+
Get the versions of the queries in the preamble stage.
120+
121+
:return: the versions of the queries in the preamble stage
122+
"""
123+
if self.preamble_versions is None:
124+
return {}
125+
else:
126+
return self.preamble_versions
127+
128+
def get_staging_versions(self) -> Dict[str, str]:
129+
"""
130+
Get the versions of the queries in the staging stage.
131+
132+
:return: the versions of the queries in the staging stage
133+
"""
134+
if self.staging_versions is None:
135+
return {}
136+
else:
137+
return self.staging_versions
138+
139+
def get_data_warehouse_versions(self) -> Dict[str, str]:
140+
"""
141+
Get the versions of the queries in the data warehouse stage.
142+
143+
:return: the versions of the queries in the data warehouse stage
144+
"""
145+
if self.data_warehouse_versions is None:
146+
return {}
147+
else:
148+
return self.data_warehouse_versions
149+
150+
def get_data_mart_versions(self) -> Dict[str, str]:
151+
"""
152+
Get the versions of the queries in the data mart stage.
153+
154+
:return: the versions of the queries in the data mart stage
155+
"""
156+
if self.data_mart_versions is None:
157+
return {}
158+
else:
159+
return self.data_mart_versions

flycs_sdk/exceptions/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Module containing all exceptions."""

0 commit comments

Comments
 (0)