Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Fix import error too general other issues #797

Merged
merged 7 commits into from
Mar 25, 2021
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
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
    [b. Live Tests](#Live-Tests)
[4. Advanced Features](#Advanced-Features)
  [4.1. Folder Customization](#Folder-Customization)
  [4.2. CLI User Interface Customization](#CLI-User-Interface-Customization)
  [4.2. CLI User Interface Customization](#CLI-User-Interface-Customization)
    [a. Add Parent Extension](#Add-Parent-Extension)
    [b. Set Extension/Command Groups/Commands/Parameters Mode](#Set-Extension/Command-Groups/Commands/Parameters-Mode)
    [c. Set min-api/max-api in Command Groups/Commands/Parameters](#Set-min-api/max-api-in-Command-Groups/Commands/Parameters)
    [d. Move Command Groups/Command Layer](#Move-Command-Groups/Command-Layer)
    [e. Rename/Hide Command Groups/Commands/Parameters](#Rename/Hide-Command-Groups/Commands/Parameters)
    [f. Client Factory Customization](#Client-Factory-Customization)
    [g. Parameter Specific Customization](#Parameter-Specific-Customization)
    [b. Customize Extension Description](#Customize-Extension-Description)
    [c. Set Extension/Command Groups/Commands/Parameters Mode](#Set-Extension/Command-Groups/Commands/Parameters-Mode)
    [d. Set min-api/max-api in Command Groups/Commands/Parameters](#Set-min-api/max-api-in-Command-Groups/Commands/Parameters)
    [e. Move Command Groups/Command Layer](#Move-Command-Groups/Command-Layer)
    [f. Rename/Hide Command Groups/Commands/Parameters](#Rename/Hide-Command-Groups/Commands/Parameters)
    [g. Client Factory Customization](#Client-Factory-Customization)
    [h. Parameter Specific Customization](#Parameter-Specific-Customization)
      [i. flatten a parameter](#flatten-a-parameter)
      [ii. set a parameter as required](#set-a-parameter-as-required)
      [iii. set default value for a parameter](#set-default-value-for-a-parameter)
Expand Down Expand Up @@ -75,6 +76,8 @@ This *--sdk-flatten* option is still in private releases. It will only take effe
This *--generate-sdk* has two available value "yes" or "no". By default the value is "yes" for Azure CLI extensions generation, and "no" for Azure CLI main repo modules.
1. --compatible-level
This *--generate-sdk* has two available value "track1" or "track2". By default the value is "track2" for Azure CLI extensions generation, and "track1" for Azure CLI main repo modules.
1. --extension-mode
This *--extension-mode* option is to set the global extension mode for the generated modules. it has three available value 'experimental' or 'preview' or 'stable'. By default the value is 'experimental' for Azure CLI extensions generation. And 'stable' for Azure CLI main repo modules but the command groups mode will still be 'experimental' if not specified.
1. --target-mode
This *--target-mode* option is a convenience option for users who working on Azure CLI main repo modules. By default Autorest.az will generate code targeting azure-cli-extensions repo. Setting `--target-mode=core` if you want to generate azure-cli repo command modules. It basically equals to `--sdk-no-flatten --generate-sdk=no --compatible-level=track1`.

Expand Down Expand Up @@ -228,6 +231,12 @@ az:
parent-extension: monitor
```

### **Customize Extension Description**
Customers can customize what can be show when run `az -h` after their extension or module has been on-boarded to Azure CLI. By default, we will simply show RP name info in it.
```
extension-description: RP description.
```

### **Set Extension/Command Groups/Commands/Parameters Mode**
In Azure CLI, we allow user to set different mode like is_preview or is_experimental for different kinds of layers including extension/command groups/commands/parameters. We can configure it in readme.az.md so the generated code can work in different mode.
see [how to configure is_preview/is_experimental in different levels](https://github.com/Azure/autorest.az/blob/master/doc/faq.md#how-to-support-configuring-is_previewis_experimental-in-different-levels) for more details.
Expand Down
1 change: 0 additions & 1 deletion readme.az.common.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# configuration for az common

``` yaml $(az)
lirenhe marked this conversation as resolved.
Show resolved Hide resolved
extension-mode: experimental

# customize library used in extension. azure.cli.core by default
# cli-core-lib: azure.cli.core
Expand Down
16 changes: 11 additions & 5 deletions src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ export async function processRequest(host: Host) {
}

function processSimpleOption() {
// handling extension-mode by default it's experimental.
let extensionMode = ExtensionMode.Experimental;
extensionMode = AzConfiguration.getValue(CodeGenConstants.extensionMode) || extensionMode;
AzConfiguration.setValue(CodeGenConstants.extensionMode, extensionMode);

// handling default debug
if (isNullOrUndefined(AzConfiguration.getValue(CodeGenConstants.debug))) {
AzConfiguration.setValue(CodeGenConstants.debug, false);
Expand Down Expand Up @@ -134,6 +129,17 @@ function processGenerationOption(session: Session<CodeModel>) {
? AzConfiguration.getValue(CodeGenConstants.compatibleLevel)
: compatibleLevel;
const isTrack1 = compatibleLevel === CompatibleLevel.Track1;
session.message({
Channel: Channel.Information,
Text: 'NOTE: You are currently generating based on ' + compatibleLevel + ' SDK ',
});
// handling extension mode, if it's extension the default extension mode is experimental. if it's core, the default module mode is stable.
let extensionMode = ExtensionMode.Experimental;
if (cliCore) {
extensionMode = ExtensionMode.Stable;
}
extensionMode = AzConfiguration.getValue(CodeGenConstants.extensionMode) || extensionMode;
AzConfiguration.setValue(CodeGenConstants.extensionMode, extensionMode);
AzConfiguration.setValue(CodeGenConstants.isCliCore, cliCore);
AzConfiguration.setValue(CodeGenConstants.sdkNeeded, isSdkNeeded);
AzConfiguration.setValue(CodeGenConstants.sdkTrack1, isTrack1);
Expand Down
1 change: 1 addition & 0 deletions src/generate/CodeModelAz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface CodeModelAz {
azOutputFolder: string;
Extension_Name: string;
Extension_Parent: string;
Extension_Description: string;
Extension_NameUnderscored: string;
ConfiguredScenario: boolean;
Extension_NameClass: string;
Expand Down
14 changes: 14 additions & 0 deletions src/generate/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
DataGraph,
SortOrder,
CliCommandType,
ExtensionMode,
} from '../utils/models';
import {
CodeModelAz,
Expand Down Expand Up @@ -825,6 +826,16 @@ export class CodeModelCliImpl implements CodeModelAz {
return this.parentExtension;
}

public get Extension_Description(): string {
if (!isNullOrUndefined(AzConfiguration.getValue(CodeGenConstants.extensionDescription))) {
return 'Manage ' + AzConfiguration.getValue(CodeGenConstants.extensionDescription);
}
return (
'Manage ' +
ToSentence(this.Extension_NameClass.replace(/ManagementClient|Client/gi, ''))
);
}

public get Extension_Mode(): string {
let extensionMode = AzConfiguration.getValue(CodeGenConstants.extensionMode);
this.codeModel.operationGroups.forEach((operationGroup) => {
Expand Down Expand Up @@ -1009,6 +1020,9 @@ export class CodeModelCliImpl implements CodeModelAz {

public get CommandGroup_Mode(): string {
if (isNullOrUndefined(this.CommandGroup?.language?.['cli']?.extensionMode)) {
if (this.IsCliCore && this.Extension_Mode === ExtensionMode.Stable) {
lirenhe marked this conversation as resolved.
Show resolved Hide resolved
return ExtensionMode.Experimental;
}
return this.Extension_Mode;
}
return this.CommandGroup?.language?.['cli']?.extensionMode;
Expand Down
7 changes: 5 additions & 2 deletions src/generate/renders/CliTopAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ export class CliTopAction extends TemplateBase {
output.push(indentStr + 'from .generated.action import * # noqa: F403');
output.push(indentStr + 'try:');
output.push(indentStr + ' from .manual.action import * # noqa: F403');
output.push(indentStr + 'except ImportError:');
output.push(indentStr + ' pass');
output.push('except ImportError as e:');
output.push(" if e.name.endswith('manual.action'):");
output.push(' pass');
output.push(' else:');
output.push(' raise e');
output.push('');
return output;
}
Expand Down
7 changes: 5 additions & 2 deletions src/generate/renders/CliTopCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ export class CliTopCustom extends TemplateBase {
output.push(indentStr + 'from .generated.custom import * # noqa: F403');
output.push(indentStr + 'try:');
output.push(indentStr + ' from .manual.custom import * # noqa: F403');
output.push(indentStr + 'except ImportError:');
output.push(indentStr + ' pass');
output.push(indentStr + 'except ImportError as e:');
output.push(indentStr + " if e.name.endswith('manual.custom'):");
output.push(indentStr + ' pass');
output.push(indentStr + ' else:');
output.push(indentStr + ' raise e');
output.push('');
return output;
}
Expand Down
7 changes: 5 additions & 2 deletions src/generate/renders/CliTopHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ export class CliTopHelp extends TemplateBase {
output.push(
indentStr + ' from .manual._help import helps # pylint: disable=reimported',
);
output.push(indentStr + 'except ImportError:');
output.push(indentStr + ' pass');
output.push(indentStr + 'except ImportError as e:');
output.push(indentStr + " if e.name.endswith('manual._help'):");
output.push(indentStr + ' pass');
output.push(indentStr + ' else:');
output.push(indentStr + ' raise e');
return output;
}

Expand Down
35 changes: 25 additions & 10 deletions src/generate/renders/CliTopInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ export class CliTopInit extends TemplateBase {
indentStr + ' from .manual._params import load_arguments as load_arguments_manual',
);
output.push(indentStr + ' load_arguments_manual(self, command)');
output.push(indentStr + 'except ImportError:');
output.push(indentStr + ' pass');
output.push(indentStr + 'except ImportError as e:');
output.push(indentStr + " if e.name.endswith('manual._params'):");
output.push(indentStr + ' pass');
output.push(indentStr + ' else:');
output.push(indentStr + ' raise e');
return output;
}

Expand All @@ -115,8 +118,11 @@ export class CliTopInit extends TemplateBase {
' from .manual.commands import load_command_table as load_command_table_manual',
);
output.push(indentStr + ' load_command_table_manual(self, args)');
output.push(indentStr + 'except ImportError:');
output.push(indentStr + ' pass');
output.push(indentStr + 'except ImportError as e:');
output.push(indentStr + " if e.name.endswith('manual.commands'):");
output.push(indentStr + ' pass');
output.push(indentStr + ' else:');
output.push(indentStr + ' raise e');
return output;
}

Expand All @@ -140,8 +146,11 @@ export class CliTopInit extends TemplateBase {
importPath +
'.manual._help import helps # pylint: disable=reimported',
);
output.push('except ImportError:');
output.push(' pass');
output.push('except ImportError as e:');
output.push(" if e.name.endswith('manual._help'):");
output.push(' pass');
output.push(' else:');
output.push(' raise e');
output.push('');
} else {
importPath = '';
Expand Down Expand Up @@ -188,8 +197,11 @@ export class CliTopInit extends TemplateBase {
'.manual.commands import load_command_table as load_command_table_manual',
);
output.push(' load_command_table_manual(self, args)');
output.push(' except ImportError:');
output.push(' pass');
output.push(' except ImportError as e:');
output.push(" if e.name.endswith('manual.commands'):");
output.push(' pass');
output.push(' else:');
output.push(' raise e');
output.push(' return self.command_table');
output.push('');
output.push(' def load_arguments(self, command):');
Expand All @@ -202,8 +214,11 @@ export class CliTopInit extends TemplateBase {
'.manual._params import load_arguments as load_arguments_manual',
);
output.push(' load_arguments_manual(self, command)');
output.push(' except ImportError:');
output.push(' pass');
output.push(' except ImportError as e:');
output.push(" if e.name.endswith('manual._params'):");
output.push(' pass');
output.push(' else:');
output.push(' raise e');
output.push('');
output.push('');
output.push('COMMAND_LOADER_CLS = ' + model.Extension_NameClass + 'CommandsLoader');
Expand Down
7 changes: 6 additions & 1 deletion src/generate/renders/generated/CliHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { CodeModelAz } from '../../CodeModelAz';
import { SchemaType, Parameter } from '@azure-tools/codemodel';
import { HeaderGenerator } from '../Header';
import { ToMultiLine, isNullOrUndefined } from '../../../utils/helper';
import { ToMultiLine, isNullOrUndefined, ToSentence } from '../../../utils/helper';
import { CodeGenConstants } from '../../../utils/models';

let showExampleStr: string;
Expand All @@ -24,7 +24,12 @@ export function GenerateAzureCliHelp(model: CodeModelAz, debug: boolean): string
let output: string[] = [];
output.push('');

output.push('');
model.GatherInternalResource();
output.push("helps['" + model.Extension_Name + "'] = '''");
output.push(' type: group');
output.push(' short-summary: ' + model.Extension_Description);
output.push("'''");
if (model.SelectFirstCommandGroup()) {
do {
// if there's no operation in this command group
Expand Down
1 change: 1 addition & 0 deletions src/utils/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export enum CodeGenConstants {
testResources = 'test-resources',
preparers = 'preparers',
genCmdletTest = 'gen-cmdlet-test',
extensionDescription = 'extension-description',

// some configuration keys under az section
namespace = 'namespace',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
from azext_attestation.generated._help import helps # pylint: disable=unused-import
try:
from azext_attestation.manual._help import helps # pylint: disable=reimported
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual._help'):
pass
else:
raise e


class AttestationManagementClientCommandsLoader(AzCommandsLoader):
Expand All @@ -33,8 +36,11 @@ def load_command_table(self, args):
try:
from azext_attestation.manual.commands import load_command_table as load_command_table_manual
load_command_table_manual(self, args)
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.commands'):
pass
else:
raise e
return self.command_table

def load_arguments(self, command):
Expand All @@ -43,8 +49,11 @@ def load_arguments(self, command):
try:
from azext_attestation.manual._params import load_arguments as load_arguments_manual
load_arguments_manual(self, command)
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual._params'):
pass
else:
raise e


COMMAND_LOADER_CLS = AttestationManagementClientCommandsLoader
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
from .generated.action import * # noqa: F403
try:
from .manual.action import * # noqa: F403
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.action'):
pass
else:
raise e
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
from .generated.custom import * # noqa: F403
try:
from .manual.custom import * # noqa: F403
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.custom'):
pass
else:
raise e
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from knack.help_files import helps


helps['attestation'] = '''
type: group
short-summary: Manage Attestation
'''

helps['attestation'] = """
type: group
short-summary: Manage operation with attestation
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/boolean/configuration/readme.az.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ az:
client-authentication-policy: SansIOHTTPPolicy
az-output-folder: $(azure-cli-extension-folder)/src/boolean
python-sdk-output-folder: "$(az-output-folder)/azext_boolean/vendored_sdks/boolean"

extension-description: Bool Services in Test Server
```
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
from azext_boolean.generated._help import helps # pylint: disable=unused-import
try:
from azext_boolean.manual._help import helps # pylint: disable=reimported
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual._help'):
pass
else:
raise e


class AutoRestTestServiceCommandsLoader(AzCommandsLoader):
Expand All @@ -33,8 +36,11 @@ def load_command_table(self, args):
try:
from azext_boolean.manual.commands import load_command_table as load_command_table_manual
load_command_table_manual(self, args)
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.commands'):
pass
else:
raise e
return self.command_table

def load_arguments(self, command):
Expand All @@ -43,8 +49,11 @@ def load_arguments(self, command):
try:
from azext_boolean.manual._params import load_arguments as load_arguments_manual
load_arguments_manual(self, command)
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual._params'):
pass
else:
raise e


COMMAND_LOADER_CLS = AutoRestTestServiceCommandsLoader
Loading