Skip to content
This repository was archived by the owner on May 22, 2026. It is now read-only.

[Package mode] add new flag --package-mode - #1154

Merged
iscai-msft merged 32 commits into
Azure:autorestv3from
msyyc:package-mode
Mar 8, 2022
Merged

[Package mode] add new flag --package-mode#1154
iscai-msft merged 32 commits into
Azure:autorestv3from
msyyc:package-mode

Conversation

@msyyc

@msyyc msyyc commented Feb 15, 2022

Copy link
Copy Markdown
Member

@msyyc
msyyc marked this pull request as ready for review February 15, 2022 06:59
@msyyc
msyyc requested a review from iscai-msft February 15, 2022 06:59
Comment thread autorest/codegen/__init__.py Outdated
Comment thread autorest/codegen/serializers/__init__.py Outdated
Comment thread autorest/codegen/serializers/__init__.py Outdated
Comment thread autorest/codegen/templates/templates_package/CHANGELOG.md.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/MANIFEST.in.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/setup.py.jinja2
Comment thread autorest/codegen/templates/templates_package/setup.py.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/setup.py.jinja2
Comment thread autorest/codegen/templates/templates_package/setup.py.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/setup.py.jinja2 Outdated
@iscai-msft

Copy link
Copy Markdown
Member

overall looks much better, thank you @msyyc!

Comment thread autorest/codegen/templates/templates_package/README.md.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/README.md.jinja2
Comment thread autorest/codegen/templates/templates_package/README.md.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/README.md.jinja2 Outdated
Comment thread autorest/codegen/serializers/__init__.py Outdated
Comment thread autorest/codegen/templates/templates_package/CHANGELOG.md.jinja2 Outdated
Comment thread autorest/codegen/templates/templates_package/setup.py.jinja2
Comment thread docs/samples/specification/management/generated/setup.py Outdated
Comment thread autorest/codegen/__init__.py
Comment thread autorest/codegen/__init__.py Outdated
Comment thread autorest/codegen/serializers/__init__.py Outdated
Comment thread autorest/codegen/templates/dev_requirements.txt.jinja2
Comment thread autorest/codegen/templates/setup.py.jinja2 Outdated
Comment thread autorest/codegen/templates/setup.py.jinja2 Outdated
Comment thread autorest/codegen/templates/MANIFEST.in.jinja2 Outdated
Comment thread autorest/codegen/templates/dev_requirements.txt.jinja2
Comment thread autorest/codegen/templates/setup.py.jinja2 Outdated
Comment thread autorest/codegen/templates/setup.py.jinja2
Comment thread test/azure/legacy/Expected/AcceptanceTests/PackageModeCustomize/template.txt Outdated
Comment thread autorest/codegen/serializers/__init__.py Outdated
@msyyc

msyyc commented Feb 28, 2022

Copy link
Copy Markdown
Member Author

@iscai-msft
(1) I think we could disable py27 CI check now that we have not supported it yet.
(2) azure-report.json is deleted in latest autorest.testserver: https://github.com/Azure/autorest.testserver/pull/358/files. We need a pr to fix it:

'AzureReport': 'azure-report.json',

@msyyc msyyc mentioned this pull request Mar 2, 2022
@msyyc
msyyc requested a review from changlong-liu as a code owner March 3, 2022 03:02

@iscai-msft iscai-msft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def getting closer @lmazuel can you take a look, left some comments ccing you. Thanks!

Comment thread autorest/codegen/__init__.py Outdated
"If you want operation files, pass in flag --show-operations"
)

if options["package_mode"] not in ("mgmtplane", "dataplane", None) and not Path(options["package_mode"]).exists():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it just be not in ("mgmtplane", "dataplane")? Not sure why None is a valid entry

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path(None).exist() will raise exception so we have to avoid that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really do None checks for any other flag, it's still a little weird because it looks like we're making None a valid entry (by including it with mgmtplane and dataplane)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could check None first and it will make the logic more clear

