Comments (3)
The merge_configs()
method is merging the top config into the base confiig and returning the latter.
RFC: for #95 and #105: how about using deepcopy
in with_fallback
? Smoke testing the gist above and #95 are working.
I'll leave this comment for a while before a PR.
import copy
#### way down
def with_fallback(self, config):
"""
return a new config with fallback on config
:param config: config or filename of the config to fallback on
:return: new config with fallback on config
"""
if isinstance(config, ConfigTree):
config = copy.deepcopy(config)
result = ConfigTree.merge_configs(config, copy.deepcopy(self))
else:
from . import ConfigFactory
result = ConfigTree.merge_configs(ConfigFactory.parse_file(config, resolve=False), copy.deepcopy(self))
from . import ConfigParser
ConfigParser.resolve_substitutions(result)
return result
from pyhocon.
Smoketest #105:
>>> from pyhocon.config_tree import ConfigTree as CT
>>> config_tree = CT()
>>>
>>> config_tree.put("a.b.c", value1)
>>> assert config_tree.get("a.b.c") == value1
>>>
>>> config_tree.put("a.b.c", value2)
>>> assert config_tree.get("a.b.c") == value2
>>>
>>> config_tree.put("a.b.c", value3, True)
>>> assert config_tree.get("a.b.c") == (value2 + value3)
>>>
from pyhocon.
Return a new object; don't mutate object and argument in config2.with_fallback(config1)
Smoketest #95:
>>>
>>> from pyhocon.config_parser import ConfigParser as CP, ConfigFactory as CF
>>>
>>> config1 = CF.parse_string('''
... string = abc
... ''')
>>>
>>> config2 = CF.parse_string('''
... string = ${string}def
... ''', resolve=False)
>>>
>>> ret = config2.with_fallback(config1)
>>> ret
ConfigTree([('string', 'abcdef')])
>>> config1
ConfigTree([('string', 'abc')])
>>> config2
ConfigTree([('string', [ConfigValues: [ConfigSubstitution: string],def])])
>>>
>>> ret is config2
False
>>> ret is config1
False
>>>
from pyhocon.
Related Issues (20)
- substitution resulting in cycle in pyhocon==0.3.60 (works in 0.3.59)
- Parsing bug when key start with months prefix with pyparsing>=3.0.0
- Extending Configuration replaces previous values HOT 1
- Version 0.3.60 breaks setting default arguments in some cases
- Cannot resolve reference to nested variable
- BUG/DEPS: tests fail for pyparsing>3
- Merge updates back to main branch
- breaking change in 0.3.60 HOT 2
- Incorrect parsing of quoted keys
- Assignment of variables with underscore in their name causes pyparsing exception HOT 4
- Chained substitution problem
- Optional substitution from included config not working
- Multiline += operations are not supported?
- Broken parsing validation on double commas within arrays
- PyHOCON to support python3.11 HOT 1
- Nested config resolving broken with 0.3.60 HOT 1
- Substitution fails for nested sections
- Chained duplicate overrides return incorrect value of "None"
- Issue parsing HOCON with newline HOT 6
- Fails to interpret escaped double quote
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyhocon.