Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff #103

Merged
merged 3 commits into from
Mar 8, 2023
Merged

Ruff #103

Show file tree
Hide file tree
Changes from all commits
Commits
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/testing-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
with:
python-version: ${{ matrix.python_version }}
cache: 'poetry'
# use the whole repo's hash (i.e. recalculate the deps everytime)
# use the whole repo's hash (i.e. recalculate the deps every time)
cache-dependency-path: pyproject.toml

- name: Install dependencies
Expand Down
30 changes: 11 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,36 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-docstring-first
- id: check-symlinks
- id: check-builtin-literals
exclude: tests
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
# only useful for pre-commit hooked to git
args: ["--profile", "black"]

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: "6.0.0"
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.253"
hooks:
- id: flake8
exclude: tests
- id: ruff
args: ["--fix"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
hooks:
- id: mypy
# files: tawazi
- id: mypy
files: tawazi
args: []
additional_dependencies:
- pydantic
Expand All @@ -44,11 +42,5 @@ repos:
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
- id: bandit
args: ["--ini", ".bandit", "--recursive"]

- repo: https://github.com/terrencepreilly/darglint
rev: v1.8.1
hooks:
- id: darglint
exclude: ^(tests|scripts)/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ assert pipeline() == (2, 3)
Currently you can only return a single value from an `ExecNode`, in the future multiple return values will be allowed.


* You can have setup `ExecNode`s; Theses are `ExecNode`s that will run once per DAG instance
* You can have setup `ExecNode`s; These are `ExecNode`s that will run once per DAG instance

```Python
from copy import deepcopy
Expand Down Expand Up @@ -291,7 +291,7 @@ assert res_c == "A + B = C"
<!-- ## Limitations:
Currently there are some limitations in the usage of tawazi that will be overcome in the future.
1. A DAG can not reuse the same function twice inside the calculation sequence (Will be resolved in the future)
2. All code inside a dag descriptor function must be either an @op decorated functions calls and arguments passed arguments. Otherwise the behavior of the DAG might be unpredicatble -->
2. All code inside a dag descriptor function must be either an @op decorated functions calls and arguments passed arguments. Otherwise the behavior of the DAG might be unpredictable -->



Expand Down
2 changes: 1 addition & 1 deletion documentation/future_developments.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A couple of features will be released soon:

* handle problems when calling `ExecNodes` wrongly.
* (for example when using *args as parameters but only **kwargs are provided).
* Calling `ExecNodes` must be similar to calling the original function (must imitate the same signature otherwise raise the correct exeception).
* Calling `ExecNodes` must be similar to calling the original function (must imitate the same signature otherwise raise the correct exception).
* support mixing ExecNodes and non `ExecNodes` functions.
* test the case where `ExecNodes` are stored in a list and then passed via * operator.
* add feature to turn off a set of nodes in the graph.
Expand Down
37 changes: 33 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,39 @@ strict_equality = true
module = "matplotlib.*,networkx.*,yaml.*"
ignore_missing_imports = true

[tool.isort]
profile = "black"
line_length = 100

[tool.black]
skip-magic-trailing-comma = true
line-length = 100


[tool.ruff]
# Use of assert detected
ignore = ["E501", "S101"]
src = ["src"]
line-length = 100
target-version = "py38"
select = [
"B",
"D",
"E",
"F",
"I",
"N",
"PGH",
"UP",
"S",
"T20",
"TID",
"W",
"RET"
]

[tool.ruff.per-file-ignores]
"tests/*.py" = ["D"]
"scripts/*.py" = ["D", "PGH"]

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "parents"

[tool.ruff.pydocstyle]
convention = "google"
10 changes: 4 additions & 6 deletions tawazi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""tawazi is a package that allows parallel execution of a set of functions written in Python."""

# exposing useful objects / Classes
from .config import Cfg
from .dag import DAG, DAGExecution
from .decorators import xn, dag
from .decorators import dag, xn
from .errors import ErrorStrategy
from .config import Cfg

"""
tawazi is a package that allows parallel execution of a set of functions written in Python
isort:skip_file
"""
__version__ = "0.2.0"

__all__ = ["DAG", "DAGExecution", "xn", "dag", "ErrorStrategy", "Cfg"]
4 changes: 4 additions & 0 deletions tawazi/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"""configuration parameters for Tawazi."""

from pydantic import BaseSettings, Field


class Config(BaseSettings):
"""Class to set configuration parameters for Tawazi."""

# whether the default in tawazi is sequentiality or not.
# This is helpful to reduce your code size and avoid repeating @xn(is_sequentiality=True/False)
TAWAZI_IS_SEQUENTIAL: bool = False
Expand Down
43 changes: 40 additions & 3 deletions tawazi/consts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module containing constants used by Tawazi."""
from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar, Union

from typing_extensions import ParamSpec
Expand All @@ -11,8 +12,8 @@


class NoValType:
"""
Tawazi's special None.
"""Tawazi's special None.

This class is a singleton similar to None to determine that no value is assigned
>>> NoVal1 = NoValType()
>>> NoVal2 = NoValType()
Expand All @@ -26,23 +27,59 @@ class NoValType:
_instance = None

def __new__(cls: Type["NoValType"]) -> "NoValType":
"""Constructor for NoValType.

Returns:
NoValType: new instance of NoValType.
"""
if cls._instance is None:
cls._instance = super().__new__(cls)
return cls._instance

def __bool__(self) -> bool:
"""Whether NoVal is Truthy or Falsy.

Returns:
bool: always False
"""
return False

def __repr__(self) -> str:
"""Representation of NoValType.

Returns:
str: "NoVal"
"""
return "NoVal"

def __eq__(self, __o: object) -> bool:
"""Check for equality.

Args:
__o (object): the other object

Returns:
bool: always returns False
"""
return False

def __copy__(self) -> "NoValType":
"""Copy of NoVal.

Returns:
NoValType: Returns the original because NoVal is a singleton.
"""
return self

def __deepcopy__(self, _prev: Dict[Any, Any]) -> "NoValType":
"""Deep copy NoVal.

Args:
_prev (Dict[Any, Any]): the previous state of the object

Returns:
NoValType: the original NoVal because NoVal is a singleton.
"""
return self


Expand All @@ -55,7 +92,7 @@ def __deepcopy__(self, _prev: Dict[Any, Any]) -> "NoValType":

# NOTE: maybe support other key types? for example int... or even tuple...
ReturnIDsType = Optional[
Union[Dict[str, Identifier], List[Identifier], Tuple[Identifier], Identifier]
Union[Dict[str, Identifier], List[Identifier], Tuple[Identifier, ...], Identifier]
]
RVTypes = Union[Any, Tuple[Any], List[Any], Dict[str, Any]]
P = ParamSpec("P")
Expand Down
Loading