-
Notifications
You must be signed in to change notification settings - Fork 57
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
add --package-mode
for new service to package
#1112
Conversation
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.
i think the scope of this PR is too big, really all we want to tackle right now is to add the different setup.pys that @lmazuel mentioned in his issue
not all([options["package_name"], options["client_name"], options["credential_scopes"], | ||
options["package_pprint_name"], options["output_folder"], options["input_file"]]): | ||
raise ValueError( | ||
"--package-name, --title, --package-pprint-name, --credential-scopes, --output-folder" |
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.
I don't think all of these flags need to be required for package-mode to work. For example, at least for title, we can get the value from the client name
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.
Indeed, most of those flags will be required anyway, and we should get the values from the codemodel, once they are solved and resolved. For instance, the codemodel will always have a title.
For options that are not necessary today to generate, see that I did a proposal in the initial issue, and it was not to add new flags.
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.
Hi @lmazuel @iscai-msft, when people want to generate a shippable package, these flags(package_name, output_folder, etc) are necessary in swagger/readme.md. Rather than that let users configure readme.md then generate package with the configuration, I think it is more convenient to do that with one step: force users to input necessary flags with 'package-mode`. After generation, users could get shippable package directly. It may be a little different with #1053, but it shall be convenient for users, too.
title
: although it is usually defined in swagger, but most of it is invalid for SDK like this. So I think it is better to let users input for confirmation.
I try to let users input less parameters as soon as possible, now they only need 6.
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.
@msyyc I'm kind of confused, wouldn't people be running --package-mode
with generation, so there's no need to add duplicate flags explicitly for pakcage mode?
For example, --title
shouldn't be required because that's a flag to override the client name in the swagger. Don't we want the package name's client to be the same as the generated client's name? So i don't get why you want to require --title
for package mode. Honestly the only flag I think we may need to do a check on is --package-pprint-name
, and I'm not sure we even have to require this flag, we could default to the client name if the flag is not specified
@@ -289,6 +304,12 @@ def _build_code_model_options(self) -> Dict[str, Any]: | |||
"low_level_client": low_level_client, | |||
"combine_operation_files": self._autorestapi.get_boolean_value("combine-operation-files", version_tolerant), | |||
"python3_only": python3_only, | |||
"package_mode": self._autorestapi.get_value("package-mode"), |
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.
Some of these are already in the options dict / can be get other ways. For example. client_name, credential_scopes, output_folder, and input_file
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.
Those parameters is to render template for package-mode
. I don't see where I could get them except in options.
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.
@msyyc, we already have informnation for all of the flags you've added here, besides package-pprint-name, this is doubling code for no real reason. If you go through the code here you can see how we're already storing this information on the code model (not necessarily just in options)
@@ -306,8 +327,16 @@ def _build_code_model_options(self) -> Dict[str, Any]: | |||
if azure_arm: | |||
options["credential"] = True | |||
options["head_as_boolean"] = True | |||
|
|||
if options["package_mode"] == 'dataplane': |
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.
I don't think adding these options is in the scope of this PR, not sure all of these should default to these values as well
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.
Correct, the scope of the PR is templating, not changing behavior
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.
The changing behavior is necessary to generate a whole package: package-mode
only asks users to input limited parameter. So it is necessary to help configure some other parameters.
For example, codegen asks to input --credential
if users want to use --credential-scopes
. For convenience, we want users to input limited parameters. So package-mode
only asks to input --credential-scopes
. Then we have to help to replenish options["credential"] = True
] | ||
), | ||
install_requires=[ | ||
"azure-core<2.0.0,>=1.20.1", |
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.
since we're setting minversions in multiple setup.py, we should have one common area for min versions
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.
each mode has its own dependency so I think it is better to put them solely. And we could update the template when new autorest.python
is released if necessary.
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.
The only realy diff in mode dependency is --azure-arm
requires azure-mgmt-core, whil dataplane does not. We should really share dependency requirements for evyerthing else
Hi @iscai-msft , This PR is part of |
@@ -76,6 +76,21 @@ def _validate_code_model_options(options: Dict[str, Any]) -> None: | |||
"If you want operation files, pass in flag --show-operations" | |||
) | |||
|
|||
if options["package_mode"] == 'dataplane' and \ |
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.
The value "dataplane" should not be hardcoded, we should have a map of value to folder, and the template folder should be part of the autorest delivery
For instance, the folder autorest/codegen/packaging_template/dataplane
contains the dataplane
template, and the folder autorest/codegen/packaging_template/abcxyz
will contain the template abcxyz
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.
autorest/codegen/__init__.py
Outdated
@@ -134,7 +149,7 @@ def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union | |||
code_model.setup_client_input_parameters(yaml_data) | |||
|
|||
# Get my namespace | |||
namespace = self._autorestapi.get_value("namespace") | |||
namespace = code_model.options.get("namespace", self._autorestapi.get_value("namespace")) |
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.
@iscai-msft why would there be a namesapce in the code_model.options?
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.
yeah you're right there isn't any, @msyyc I don't think we need to change the code here
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.
namesapce
in the code_model.options
is needed to render template for package-mode
. Please see here: https://github.com/Azure/autorest.python/pull/1112/files#r794987407
@@ -134,7 +149,10 @@ def _create_code_model(self, yaml_data: Dict[str, Any], options: Dict[str, Union | |||
code_model.setup_client_input_parameters(yaml_data) | |||
|
|||
# Get my namespace | |||
namespace = self._autorestapi.get_value("namespace") | |||
if not code_model.options.get("package_mode"): |
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.
i don't think we should change this code, we really want package mode to be as similar to generation flags as possible, I don't think it helps the users to have these slightly different flags for generation and package mode
@@ -0,0 +1,6 @@ | |||
# Release History |
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.
I think pretty much all of the files you've put down as specific to dataplane package mode can be shared across different packaging modes. All of the differences between --azure-arm
and dataplane can be easily resolved in one file: we don't need duplicate templates for each different packaging mode. Not as important, but. wealso really don't need a separate folder for templates_package_dataplane
either
- You need an [Azure subscription][azure_sub] to use this package. | ||
- An existing {{ package_pprint_name }} instance. | ||
|
||
#### Create with an Azure Active Directory Credential |
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.
you can't be sure the package uses AAD, you can look at the credential scope policy property / other credential properties on the code model to see what kind of credentials we use
-e ../../../tools/azure-devtools | ||
-e ../../../tools/azure-sdk-tools | ||
../../core/azure-core | ||
../../identity/azure-identity |
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 don't know if we need identity. Also we don't need to do 3.x checks anymore, I think by the time we merge this pr, we will have dropped 2.x support in autorest
{% for file in code_model.options['input_file'] -%} | ||
- {{ file }} | ||
{% endfor -%} | ||
output-folder: {{ '../' + code_model.options["package_name"].replace('-', '/') }} |
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.
I don't think we need to generate a swagger readme file as part of packaging... aren't they running the package mode from a config file already?
After sync, will create another PR for this feature: #1154 |
#1053
try the following cmd:
(powershell)
(linux)