for template_name in package_files:
file = template_name.replace(".jinja2", "")
output_name = out_path / file
if not self._autorestapi.read_file(output_name) or file == 'setup.py':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay looks good, just want to confirm with @lmazuel : are you good with us not overriding any of the files except setup.py during regeneration? This way if, for example, users update the README, we won't override when regenerating

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should override the MANIFEST as well (though it's unlikely it changes, this should not be changed manually by anyone)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it and will make a override-list. Now it contains 'setup.py' and 'MAINFEST.in'

Comment thread autorest/codegen/templates/CHANGELOG.md.jinja2
# {{ package_pprint_name }} client library for Python
<!-- write necessary description of service -->

## _Disclaimer_

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove the disclaimer, we've already droppd support for 2.7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it's fair to remove it we're in March already

@msyyc msyyc Mar 4, 2022

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it

### Installating the package

```bash
python -m pip install {{ package_name }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally just do pip install {{ package_name }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's debatable, we saw people confused because they had several Python installed, and python and pip were not referencing the same python interpreter. I would suggest to talk about venv instead, since this is a more efficient to ensure consistency between python and pip

Comment thread docs/samples/specification/management/generated/setup.py

def __init__(self, *, status: Optional[Union[str, "OperationResultStatus"]] = None, **kwargs):
"""
:keyword status: The status of the request. Possible values include: "Succeeded", "Failed",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also run at least one acceptance test on each package mode package? This way we can know if the package can be run. So for this package, you can run a paging test, and so on and so forth for the other two package mode packages

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test:
test_packagemode.py for dataplane,
test_package_mode_mgmt.py for mgmtplane,
test_package_mode_customize.py for customize


```yaml $(package-mode)
package-configuration:
min_python_version: 3.6

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it's a little weird that this test includes package_name as an entry in the custom template, since we already have flag --package-name, maybe we could switch the packge_name customization to a classifier customization or something

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed.

Comment thread test/azure/legacy/specification/packagemodecustomize/template/setup.py Outdated
Comment thread test/azure/legacy/specification/packagemodemgmtplane/README.md
Comment thread autorest/codegen/templates/setup.py.jinja2 Outdated
Comment thread autorest/codegen/templates/setup.py.jinja2 Outdated

@iscai-msft iscai-msft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i think with the following comments, we should be good to merge!

Comment thread autorest/codegen/__init__.py Outdated
"If you want operation files, pass in flag --show-operations"
)

if options["package_mode"] not in ("mgmtplane", "dataplane", None) and not Path(options["package_mode"]).exists():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really do None checks for any other flag, it's still a little weird because it looks like we're making None a valid entry (by including it with mgmtplane and dataplane)

{% set author_email = "azpysdkhelp@microsoft.com" %}
{% set url = "https://github.com/Azure/azure-sdk-for-python/tree/main/sdk" %}
{% else %}
version = "{{ code_model.options.get('package_version', '0.0.0') }}"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @msyyc. with that check thought, we don't have to set a default value when we get package_version from options. I think you set default value here and at least one more place, so can you change those just to code_model.options["package_version"]?

Comment thread autorest/codegen/templates/setup.py.jinja2


PACKAGE_NAME = "{{ package_name }}"
PACKAGE_NAME = "azure-packagemode-customize"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be setup.py.jinja2 because it's formatted as a jinja template. Endings without .jinja2 means "keep as is" inside the custom package-mode folder, so we should be able to handle both

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be setup.py.jinja2 because it's formatted as a jinja template. Endings without .jinja2 means "keep as is" inside the custom package-mode folder, so we should be able to handle both

sure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments are same with up and they are resolved

Comment thread autorest/codegen/__init__.py
file = template_name.replace(".jinja2", "")
output_name = out_path / file
if not self._autorestapi.read_file(output_name) or file == 'setup.py':
if not self._autorestapi.read_file(output_name) or file in _REGENERATE_FILES:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm: if a user passes any template / file inside --package-mode=my-custom-folder/, that will override any of the templates we have in autorest?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user passes folder, autorest will use those files instead of built-in template files. This logic is to permit to override specific files when rerun autorest.

@iscai-msft iscai-msft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay looks great @msyyc!

Want to thank you again for dealing with all of the comments and your patience, going to go ahead and merge!

@iscai-msft
iscai-msft merged commit c151a1e into Azure:autorestv3 Mar 8, 2022
@msyyc
msyyc deleted the package-mode branch March 9, 2022 00:07
iscai-msft added a commit that referenced this pull request Mar 9, 2022
…into inherit_customization

* 'autorestv3' of https://github.com/Azure/autorest.python:
  dpg service-driven-test (#1180)
  prepare for release (#1181)
  [Package mode] add new flag `--package-mode` (#1154)
  hide operation group docs (#1179)
iscai-msft added a commit that referenced this pull request Mar 10, 2022
…into mypy_code

* 'autorestv3' of https://github.com/Azure/autorest.python: (26 commits)
  dpg service-driven-test (#1180)
  prepare for release (#1181)
  [Package mode] add new flag `--package-mode` (#1154)
  hide operation group docs (#1179)
  add coverage var (#1178)
  improve logging (#1177)
  don't reformat query params for dpg next link calls (#1168)
  Update package.json
  Update ChangeLog.md
  default optional const parameter to none (#1171)
  add storage to ci checks (#1176)
  fail on regeneration diff (#1173)
  Drop Python 2.7 (#1175)
  Add secrets test (#1174)
  bump testserver version (#1172)
  make content type keyword only if multiple (#1167)
  add default value info for params to docs (#1164)
  update release tests to hopefully get coverage report green (#1152)
  fix windows: clean the outputFolderUri  (#1135)
  Update CODEOWNERS
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants