Code Monkey home page Code Monkey logo

Comments (7)

zerwes avatar zerwes commented on June 28, 2024

Hello. Would you please be so kind and provide me a patch / diff ?

from hiyapyco.

alex-ber avatar alex-ber commented on June 28, 2024

Index: hiyapyco/init.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8

--- hiyapyco/init.py (revision 8ab38a0)
+++ hiyapyco/init.py (date 1582205392539)
@@ -65,9 +65,11 @@

you may set this to something suitable for you

jinja2env = Environment(undefined=Undefined)

-METHODS = { 'METHOD_SIMPLE':0x0001, 'METHOD_MERGE':0x0002 }
+METHODS = { 'METHOD_SIMPLE':0x0001, 'METHOD_MERGE':0x0002, 'METHOD_SUBSTITUTE':0x0003 }
METHOD_SIMPLE = METHODS['METHOD_SIMPLE']
METHOD_MERGE = METHODS['METHOD_MERGE']
+METHOD_SUBSTITUTE = METHODS['METHOD_SUBSTITUTE']
+

class HiYaPyCo():
"""Main class"""
@@ -75,8 +77,8 @@
"""
args: YAMLfile(s)
kwargs:

  •      * method: one of hiyapyco.METHOD_SIMPLE | hiyapyco.METHOD_MERGE
    
  •      * mergelists: boolean (default: True) try to merge lists (only makes sense if hiyapyco.METHOD_MERGE)
    
  •      * method: one of hiyapyco.METHOD_SIMPLE | hiyapyco.METHOD_MERGE | hiyapyco.METHOD_SUBSTITUTE
    
  •      * mergelists: boolean (default: True) try to merge lists (only makes sense if hiyapyco.METHOD_MERGE or hiyapyco.METHOD_SUBSTITUTE)
         * interpolate: boolean (default: False)
         * castinterpolated: boolean (default: False) try to cast values after interpolating
         * usedefaultyamlloader: boolean (default: False)
    

@@ -238,6 +240,8 @@
else:
if self.method == METHOD_SIMPLE:
self._data = self._simplemerge(self._data, ydata)

  •            elif self.method == METHOD_SIMPLE:
    
  •                self._data = self._deepmerge(self._data, ydata)
               else:
                   self._data = self._deepmerge(self._data, ydata)
               logger.debug('merged data: %s' % self._data)
    

@@ -329,6 +333,50 @@
(type(b), type(a), a, b,)
)
return a
+

  • def __substmerge(self, a, b):

  •    logger.debug('>' * 30)
    
  •    logger.debug('deepmerge %s and %s' % (a, b,))
    
  •    # FIXME: make None usage configurable
    
  •    if b is None:
    
  •        logger.debug('pass as b is None')
    
  •        pass
    
  •    # treat listTypes as primitiveTypes in merge
    
  •    # subsititues list, don't merge them
    
  •    if a is None or isinstance(b, primitiveTypes) or isinstance(b, listTypes):
    
  •        logger.debug('deepmerge: replace a "%s"  w/ b "%s"' % (a, b,))
    
  •        a = b
    
  •    elif isinstance(a, dict):
    
  •        if isinstance(b, dict):
    
  •            logger.debug('deepmerge: dict ... "%s" and "%s"' % (a, b,))
    
  •            for k in b:
    
  •                if k in a:
    
  •                    logger.debug('deepmerge dict: loop for key "%s": "%s" and "%s"' % (k, a[k], b[k],))
    
  •                    a[k] = self._deepmerge(a[k], b[k])
    
  •                else:
    
  •                    logger.debug('deepmerge dict: set key %s' % k)
    
  •                    a[k] = b[k]
    
  •        elif isinstance(b, listTypes):
    
  •            logger.debug('deepmerge: dict <- list ... "%s" <- "%s"' % (a, b,))
    
  •            for bd in b:
    
  •                if isinstance(bd, dict):
    
  •                    a = self._deepmerge(a, bd)
    
  •                else:
    
  •                    raise HiYaPyCoImplementationException(
    
  •                        'can not merge element from list of type %s to dict (@ "%s" try to merge "%s")' %
    
  •                        (type(b), a, b,)
    
  •                    )
    
  •        else:
    
  •            raise HiYaPyCoImplementationException(
    
  •                'can not merge %s to %s (@ "%s" try to merge "%s")' %
    
  •                (type(b), type(a), a, b,)
    
  •            )
    
  •    logger.debug('end deepmerge part: return: "%s"' % a)
    
  •    logger.debug('<' * 30)
    
  •    return a
    

    def _deepmerge(self, a, b):
    logger.debug('>'*30)
    @@ -436,8 +484,8 @@

    args: YAMLfile(s)
    kwargs:

  •  * method: one of hiyapyco.METHOD_SIMPLE | hiyapyco.METHOD_MERGE
    
  •  * mergelists: boolean (default: True) try to merge lists
    
  •  * method: one of hiyapyco.METHOD_SIMPLE | hiyapyco.METHOD_MERGE | hiyapyco.METHOD_SUBSTITUTE
    
  •  * mergelists: boolean (default: True) try to merge lists (only makes sense if hiyapyco.METHOD_MERGE or hiyapyco.METHOD_SUBSTITUTE)
     * interpolate: boolean (default: False)
     * castinterpolated: boolean (default: False) try to cast values after interpolating
     * usedefaultyamlloader: boolean (default: False)
    

from hiyapyco.

alex-ber avatar alex-ber commented on June 28, 2024

My comment above is proposed patch. Sorry for formatting issues.

from hiyapyco.

zerwes avatar zerwes commented on June 28, 2024

sorry, I need something usable.
can you please fork the repo and commit your proposes changes into the fork?
and maybe you can even create a pull request then ...
Greetings

from hiyapyco.

alex-ber avatar alex-ber commented on June 28, 2024

patch.txt

You should be more clear about this. Uploading patch as attachment.

from hiyapyco.

alex-ber avatar alex-ber commented on June 28, 2024

Please, see #37

from hiyapyco.

zerwes avatar zerwes commented on June 28, 2024

PR #37 merged
released 0.4.16

from hiyapyco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.