Skip to content
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

Update dpg version #24986

Merged
merged 3 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions scripts/quickstart_tooling_dpg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
from jinja2 import Environment, FileSystemLoader
from subprocess import check_call
import time
from typing import Any
import json

Expand Down Expand Up @@ -69,7 +68,7 @@ def generate_swagger_readme(work_path: str, env: Environment, **kwargs: Any) ->
os.makedirs(swagger_path)

# render file
template = env.get_template('swagger_README.md')
template = env.get_template('README.md')
result = template.render(**kwargs)
swagger_readme = swagger_path / Path('README.md')
with open(swagger_readme, 'w') as fd:
Expand All @@ -88,16 +87,9 @@ def build_package(**kwargs) -> None:
# prepare template render parameters
output_folder = kwargs.get("output_folder")
package_name = kwargs.get("package_name")
swagger_readme_output = '../' + package_name.replace('-', '/')
kwargs['swagger_readme_output'] = swagger_readme_output
namespace = package_name.replace('-', '.')
kwargs['namespace'] = namespace
kwargs['date'] = time.strftime('%Y-%m-%d', time.localtime())
folder_list = package_name.split('-')
kwargs['folder_first'] = folder_list[0]
kwargs['folder_second'] = folder_list[1]
kwargs['folder_parent'] = Path(output_folder).parts[-2]
kwargs['test_prefix'] = folder_list[-1]
kwargs['test_prefix'] = package_name.split('-')[-1]

_LOGGER.info("Build start: %s", package_name)
check_parameters(output_folder)
Expand All @@ -114,24 +106,9 @@ def build_package(**kwargs) -> None:
_LOGGER.info(f"generate SDK code with autorest: {autorest_cmd}")
check_call(autorest_cmd, shell=True)

# generate necessary file(setup.py, CHANGELOG.md, etc)
work_path = Path(output_folder)
for template_name in env.list_templates():
_LOGGER.info(f"generate necessary file: {template_name}")
template = env.get_template(template_name)
result = template.render(**kwargs)
# __init__.py is a weird one
if template_name == "__init__.py":
split_package_name = package_name.split("-")[:-1]
for i in range(len(split_package_name)):
init_path = work_path.joinpath(*split_package_name[: i + 1], template_name)
with open(init_path, "w") as fd:
fd.write(result)
elif template_name != 'swagger_README.md':
with open(work_path / template_name, "w") as fd:
fd.write(result)

# generate test framework
work_path = Path(output_folder)
generate_test_sample(_TEMPLATE_TESTS, work_path / Path('tests'), **kwargs)

# generate sample framework
Expand Down
6 changes: 0 additions & 6 deletions scripts/quickstart_tooling_dpg/template/CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/quickstart_tooling_dpg/template/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/quickstart_tooling_dpg/template/MANIFEST.in

This file was deleted.

105 changes: 19 additions & 86 deletions scripts/quickstart_tooling_dpg/template/README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,20 @@
# {{ package_pprint_name }} client library for Python
<!-- write necessary description of service -->

## _Disclaimer_

_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please
refer to https://github.com/Azure/azure-sdk-for-python/issues/20691_

## Getting started

### Installating the package

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

#### Prequisites

- Python 3.6 or later is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing {{ package_pprint_name }} instance.

#### Create with an Azure Active Directory Credential
To use an [Azure Active Directory (AAD) token credential][authenticate_with_token],
provide an instance of the desired credential type obtained from the
[azure-identity][azure_identity_credentials] library.

To authenticate with AAD, you must first [pip][pip] install [`azure-identity`][azure_identity_pip]

After setup, you can choose which type of [credential][azure_identity_credentials] from azure.identity to use.
As an example, [DefaultAzureCredential][default_azure_credential] can be used to authenticate the client:

Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`

Use the returned token credential to authenticate the client:

```python
>>> from {{ namespace }} import {{ client_name }}
>>> from azure.identity import DefaultAzureCredential
>>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
### Settings

```yaml
input-file: {{ input_file }}
output-folder: ../
namespace: {{ namespace }}
package-name: {{ package_name }}
license-header: MICROSOFT_MIT_NO_VERSION
title: {{ client_name }}
package-version: 1.0.0b1
package-mode: dataplane
package-pprint-name: {{ package_pprint_name }}
{%- if security_scope %}
security: AADToken
security-scopes: {{ security_scope }}
{%- elif security_header_name %}
security: AzureKey
security-header-name: {{ security_header_name }}
{%- endif %}
```

## Examples

```python
>>> from {{ namespace }} import {{ client_name }}
>>> from azure.identity import DefaultAzureCredential
>>> from azure.core.exceptions import HttpResponseError

>>> client = {{ client_name }}(endpoint='<endpoint>', credential=DefaultAzureCredential())
>>> try:
<!-- wirte test code here -->
except HttpResponseError as e:
print('service responds error: {}'.format(e.response.json()))

```

## Next steps

More examples are coming soon...

## Contributing

This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution.
For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only
need to do this once across all repos using our CLA.

This project has adopted the
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact [email protected] with any
additional questions or comments.

<!-- LINKS -->
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
[azure_identity_pip]: https://pypi.org/project/azure-identity/
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
[pip]: https://pypi.org/project/pip/
[azure_sub]: https://azure.microsoft.com/free/
1 change: 0 additions & 1 deletion scripts/quickstart_tooling_dpg/template/__init__.py

This file was deleted.

7 changes: 0 additions & 7 deletions scripts/quickstart_tooling_dpg/template/dev_requirements.txt

This file was deleted.

67 changes: 0 additions & 67 deletions scripts/quickstart_tooling_dpg/template/setup.py

This file was deleted.

21 changes: 0 additions & 21 deletions scripts/quickstart_tooling_dpg/template/swagger_README.md

This file was deleted.

2 changes: 1 addition & 1 deletion swagger_to_sdk_config_dpg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"meta": {
"autorest_options": {
"version": "3.8.1",
"use": ["@autorest/python@5.19.0", "@autorest/[email protected]"],
"use": ["@autorest/python@6.0.0", "@autorest/[email protected]"],
"python": "",
"sdkrel:python-sdks-folder": "./sdk/.",
"version-tolerant": ""
Expand Down