Commit bf177a46 authored by David Scheliga's avatar David Scheliga

Release 0.0a2

parent 7448f445
**/__pycache__/*pyc
**/Testing/**
**/debug_scripts/**
**/scratches/**
.idea/**
docs/_build/**
......
# Changelog
This changelog is inspired by [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Release 0.0a2 (2020.02.07)
### Added
- added *normalize_path_of_tree* to documentation
- added doctest to package.rst for *normalize_path_of_tree*
### Changed
- made the setup.py more convenient by adding cleaning directory, since
*clean* argument didn't work with setuptools
### Fixed
- *augmentedtree.core.normalize_path_of_tree* ignores other data types than
*str*, *int* or *float* within the path creation.
## Release 0.0a1.post4 (2020.02.03)
## Added
### Added
- added changelog
- added source code and documentation link to setup
## Fixed
### Fixed
- fixed broken link
## Release 0.0a1.post3 (2020.02.02)
# Fixed
### Fixed
- fixed all wrong links in the docs and readme.md
- fixed missing packages within requirements.txt
## Added
### Added
- all tree item classes are now shown within the package chapter
## Release 0.0a1 (2020.02.02)
......
__version__ = "0.0a1.post4"
__version__ = "0.0a2"
import augmentedtree.core
from augmentedtree.core import (
......
......@@ -10,7 +10,7 @@ from typing import (
Optional,
Dict,
Callable,
)
Sequence)
_logger = logging.getLogger("augmentedtree")
......@@ -18,6 +18,8 @@ _augmentation_classes = {}
_mappingtree_json_schemas = {}
_type_defined_augmentation_methods = {}
_detect_multiple_delimiter = re.compile("\/+")
_valid_path_part_types = (str, int, float)
AUGMENTATION_FOR_MAPPING = "mapping"
AUGMENTATION_FOR_SEQUENCE = "sequence"
......@@ -470,39 +472,50 @@ def set_augmentation_classes(usecase, class_type, augmentation_class):
_augmentation_classes[usecase][class_type] = augmentation_class
def normalize_path_of_tree(treepath: Union[str, List[str]]):
def normalize_path_of_tree(*treepath: Union[str, List[str]]):
"""
Normalized a path (str) or parts of a path (List[str]) to
'/a/path/like/this'.
Args:
treepath:
*treepath:
A single tree path part or multiple tree path parts.
Returns:
str:
Normalized path '/like/this/example'.
"""
if isinstance(treepath, int):
treepath = str(treepath)
first_item_is_the_path_in_parts = (
len(treepath) == 1
and isinstance(treepath[0], (list, tuple))
)
if first_item_is_the_path_in_parts:
return normalize_path_of_tree(*treepath[0])
if not treepath:
return ""
if isinstance(treepath, list):
try:
joined_path = TreePath.DELIMITER.join(treepath)
except TypeError:
convert_path = [str(part) for part in treepath]
joined_path = TreePath.DELIMITER.join(convert_path)
return normalize_path_of_tree(joined_path)
assert isinstance(
treepath, str
), "`treepath` should be `str` is `{}` instead".format(type(treepath))
normalized_path = _detect_multiple_delimiter.sub("/", treepath)
convert_path = [
str(part) for part in treepath
if isinstance(part, _valid_path_part_types)
]
joined_path = TreePath.DELIMITER.join(convert_path)
normalized_path = _detect_multiple_delimiter.sub("/", joined_path)
if not normalized_path:
return ""
if normalized_path[-1] == TreePath.DELIMITER:
normalized_path = normalized_path[:-1]
if normalized_path[0] != TreePath.DELIMITER:
LAST_CHAR = -1
FIRST_CHAR = 0
ALL_EXCEPT_LAST = slice(None, -1, None)
path_ends_with_delimiter = normalized_path[LAST_CHAR] == TreePath.DELIMITER
if path_ends_with_delimiter:
normalized_path = normalized_path[ALL_EXCEPT_LAST]
path_starts_with_delimiter = normalized_path[FIRST_CHAR] == TreePath.DELIMITER
if not path_starts_with_delimiter:
normalized_path = TreePath.DELIMITER + normalized_path
return normalized_path
......@@ -570,8 +583,13 @@ class TreePath(object):
If parameter `treepath` is given, all parameters are overriden by it.
Args:
real_path:
augmented_path:
real_path (Union[str, List[str]]):
Real path within the nested data structure of the augmented tree items.
augmented_path (Union[str, List[str]]):
Path defined by the augmentation; if no schemas are used identical to
*real_path*
meta_attributes (List):
Associations of this path part.
......
......@@ -39,7 +39,8 @@ extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.ifconfig',
'sphinx.ext.napoleon',
'sphinx_rtd_theme'
'sphinx_rtd_theme',
'sphinx.ext.doctest'
]
# Add any paths that contain templates here, relative to this directory.
......@@ -79,9 +80,11 @@ html_theme_options = {
'style_external_links': False,
'style_nav_header_background': 'white',
# Toc options
'collapse_navigation': False,
'collapse_navigation': True,
'sticky_navigation': True,
'navigation_depth': 4,
'includehidden': True,
'titles_only': False
}
# nbsphinx_allow_errors = True
\ No newline at end of file
......@@ -91,13 +91,10 @@ The **development status** is **alpha**.
.. toctree::
:maxdepth: 2
:maxdepth: 3
:caption: Contents:
basic_usage
detailed_examples
an_augmented_tree_item
package
package/package
......@@ -81,4 +81,46 @@ Enhancement of Mappings by *schemas*
.. autoclass:: MappingSchemaBuilder
:members: construct, construct_from_collection
Tree path related
-----------------
.. autoclass:: augmentedtree.core.TreePath
:members:
.. autofunction:: augmentedtree.core.normalize_path_of_tree
.. testsetup:: *
from augmentedtree.core import normalize_path_of_tree
.. doctest::
>>> normalize_path_of_tree("//to/many/delimiters///everywhere//")
'/to/many/delimiters/everywhere'
>>> normalize_path_of_tree("missing/front/delimiter")
'/missing/front/delimiter'
>>> normalize_path_of_tree("/this/path/is/correct")
'/this/path/is/correct'
>>> normalize_path_of_tree("/unwanted/delimiter/at/the/end/")
'/unwanted/delimiter/at/the/end'
>>> normalize_path_of_tree(None)
''
>>> normalize_path_of_tree([])
''
.. doctest::
>>> normalize_path_of_tree("//to", "/many/delimiters//", "/everywhere//")
'/to/many/delimiters/everywhere'
>>> normalize_path_of_tree("missing", "front/delimiter")
'/missing/front/delimiter'
>>> normalize_path_of_tree("this", "path", "is/correct")
'/this/path/is/correct'
>>> normalize_path_of_tree("unwanted", "delimiter", "at/the/end/")
'/unwanted/delimiter/at/the/end'
>>> normalize_path_of_tree("invalid", "type", [], "within/the/path")
'/invalid/type/within/the/path'
>>> normalize_path_of_tree(None)
''
>>> normalize_path_of_tree([])
''
\ No newline at end of file
......@@ -5,12 +5,33 @@ from setuptools import setup, find_packages
# read the contents of your README file
from os import path
import augmentedtree
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
long_description = f.read()
import augmentedtree
REMOVE_THESE_PATH_PRIOR_SETUP = ["build", "dist", "*.egg-info"]
REMOVE_THESE_PATH_POST_SETUP = ["build", "*.egg-info"]
def _remove_paths(root_path, path_patterns):
from shutil import rmtree
from pathlib import Path
abs_path = Path(root_path).resolve()
paths_to_remove = []
for path_pattern in path_patterns:
found_paths_to_remove = list(abs_path.glob(path_pattern))
paths_to_remove.extend(found_paths_to_remove)
for path_to_remove in paths_to_remove:
print("removing path {}".format(path_to_remove))
rmtree(path_to_remove)
_remove_paths(this_directory, REMOVE_THESE_PATH_PRIOR_SETUP)
setup(
name="augmentedtree",
......@@ -44,6 +65,10 @@ setup(
],
keywords="dictionary, mapping, list, sequence, nested, handling, navigation, selection",
python_requires=">=3.6",
packages=find_packages(),
#exclude_package_data={"augmentedtree": ["scratches/*", "debug_scripts/*"]},
packages=find_packages(exclude=["*.scratches", "*.debug_scripts", "*.scratches.*", "*.debug_scripts.*"]),
requires=["pandas", 'numpy'],
)
_remove_paths(this_directory, REMOVE_THESE_PATH_POST_SETUP)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment