Azure / autorest.python

Extension for AutoRest (https://github.com/Azure/autorest) that generates Python code
MIT License
79 stars 57 forks source link

ExternalError when running tsp-client init #2687

Closed mc3784 closed 2 months ago

mc3784 commented 2 months ago

Hello I was trying to generate the python sdk using this command:

tsp-client init -c https://github.com/Azure/azure-rest-api-specs-pr/blob/dcd30a31e125cfb4f1e256db611aea8ac99bcb52/specification/orbitalplanetarycomputer/Orbital.Spatio/tspconfig.yaml

I got a message back suggesting that this might be a bug and asking to file a bug here. Can somebody take a look and let me know if this is a bug or if I am doing something wrong? Thank you so much!

Following the full output:

`Use output directory 'C:/One/azure-sdk-for-python'? (y/n) y Using output directory 'C:/One/azure-sdk-for-python'

888 888 d8b 888 888 888 Y8P 888 888 888 888 888888 .d8888b 88888b. .d8888b 888 888 .d88b. 88888b. 888888 888 88K 888 "88b d88P" 888 888 d8P Y8b 888 "88b 888 888 "Y8888b. 888 888 888888 888 888 888 88888888 888 888 888 Y88b. X88 888 d88P Y88b. 888 888 Y8b. 888 888 Y88b. "Y888 88888P' 88888P" "Y8888P 888 888 "Y8888 888 888 "Y888 888 888 888

tsp-client version: 0.9.2 Found emitter package @azure-tools/typespec-python SDK initialized in C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog Found emitter package @azure-tools/typespec-python Installing dependencies from npm...

added 95 packages, and audited 96 packages in 47s

12 packages are looking for funding run npm fund for details

found 0 vulnerabilities Resolved path: C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog/TempTypeSpecFiles/Orbital.Spatio/node_modules/@typespec/compiler Compiling tsp using @azure-tools/typespec-python... Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen__init.py", line 334, in ).process() ^^^^^^^^^ File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen__init__.py", line 318, in process code_model = CodeModel(yaml_data=yaml_data, options=options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen\models\code_model.py", line 67, in init__ self.sort_model_types() File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen\models\code_model.py", line 220, in sort_model_types sorted_object_schemas.extend(self._sort_model_types_helper(schema, seen_schema_names, seen_schema_yaml_ids)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen\models\code_model.py", line 197, in _sort_model_types_helper raise ValueError(f"We have already generated a schema with name {current.name}") ValueError: We have already generated a schema with name Link Error: Command failed: py -3 C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python/scripts/run_tsp.py --output-folder=C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog --cadl-file=C:/Users/miceru/AppData/Local/Temp/cadl-codegen/typespec-python-yaml-mapec0ac960-70ea-4a79-a1bf-e8972b5587ee.yaml --package-version=1 --generate-packaging-files=true --flavor=azure --basic-setup-py=true --package-dir=geocatalog --package-name=geocatalog --models-mode=dpg --package-mode=azure-dataplane --emit-cross-language-definition-file=true --from-typespec=true ExternalError: Emitter "@azure-tools/typespec-python" crashed! This is a bug. Please file an issue at https://github.com/Azure/autorest.python/issues

Error: Command failed: C:\Program Files\nodejs\node.exe C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python/scripts/run-python3.cjs C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python/scripts/run_tsp.py --output-folder=C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog --cadl-file=C:/Users/miceru/AppData/Local/Temp/cadl-codegen/typespec-python-yaml-mapec0ac960-70ea-4a79-a1bf-e8972b5587ee.yaml --package-version=1 --generate-packaging-files=true --flavor=azure --basic-setup-py=true --package-dir=geocatalog --package-name=geocatalog --models-mode=dpg --package-mode=azure-dataplane --emit-cross-language-definition-file=true --from-typespec=true Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen__init.py", line 334, in ).process() ^^^^^^^^^ File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen__init__.py", line 318, in process code_model = CodeModel(yaml_data=yaml_data, options=options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen\models\code_model.py", line 67, in init__ self.sort_model_types() File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen\models\code_model.py", line 220, in sort_model_types sorted_object_schemas.extend(self._sort_model_types_helper(schema, seen_schema_names, seen_schema_yaml_ids)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python\generator\pygen\codegen\models\code_model.py", line 197, in _sort_model_types_helper raise ValueError(f"We have already generated a schema with name {current.name}") ValueError: We have already generated a schema with name Link Error: Command failed: py -3 C:\One\azure-sdk-for-python\sdk\geocatalog\geocatalog\TempTypeSpecFiles\Orbital.Spatio\node_modules\@azure-tools\typespec-python/scripts/run_tsp.py --output-folder=C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog --cadl-file=C:/Users/miceru/AppData/Local/Temp/cadl-codegen/typespec-python-yaml-mapec0ac960-70ea-4a79-a1bf-e8972b5587ee.yaml --package-version=1 --generate-packaging-files=true --flavor=azure --basic-setup-py=true --package-dir=geocatalog --package-name=geocatalog --models-mode=dpg --package-mode=azure-dataplane --emit-cross-language-definition-file=true --from-typespec=true

at genericNodeError (node:internal/errors:984:15)
at wrappedFn (node:internal/errors:538:14)
at checkExecSyncError (node:child_process:890:11)
at execFileSync (node:child_process:926:15)
at Object.$onEmit [as emitFunction] (file:///C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog/TempTypeSpecFiles/Orbital.Spatio/node_modules/@azure-tools/typespec-python/dist/src/emitter.js:89:9)
at async runEmitter (file:///C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog/TempTypeSpecFiles/Orbital.Spatio/node_modules/@typespec/compiler/dist/src/core/program.js:452:13)
at async compile (file:///C:/One/azure-sdk-for-python/sdk/geocatalog/geocatalog/TempTypeSpecFiles/Orbital.Spatio/node_modules/@typespec/compiler/dist/src/core/program.js:132:9)
at async compileTsp (file:///C:/Users/miceru/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/typespec.js:78:21)
at async generate (file:///C:/Users/miceru/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:196:5)
at async main (file:///C:/Users/miceru/AppData/Roaming/npm/node_modules/@azure-tools/typespec-client-generator-cli/dist/index.js:269:17)

Library Version 0.25.0 TypeSpec Compiler Version 0.57.0 --------------------------------------------------`

iscai-msft commented 2 months ago

thank you for opening this issue @mc3784 I'm going to take a look today

iscai-msft commented 2 months ago

This is because there are two definitions of Link in the spec: here and here. Python isn't able to deal with models of the same name in different namespaces. This is a feature-lack that we have this issue open for. We don't have a timeline for being able to generate models under different namesapces, is this something you guys really need? If not, I'd recommend for now a model rename.