Skip to content

Commit

Permalink
add priority kwargs; use pre-commit.ci; bump version (#23)
Browse files Browse the repository at this point in the history
* add pirority kwargs; use pre-commit.ci; bump version

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PythonFZ and pre-commit-ci[bot] authored Sep 21, 2023
1 parent e7e3acf commit 0ce3fc7
Show file tree
Hide file tree
Showing 13 changed files with 928 additions and 1,242 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/lint.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.11"
- "3.10"
- 3.9
- 3.8
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ cython_debug/
.idea/

# Project temporary directory
tmp/
tmp/
63 changes: 39 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
exclude: '.git|.tox'
default_stages: [commit]
fail_fast: true

default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
args: ['--assume-in-merge']
exclude: ^(docs/)
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ['--fix=lf']
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
additional_dependencies: [".[jupyter]"]
types_or: [python, pyi, jupyter]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.126
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.290'
hooks:
- id: ruff


- repo: local
args: ['--fix']
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
exclude: ^test
types: [python]
args:
[
"--load-plugins=perflint"
]
- id: mdformat
args: ["--wrap=80"]
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@ CONTRIBUTION AGREEMENT

By contributing to the BVLC/caffe repository through pull-request, comment,
or otherwise, the contributor releases their content to the
license and copyright terms herein.
license and copyright terms herein.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/zincware/ZnInit/HEAD)
[![zincware](https://img.shields.io/badge/Powered%20by-zincware-darkcyan)](https://github.com/zincware)

# ZnInit - Automatic Generation of ``__init__`` based on Descriptors

This package provides a base class for ``dataclass`` like structures with the addition of using [Descriptors](https://docs.python.org/3/howto/descriptor.html).
The main functionality is the automatic generation of an keyword-only``__init__`` based on selected descriptors.
The descriptors can e.g. overwrite ``__set__`` or ``__get__`` or have custom metadata associated with them.
The ``ZnInit`` package is used by [ZnTrack](https://github.com/zincware/ZnTrack) to enable lazy loading data from files as well as distinguishing between different types of descriptors such as `zn.params` or `zn.outputs`. An example can be found in the `examples` directory.
# ZnInit - Automatic Generation of `__init__` based on Descriptors

This package provides a base class for `dataclass` like structures with the
addition of using
[Descriptors](https://docs.python.org/3/howto/descriptor.html). The main
functionality is the automatic generation of an keyword-only`__init__` based on
selected descriptors. The descriptors can e.g. overwrite `__set__` or `__get__`
or have custom metadata associated with them. The `ZnInit` package is used by
[ZnTrack](https://github.com/zincware/ZnTrack) to enable lazy loading data from
files as well as distinguishing between different types of descriptors such as
`zn.params` or `zn.outputs`. An example can be found in the `examples`
directory.

# Example

The most simple use case is a replication of a dataclass like structure.

```python
Expand All @@ -35,9 +42,12 @@ fabian = Human(name="Fabian")
fabian = Human(name="Fabian", language="DE")
```

The benefit of using ``ZnInit`` comes with using descriptors. You can subclass the `zninit.Descriptor` class and only add certain kwargs to the `__init__` defined in `init_descriptors: list`. Furthermore, a `post_init` method is available to run code immediately after initializing the class.
The benefit of using `ZnInit` comes with using descriptors. You can subclass the
`zninit.Descriptor` class and only add certain kwargs to the `__init__` defined
in `init_descriptors: list`. Furthermore, a `post_init` method is available to
run code immediately after initializing the class.

````python
```python
from zninit import ZnInit, Descriptor


Expand All @@ -63,17 +73,18 @@ julian = Human(name="Julian")
print(julian) # Human(language='DE', name='Julian')
print(julian.date) # 2022-09-16
print(Input.get_dict(julian)) # {"name": "Julian", "language": "DE"}
````
One benefit of ``ZnInit`` is that it also allows for inheritance.
```

One benefit of `ZnInit` is that it also allows for inheritance.

````python
```python
from zninit import ZnInit, Descriptor

class Animal(ZnInit):
age: int = Descriptor()

class Cat(Animal):
name: str = Descriptor()

billy = Cat(age=4, name="Billy")
````
```
Loading

0 comments on commit 0ce3fc7

Please sign in to comment.