Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
Template
Commits
00a42412
Commit
00a42412
authored
8 years ago
by
nimrod
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/jmespath'
parents
b0817717
256a1439
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.rst
+2
-1
2 additions, 1 deletion
README.rst
setup.py
+1
-1
1 addition, 1 deletion
setup.py
template/filters.py
+24
-1
24 additions, 1 deletion
template/filters.py
tox.ini
+2
-1
2 additions, 1 deletion
tox.ini
with
29 additions
and
4 deletions
README.rst
+
2
−
1
View file @
00a42412
...
...
@@ -45,6 +45,8 @@ The following Jinja filters were added:
- :code:`from_json`: Convert from json.
- :code:`pprint`: Pretty print variable.
- :code:`combine`: Combine 2 dictionaries.
- :code:`jmespath`: Queries data using the `JMESPath <http://jmespath.org/>`_
query language.
Example usage can be seen in :code:`tests.sh` and for specific filters in the
docstrings in :code:`template/filters.py`.
...
...
@@ -85,5 +87,4 @@ TODO
- Release on tagged commits to PyPI in Travis CI
(https://docs.travis-ci.com/user/deployment/pypi/ and
https://docs.travis-ci.com/user/encryption-keys/).
- Add JMESPath support.
- Add TOML support?
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
00a42412
...
...
@@ -21,7 +21,7 @@ setup(
],
keywords
=
'
config configuration jinja template environment
'
,
packages
=
find_packages
(),
install_requires
=
[
'
Jinja2
'
,
'
PyYAML
'
,
'
six
'
],
install_requires
=
[
'
Jinja2
'
,
'
PyYAML
'
,
'
jmespath
'
],
extras_require
=
{
'
dev
'
:
[
'
tox
'
],
},
entry_points
=
{
...
...
This diff is collapsed.
Click to expand it.
template/filters.py
+
24
−
1
View file @
00a42412
#!/usr/bin/env python
from
__future__
import
(
absolute_import
,
division
,
print_function
,
unicode_literals
)
import
six
# noqa: F401
def
to_yaml
(
value
):
...
...
@@ -45,6 +44,7 @@ def from_json(value):
Returns native data structure from the given JSON string.
Examples:
>>>
import
six
>>>
from_json
(
'
[1, 2, 3]
'
)
[
1
,
2
,
3
]
>>>
from_json
(
'"
a
"'
)
==
six
.
text_type
(
'
a
'
)
...
...
@@ -78,6 +78,7 @@ def pprint(value):
Examples:
>>>
pprint
(
1
)
'
1
'
>>>
import
six
>>>
output
=
pprint
([{
'
first_name
'
:
'
John
'
,
'
last_name
'
:
'
Doe
'
},
{
'
first_name
'
:
'
Jane
'
,
'
last_name
'
:
'
Doe
'
}])
# noqa: E501
>>>
if
six
.
PY3
:
...
output
==
"
[{
'
first_name
'
:
'
John
'
,
'
last_name
'
:
'
Doe
'
},
\\
n {
'
first_name
'
:
'
Jane
'
,
'
last_name
'
:
'
Doe
'
}]
"
...
...
@@ -101,3 +102,25 @@ def combine(default, override):
combined
=
default
.
copy
()
combined
.
update
(
override
)
return
combined
def
jmespath
(
value
,
query
):
'''
Queries the data using the JMESPath query language.
Examples:
>>>
import
six
>>>
locations
=
[{
'
name
'
:
'
Seattle
'
,
'
state
'
:
'
WA
'
},
...
{
"
name
"
:
"
New York
"
,
"
state
"
:
"
NY
"
},
...
{
"
name
"
:
"
Bellevue
"
,
"
state
"
:
"
WA
"
},
...
{
"
name
"
:
"
Olympia
"
,
"
state
"
:
"
WA
"
}]
>>>
query
=
"
[?state ==
'
WA
'
].name | sort(@) | {WashingtonCities: join(
'
,
'
, @)}
"
# noqa: E501
>>>
WACities
=
jmespath
(
locations
,
query
)
>>>
if
six
.
PY2
:
...
WACities
==
{
u
'
WashingtonCities
'
:
u
'
Bellevue, Olympia, Seattle
'
}
...
elif
six
.
PY3
:
...
WACities
==
{
'
WashingtonCities
'
:
'
Bellevue, Olympia, Seattle
'
}
...
True
'''
import
jmespath
return
jmespath
.
search
(
query
,
value
)
This diff is collapsed.
Click to expand it.
tox.ini
+
2
−
1
View file @
00a42412
[tox]
envlist
=
py{2,3}
envlist
=
py{2,3}
,docs
[travis]
python
=
...
...
@@ -17,6 +17,7 @@ deps =
check-manifest
readme_renderer
flake8
six
commands
=
check-manifest
--ignore
tox.ini,tests*
flake8
.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment