Skip to content

Commit

Permalink
Renamed read_context_data2() to read_context_data().
Browse files Browse the repository at this point in the history
Removed the obsolete implementation of read_context_data().
  • Loading branch information
m000 committed Nov 21, 2019
1 parent be66015 commit 29d6017
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
4 changes: 2 additions & 2 deletions j2cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import imp, inspect

from .context import FORMATS
from .context import parse_data_spec, read_context_data2, dict_update_deep
from .context import parse_data_spec, read_context_data, dict_update_deep
from .extras import filters
from .extras.customize import CustomizationModule

Expand Down Expand Up @@ -152,7 +152,7 @@ def render_command(argv):
customize = CustomizationModule(None)

# Read data based on specs
data = [read_context_data2(*dspec) for dspec in dspecs]
data = [read_context_data(*dspec) for dspec in dspecs]

# Squash data into a single context
context = reduce(dict_update_deep, data, {})
Expand Down
35 changes: 1 addition & 34 deletions j2cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def parse_data_spec(dspec, fallback_format='ini'):
### return ############################################
return (source, ctx_dst, fmt)

def read_context_data2(source, ctx_dst, fmt):
def read_context_data(source, ctx_dst, fmt):
""" Read context data into a dictionary
:param source: Source file to read from.
Use '-' for stdin, None to read environment (requires fmt == 'env'.)
Expand Down Expand Up @@ -300,36 +300,3 @@ def read_context_data2(source, ctx_dst, fmt):
else:
return {ctx_dst: context}

def read_context_data(format, f, environ, import_env=None):
""" Read context data into a dictionary
:param format: Data format
:type format: str
:param f: Data file stream, or None (for env)
:type f: file|None
:param import_env: Variable name, if any, that will contain environment variables of the template.
:type import_env: bool|None
:return: Dictionary with the context data
:rtype: dict
"""

# Special case: environment variables
if format == 'env' and f is None:
return _parse_env(environ)

# Read data string stream
data_string = f.read()

# Parse it
if format not in FORMATS:
raise ValueError('{0} format unavailable'.format(format))
context = FORMATS[format](data_string)

# Import environment
if import_env is not None:
if import_env == '':
context.update(environ)
else:
context[import_env] = environ

# Done
return context

0 comments on commit 29d6017

Please sign in to comment.