-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{Core} Fix #24542: Support JMESPath Community dependencies and assets. #25590
base: dev
Are you sure you want to change the base?
Conversation
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
Thank you for your contribution springcomp! We will review the pull request and get back to you soon. |
JMESPath Community |
Thank you very much @springcomp for the notification and great work. Because of the ever-increasing usage of Azure CLI, we are focusing more and more on maintaining a stable and consistent user experience. https://jmespath.site/main/#libraries mentions the Python version of However, due to other high priority tasks, this has not been planned yet. We will discuss this PR with our Product Managers and see how we should move on. For now, instructing users to use |
@jiasli Thank you for your honest feedback. You are right, JMESPath Community is not fully compliant. I have made efforts to make sure compatibility is preserved as much as is possible. The unit-tests in AZ CLI are all working fine with the compatibility switch. However, there are still a couple of opinionated differences with the original implementation 😏. For the sake of transparency, these are tracked here: Instructing users to us jp might be a good interim solution. Thank you for your time. |
src/azure-cli/azure/cli/command_modules/batch/tests/latest/recordings/cli-3.1.11.help.txt
Outdated
Show resolved
Hide resolved
@@ -2262,7 +2262,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
|
|||
--------------------------------------------------------- | |||
|
|||
jmespath 0.10.0 - MIT | |||
jmespath-community 1.1.0 - MIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the copyright of jmespath-community
still belong to Amazon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have forked the repository, so I’m not sure what is the best practice.
Also, I’m not familiar at all with respect to licenses and copyright 😱.
What do you think in your experience ?
Related Command
As this PR addresses the JMESPath language used in the
--query
command-line argument, it applies to all az CLI commands 😱.Description
This PR addresses #24542 by updating the current dependency on the JMESPath language used in the
--query
command-line argument.Testing Guide
az CLI uses the JMESPath language to power its
--query
command-line argument.For instance, consider the following current behaviour:
az storage account list --query "[].{location: location, name:name}"
:Here is a new query that can be performed using JMESPath Community:
az storage account list \ --query "group_by([].{loc: location, n:name}, &loc).*.let( {key: [0].loc, values: [*].n}, &{key: key, values: values})|from_items(zip([*].key, [*].values))"
with the corresponding result:
While there is definitely a learning curve to JMESPath, this example features most of the improvements we’ve made to the specification.
The full expression can be broken down into chunks:
group_by([].{loc: location, n: name}, &loc)
: creates a new hash with the subset of interestinglocation
andname
properties from the original object. It uses the newgroup_by()
function to split the result by location..*
: is a value projection to create an array that can be iterated upon subsequently.let( {key: [0].loc, values: [*].n}, &{key:key, values:values})
: expression that is evaluated for each item in the projected array. It uses the newlet()
function to take advantage of lexical scoping.key
andvalues
properties that contain the value of theloc
property from the first array entry – as all entries contain the same location at this stage – and the list of names respectively.|
: the pipe stops the projection so that later expressions operate on the full array instead of being evaluated iteratively on each array element.from_items(zip([*].key, [*].values))
: creates the expected result.zip()
function to combine the list ofkey
elements and thevalues
arrays into a single entity.from_items()
functions to combine those two lists – like for like – to produce the resulting object shown above.Overview
This PR is a draft as I would like to make the most effort to help include an updated JMESPath language with an improved feature set to az CLI. However, I’m not sure what would be the reasonable changes to do or if it should be broken into multiple pull requests. I would also likely need guidance over how to best fill the PR description template.
This PR makes the following changes:
jmespath.org
original web site to the newjmespath.site
.jmespath
Python package to the newjmespath-community
Python package.jmespath-terminal
(jpterm
helper) Python CLI tool to the newjmespath-community-terminal
tool in Docker images.github.com/jmespath/jp
CLI tool by the newgithub.com/jmespath-community/jp
CLI tool in Docker images.3.7.16
for some Docker image.I’m not sure if all the documentation pages must be updated though.
JMESPath Community
This PR aims to include JMESPath Community assets into az CLI.
JMESPath Community is a new initiative to bring improvements to and steward the specification going forward,
as the language and its tools no longer appear to be maintained. As its first milestone,
JMESPath Community includes the following improvements to the original specification:
JMESPath Community also aims to be an umbrella for specific programming language implementations. It currently hosts the following 100% compliant implementations:
I’m also the co-author of the JMESPath.Net implementation 🤐.
For the purpose of az CLI, JMESPath Community can be configured to maintain backwards compatibility with the original
jmespath
Python package. This PR adds the necessaryenable_legacy_literals=True
flag in various places to prevent breaking existing syntax and scripts. Incidentally, I think the usage of JMESPath’sOptions
parameter is a bit too scattered in various places and could gain from being more centralized. I will think of a PR for that in the future.The various built-in Docker images re-introduce
jpterm
which has seen its dependencies updated and no longer breaks the CI.The accompanying
jp
executable has also been brought up to standards and is included in this PR.This checklist is used to make sure that common guidelines for a pull request are followed.