Skip to content

Commit

Permalink
Merge pull request #17 from marchinho11/add-improvements-iteration
Browse files Browse the repository at this point in the history
Improvements iteration
  • Loading branch information
marchinho11 authored Oct 15, 2023
2 parents 7e772c2 + 44760e0 commit 44409df
Show file tree
Hide file tree
Showing 38 changed files with 649 additions and 1,350 deletions.
10 changes: 0 additions & 10 deletions .coveragerc

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/docs.yaml

This file was deleted.

15 changes: 8 additions & 7 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ on:
workflow_call:

jobs:
black:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: psf/black@stable
with:
version: "23.3.0"
version: "23.9.1"

isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: isort/isort-action@v1
with:
isort-version: "5.12.0"

- uses: chartboost/ruff-action@v1
with:
version: "0.0.292"
24 changes: 15 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ jobs:
runs-on: ubuntu-latest
needs: [ tests ]
steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry==1.6.1

- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"
- run: poetry install

- run: poetry build
- run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
- run: poetry publish
- name: Install poetry dependencies
run: poetry install

- name: Build python package
run: poetry build

- name: Configure PyPi secrets
run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}

docs:
needs: [ pypi ]
uses: ./.github/workflows/docs.yaml
- name: Publish python package to PyPi
run: poetry publish
14 changes: 10 additions & 4 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ jobs:
- 5432:5432

steps:
- uses: actions/checkout@v3
- run: pipx install poetry
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry==1.6.1

- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"
- run: poetry install

- run: poetry run pytest -v --cov=hnhm --cov-report xml --cov-report term tests/
- name: Install poetry dependencies
run: poetry install

