Skip to content

Commit

Permalink
Merge branch 'release/release1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed May 24, 2019
2 parents b7f4e6e + 2d10ba2 commit c61799d
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 48 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ script:
- coveralls
- black --check warg

deploy:
provider: pypi
user: ""
password: #travis encrypt your-password-here --add deploy.password
secure: "Your encrypted password"
on:
tags: true
#server: https://mypackageindex.com/index
#skip_existing: true
#skip_cleanup: true
#after_deploy:
# - ./after_deploy_1.sh
2 changes: 1 addition & 1 deletion benchmarks/returns_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sorcery

from benchmarks.benchmark_func import benchmark_func
from warg import NOD
from warg.named_ordered_dictionary import NOD


def returns_benchmark():
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ six
sorcery
pytest
cloudpickle
wrapt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
./clean_package.sh
scripts/clean_package.sh
#python2 setup.py bdist
#python2 setup.py bdist_wheel
#python3 setup.py bdist
python3 setup.py bdist_wheel
twine upload dist/*
./clean_package.sh
scripts/clean_package.sh
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_nod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
import pytest

from warg import NamedOrderedDictionary, IllegalAttributeKey
from warg.named_ordered_dictionary import NOD, IllegalAttributeKey

__author__ = "cnheider"

Expand Down
4 changes: 0 additions & 4 deletions warg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@
@author: cnheider
"""

from .named_ordered_dictionary import *
from .arguments import *
from .app_path import AppPath
11 changes: 11 additions & 0 deletions warg/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pathlib import Path, PosixPath
from warnings import warn

import wrapt

__author__ = "cnheider"


Expand Down Expand Up @@ -163,3 +165,12 @@ def check_for_duplicates_in_args(**kwargs) -> None:

if occur > 1:
warn(f"Config contains hiding duplicates of {key} and {k_lowered}, {occur} times")


def namedtuple_args(n_tuple):
@wrapt.decorator(adapter=n_tuple)
def wrapper(wrapped, instance, args, kwargs):
n = n_tuple(*args, **kwargs)
return wrapped(n)

return wrapper
5 changes: 5 additions & 0 deletions warg/experimental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = "cnheider"
__doc__ = ""
14 changes: 7 additions & 7 deletions warg/auto_nod_return.py → warg/experimental/auto_nod_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sorcery import dict_of

from warg import NamedOrderedDictionary
from warg.named_ordered_dictionary import NOD


def dict_of_func(func: callable = None) -> callable:
Expand All @@ -16,18 +16,18 @@ def dict_of_func(func: callable = None) -> callable:
def wrapper(*args, **kwargs):
if func.__name__ is not "__init__":
return_value = func(*args, **kwargs)
if isinstance(return_value, NamedOrderedDictionary):
if isinstance(return_value, NOD):
return return_value
elif isinstance(return_value, Mapping):
return NamedOrderedDictionary(**return_value)
return NOD(**return_value)
elif isinstance(return_value, Iterable):
return NamedOrderedDictionary(*return_value)
return NamedOrderedDictionary(return_value)
return NOD(*return_value)
return NOD(return_value)
else:
return func(*args, **kwargs)

sig = signature(func)
sig = sig.replace(return_annotation=NamedOrderedDictionary)
sig = sig.replace(return_annotation=NOD)
func.__signature__ = sig
wrapper.__signature__ = sig

Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, *args, **kwargs):
class NodReturnExampleClass(AutoNodReturns):
def cool(self, agkjas):
slfs = 4 + agkjas
return NamedOrderedDictionary(4, **dict_of(slfs))
return NOD(4, **dict_of(slfs))

def hot(self):
s = 7
Expand Down
24 changes: 24 additions & 0 deletions warg/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = "cnheider"
__doc__ = ""


class IterItemsMixin(object):
def __iter__(self):
for attr, value in self.__dict__.items():
yield attr, value


class IterKeysMixin(object):
def __iter__(self):
for attr in self.__dict__.keys():
yield attr


class IterValuesMixin(object):
def __iter__(self):
a = self.__dict__
for value in self.__dict__.values():
yield value
64 changes: 32 additions & 32 deletions warg/named_ordered_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,64 +34,64 @@ class NamedOrderedDictionary(Mapping):
.. code-block:: python
nodict = NamedOrderedDictionary()
nodict.paramA = 'str_parameter'
nodict.paramB = 10
assert nodict.paramA == 'str_parameter'
assert nodict.paramB == 10
nodict = NamedOrderedDictionary()
nodict.paramA = 'str_parameter'
nodict.paramB = 10
assert nodict.paramA == 'str_parameter'
assert nodict.paramB == 10
.. code-block:: python
nodict = NamedOrderedDictionary()
nodict['paramA'] = 10
assert nodict.paramA == 10
nodict = NamedOrderedDictionary()
nodict['paramA'] = 10
assert nodict.paramA == 10
.. code-block:: python
nodict = NamedOrderedDictionary({'paramA': 'str_parameter', 'paramB': 10})
assert nodict.paramA == 'str_parameter'
assert nodict.paramB == 10
nodict = NamedOrderedDictionary({'paramA': 'str_parameter', 'paramB': 10})
assert nodict.paramA == 'str_parameter'
assert nodict.paramB == 10
.. code-block:: python
nodict = NamedOrderedDictionary(paramA='str_parameter', paramB=10)
assert nodict.paramA == 'str_parameter'
assert nodict.paramB == 10
nodict = NamedOrderedDictionary(paramA='str_parameter', paramB=10)
assert nodict.paramA == 'str_parameter'
assert nodict.paramB == 10
.. code-block:: python
nodict = NamedOrderedDictionary('str_parameter', 10)
assert nodict.arg0 == 'str_parameter'
assert nodict.arg1 == 10
nodict = NamedOrderedDictionary('str_parameter', 10)
assert nodict.arg0 == 'str_parameter'
assert nodict.arg1 == 10
.. code-block:: python
arg0,arg1 = NamedOrderedDictionary('str_parameter', 10).as_list()
assert arg0 == 'str_parameter'
assert arg1 == 10
arg0,arg1 = NamedOrderedDictionary('str_parameter', 10).as_list()
assert arg0 == 'str_parameter'
assert arg1 == 10
As with dictionaries you can use the `update()` method.
.. code-block:: python
nodict = NamedOrderedDictionary()
nodict.update({'paramA': 20, 'paramB': 'other_param', 'paramC': 5.0})
assert nodict.paramA == 20
assert nodict.paramB == 'other_param'
nodict = NamedOrderedDictionary()
nodict.update({'paramA': 20, 'paramB': 'other_param', 'paramC': 5.0})
assert nodict.paramA == 20
assert nodict.paramB == 'other_param'
.. code-block:: python
nodict = NamedOrderedDictionary('str_parameter', 10)
nodict.update({'arg1': 20, 'arg0': 'other_param'})
assert nodict.arg0 == 'other_param'
assert nodict.arg1 == 20
nodict = NamedOrderedDictionary('str_parameter', 10)
nodict.update({'arg1': 20, 'arg0': 'other_param'})
assert nodict.arg0 == 'other_param'
assert nodict.arg1 == 20
.. code-block:: python
nodict = NamedOrderedDictionary(paramA='str_parameter', paramB=10)
nodict.update(20,'other_param')
assert nodict.paramB == 'other_param'
assert nodict.paramA == 20
nodict = NamedOrderedDictionary(paramA='str_parameter', paramB=10)
nodict.update(20,'other_param')
assert nodict.paramB == 'other_param'
assert nodict.paramA == 20
"""

Expand Down
1 change: 1 addition & 0 deletions warg/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


__author__ = "cnheider"
__doc__ = """
Created on 27/04/2019
Expand Down
2 changes: 1 addition & 1 deletion warg/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from warnings import warn

__author__ = "cnheider"
__version__ = "0.1.4"
__version__ = "0.1.5"
__version_info__ = tuple(int(segment) for segment in __version__.split("."))
__doc__ = """
Created on 27/04/2019
Expand Down

0 comments on commit c61799d

Please sign in to comment.