Azure / autorest.azure-functions

Code Generation for Azure Functions
MIT License
46 stars 6 forks source link

[Bug Report] Python scaffolding fails with ModuleNotFoundError: No module named 'm2r' #12

Open epopisces opened 2 years ago

epopisces commented 2 years ago

Troubleshooting:

Setup (please complete the following information): **

Type Extension Name Version
extension @autorest/azure-functions-python 0.1.0-preview
core @autorest/core 3.0.6320
core @autorest/core 3.8.3
extension @autorest/modelerfour 4.15.414

Describe the bug

When attempting to scaffold a project using the VSCode extension (Create new project > select folder > Python > HTTP trigger(s) from OpenAPI V2/V3 Specification (Preview)), the process fails with the following error:

10:32:13 AM: Running command: "autorest --input-file:"c:\development\test\example_OpenAPIv3.json" --version:3.0.6320 --azure-functions-python --no-namespace-folders:True --no-async --generate-metadata:false --output-folder:"c:\development\test""... AutoRest code generation utility [cli version: 3.6.1; node: v17.8.0] (C) 2018 Microsoft Corporation. https://aka.ms/autorest info | AutoRest core version selected from configuration: 3.0.6320. Loading AutoRest core 'C:\Users\%USER%.autorest\@autorestcore@3.0.6320\nodemodules\@autorest\core\dist' (3.0.6320) Loading AutoRest extension '@autorest/azure-functions-python' (latest->0.1.0-preview) Loading AutoRest extension '@autorest/modelerfour' (4.15.414->4.15.414) WARNING (PreCheck/CheckDuplicateSchemas): Checking for duplicate schemas, this could take a (long) while. Run with --verbose for more detail. API Exception: {'type': 'ModuleNotFoundError', 'args': ("No module named 'm2r'",), 'message': "No module named 'm2r'"} Traceback (most recent call last): File "C:\Users\%USER%.autorest\@autorest_azure-functions-python@0.1.0-preview\node_modules\@autorest\azure-functions-python\venv\lib\site-packages\jsonrpc\manager.py", line 113, in _get_responses result = method(*request.args, **request.kwargs) File "C:\Users\%USER%.autorest\@autorest_azure-functions-python@0.1.0-preview\node_modules\@autorest\azure-functions-python\autorest\jsonrpc\server.py", line 34, in Process from ..m2r import M2R as PluginToLoad File "C:\Users\%USER%.autorest\@autorest_azure-functions-python@0.1.0-preview\node_modules\@autorest\azure-functions-python\autorest\m2r__init__.py", line 11, in import m2r ModuleNotFoundError: No module named 'm2r' Error: Server error 10:32:17 AM: Error: Failed to run "autorest" command. Check output window for more details.

Strongly suspect this is due to one of the dependencies--or rather, dependencies' dependency mistune--having a breaking change when it went from 0.8.4 to 2.0.x. The Common Errors section of the autorest.az FAQ was invaluable in figuring out the workaround (see Additional Context below for the workaround).

To Reproduce

Prerequisites:

  1. From the VSCode extension, Create new project > select folder > Python > HTTP trigger(s) from OpenAPI V2/V3 Specification (Preview)
  2. Select test.json as the file

Error will be reproduced as described above.

Additional context Was able to resolve the issue by activating the autorest venv and installing a pinned version of mistune, then also installing the other dependencies it blocked.

C:\Users\%USER%\.autorest\@autorest_azure-functions-python@0.1.0-preview\node_modules\@autorest\azure-functions-python\venv\Scripts\activate
pip install mistune==0.8.4
pip install m2r
pip install jinja2

Once those steps are taken, it works fine. Perhaps pinning the mistune version within autorest would resolve for future users?