- name: Run tests with coverage
run: poetry run pytest -v --cov=hnhm --cov-report xml --cov-report term tests/
env:
PG_DB: ${{ env.PG_DB }}
PG_USER: ${{ env.PG_USER }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

dist/
.pytest_cache/
.mypy_cache/
.ruff_cache/
**/__pycache__/*

.coverage
Expand Down
13 changes: 12 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.9.1
hooks:
- id: black
language_version: python3.10
Expand All @@ -9,3 +9,14 @@ repos:
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.292
hooks:
- id: ruff

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.0
hooks:
- id: mypy
exclude: ^tests/
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ lines:

lines-all:
@poetry run pygount --format=summary --suffix=py hnhm/ tests/

bump:
@poetry run bump-my-version bump patch
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Implementation of this package is based on report
* [Supported Databases](#supported-databases)
* [Future plans](#future-plans)
* [Contribute!](#contribute)
* [Documentation](#documentation)
* [Created with](#created-with)


## Tutorial
Expand Down Expand Up @@ -140,7 +140,7 @@ class User(HnhmEntity):

__layout__ = Layout(name="user", type=LayoutType.HNHM)

user_id = String(comment="User ID.", change_type=ChangeType.IGNORE)
user_id = String("User ID.", change_type=ChangeType.IGNORE)

__keys__ = [user_id]

Expand Down Expand Up @@ -212,10 +212,10 @@ class User(HnhmEntity):
__layout__ = Layout(name="user", type=LayoutType.HNHM)
user_id = String(comment="User ID.", change_type=ChangeType.IGNORE)
+ age = Integer(comment="Age.", change_type=ChangeType.UPDATE)
+ first_name = String(comment="First name.", change_type=ChangeType.NEW, group="name")
+ last_name = String(comment="Last name.", change_type=ChangeType.NEW, group="name")
user_id = String("User ID.", change_type=ChangeType.IGNORE)
+ age = Integer("Age.", change_type=ChangeType.UPDATE)
+ first_name = String("First name.", change_type=ChangeType.NEW, group="name")
+ last_name = String("Last name.", change_type=ChangeType.NEW, group="name")
__keys__ = [user_id]
Expand Down Expand Up @@ -320,8 +320,6 @@ view: entity__user
* Guides, best practices, and recipes
* Code Style & CI
* Testing matrix
* Adopt [`Ruff`](https://github.com/roman-right/beanie/blob/main/.pre-commit-config.yaml) or [`wemake-python-styleguide`](https://github.com/wemake-services/wemake-python-styleguide)
## Contribute!
What contributions are welcome? (**spoiler: any!**)
Expand All @@ -333,6 +331,7 @@ What contributions are welcome? (**spoiler: any!**)
- Code refinement
- Bug fixes
## Documentation
https://marchinho11.github.io/hnhm
## Created with
| <img height="20" src="https://upload.wikimedia.org/wikipedia/commons/1/1d/PyCharm_Icon.svg"> PyCharm Professional |
|-------------------------------------------------------------------------------------------------------------------|
| <img height="20" src="https://upload.wikimedia.org/wikipedia/commons/3/3a/Neovim-mark.svg"> Neovim |
6 changes: 0 additions & 6 deletions docs/assets/color_scheme.css

This file was deleted.

Binary file removed docs/assets/favicon.png
Binary file not shown.
Binary file removed docs/assets/logo.png
Binary file not shown.
7 changes: 0 additions & 7 deletions docs/index.md

This file was deleted.

8 changes: 4 additions & 4 deletions dwh/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class User(HnhmEntity):

__layout__ = Layout(name="user", type=LayoutType.HNHM)

user_id = String(comment="User ID.", change_type=ChangeType.IGNORE)
age = Integer(comment="Age.", change_type=ChangeType.UPDATE)
first_name = String(comment="First name.", change_type=ChangeType.NEW, group="name")
last_name = String(comment="Last name.", change_type=ChangeType.NEW, group="name")
user_id = String("User ID.", change_type=ChangeType.IGNORE)
age = Integer("Age.", change_type=ChangeType.UPDATE)
first_name = String("First name.", change_type=ChangeType.NEW, group="name")
last_name = String("Last name.", change_type=ChangeType.NEW, group="name")

__keys__ = [user_id]
5 changes: 4 additions & 1 deletion hnhm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .postgres.sql import PostgresPsycopgSql
from .hnhm_link import HnhmLink, HnhmLinkElement
from .hnhm_entity import Layout, HnhmEntity, LayoutType
from .hnhm_attribute import Float, String, Integer, Timestamp, ChangeType
from .hnhm_attribute import Float, String, Boolean, Integer, Timestamp, ChangeType

__all__ = [
"ChangeType",
Expand All @@ -25,4 +25,7 @@
"PostgresPsycopgSql",
"String",
"Timestamp",
"Boolean",
]

__version__ = "0.0.10"
4 changes: 2 additions & 2 deletions hnhm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def import_registry(module: str) -> HnhmRegistry:
"Please, use the hnhm from the parent directory."
)

module = module.rstrip("/").lstrip("/")
module = module.strip("/")
module = f"{module}.__hnhm__"

click.secho(
Expand All @@ -24,7 +24,7 @@ def import_registry(module: str) -> HnhmRegistry:
click.secho()
imported_module = importlib.import_module(module)

registry: HnhmRegistry = getattr(imported_module, "registry", None)
registry: HnhmRegistry | None = getattr(imported_module, "registry", None)
if not registry:
raise HnhmError(
f"Failed to import registry from module: '{module}'."
Expand Down
1 change: 1 addition & 0 deletions hnhm/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Type(str, Enum):
INTEGER = "INTEGER"
FLOAT = "FLOAT"
TIMESTAMP = "TIMESTAMP"
BOOLEAN = "BOOLEAN"

def __str__(self):
return self.name
Expand Down
2 changes: 1 addition & 1 deletion hnhm/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class LoadLink(Task):
priority: Priority = Priority.SECOND
link: Link
key_entities_names: list[str]
keys_mapping: dict[str, dict[Attribute, Attribute]]
keys_mapping: dict[str, dict[Attribute, Attribute]] # type: ignore

@property
def id(self):
Expand Down
8 changes: 4 additions & 4 deletions hnhm/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def tasks(self) -> list[task.Task]:
)

for link_name, link in self._links.items():
keys_mapping = {}
keys_mapping_link = {}
depends_on = []
key_entities_names = []
for link_element in link.elements:
entity_name = link_element.entity.name
depends_on.append(hub_tasks[entity_name].id)
keys_mapping[entity_name] = self._entities_keys_mappings[entity_name]
keys_mapping_link[entity_name] = self._entities_keys_mappings[entity_name]

if link_element in link.keys:
key_entities_names.append(link_element.entity.name)
Expand All @@ -96,7 +96,7 @@ def tasks(self) -> list[task.Task]:
task.LoadLink(
source=self.source,
link=link,
keys_mapping=keys_mapping,
keys_mapping=keys_mapping_link,
key_entities_names=key_entities_names,
business_time_field=self.business_time_field,
depends_on=depends_on,
Expand Down Expand Up @@ -129,7 +129,7 @@ def load(
)

keys_mapping = {}
groups_mapping = {}
groups_mapping: dict[str, dict[Attribute, Attribute]] = {}
attributes_mapping = {}
for attribute_target, attribute_source in mapping.items():
attribute_target = attribute_target.to_core(target_entity.name)
Expand Down
2 changes: 1 addition & 1 deletion hnhm/hnhm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def is_empty(self):
return not self.entities_migrations and not self.links_migrations

@property
def migrations_all(self):
def migrations_all(self) -> list[migration.Migration]:
migrations: list[migration.Migration] = []

for collection in self.entities_migrations.values():
Expand Down
8 changes: 6 additions & 2 deletions hnhm/hnhm_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class HnhmAttribute(abc.ABC):

def __init__(
self,
*,
comment: str,
change_type: ChangeType,
*,
change_type: ChangeType = ChangeType.IGNORE,
group: str | None = None,
):
self.comment = comment
Expand Down Expand Up @@ -47,3 +47,7 @@ class Float(HnhmAttribute):

class Timestamp(HnhmAttribute):
type = Type.TIMESTAMP


class Boolean(HnhmAttribute):
type = Type.BOOLEAN
2 changes: 1 addition & 1 deletion hnhm/hnhm_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class HnhmEntity(abc.ABC):
__layout__: Layout = None
__layout__: Layout | None = None
__keys__: list[HnhmAttribute] | None = None

def to_core(self) -> Entity:
Expand Down
4 changes: 2 additions & 2 deletions hnhm/hnhm_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


class HnhmLinkElement:
def __init__(self, *, entity: HnhmEntity, comment: str):
self.entity = entity
def __init__(self, comment: str, *, entity: HnhmEntity):
self.comment = comment
self.entity = entity

def to_core(self) -> LinkElement:
entity = self.entity.to_core()
Expand Down
Loading

0 comments on commit 44409df

Please sign in to comment.