I'm trying to get the `experimental_wrap_as_python...
# general
p
I'm trying to get the
experimental_wrap_as_python_sources
to work. I have an adhoc tool that is outputing dist/codegen/blah. Where blah is a python package. Blah is generated with the openapi-generator. The code looks good. I have set the
experimental_wrap_as_python_sources
target as a dependency to the python_sources.. but I'm seeing
Copy code
NoSourceRootError: No source root found for blah
Any advice to debug this?
Copy code
adhoc_tool(
    name="observatory-api-py-bindings",
    runnable="//third_party/jvm:openapi-generator",
    args=[
        "generate",
        "--input-spec=observatory.yaml",
        "--generator-name=python-experimental",
        "--output=observatory_api",
        "--package-name=observatory_api",
    ],
    execution_dependencies=[
        ":openapi",
    ],
    output_directories=[
        "observatory_api/observatory_api",
    ],
    root_output_directory="./observatory_api",
)

experimental_wrap_as_python_sources(
    name="observatory-api-py",
    inputs=[
        ":observatory-api-py-bindings",
    ],
)
Following an export-codegen
Copy code
ls dist/codegen/observatory_api/
api  api_client.py  apis  configuration.py  exceptions.py  __init__.py  model  models  rest.py  schemas.py
Copy code
* observatory_api.ApiClient (line: 6)
  * observatory_api.exceptions.ApiException (line: 7)

If you do not expect an import to be inferrable, add `# pants: no-infer-dep` to the import line. Otherwise, see <https://www.pantsbuild.org/v2.18/docs/troubleshooting#import-errors-and-missing-dependencies> for common problems.
I feel like this should work? 🤔
Following the adhoc example and exploring the output I think it’s the same. :/ https://github.com/pantsbuild/example-adhoc/blob/main/antlr/BUILD
b
What’s your source root configuration in
pants.toml
? Is it similar to that example?
p
Let me check
Source root was
Copy code
[source]
root_patterns = [
  "/enclosure",
  "/teletom_shared/src",
  "/teletom/",
  # "/observatory_api",
]
I have removed the observatory_api. In the past I was generating this and checking it in.
Also removed the directory /obser..
So the antlr expr_parser_py also outputs with the directory stucture of
expr_parser/*.py
this doesn't have a
__init__.py
It also has the infer warning.. but that seems to not matter here
Copy code
15:57:23.48 [WARN] Pants cannot infer owners for the following imports in the target antlr:antlr_demo:

  * expr_parser.ExprLexer (line: 10)
  * expr_parser.ExprListener (line: 11)
  * expr_parser.ExprParser (line: 12)
When running pants dependencies I see that
observatory-api-py
is a dependency of the python_source in question
Maybe it is the pants package path? In pantsbuild it is testprojects.wrap_as.hello_world https://github.com/pantsbuild/pants/blob/adb05447f504a4a2f48bec5047a7f0a7bff03ab4/testprojects/wrap_as/BUILD#L29
No. That doesn't work, and doesn't match the example_adhoc 🤔
Any thoughts @broad-processor-92400? The underlying code seems fairly straightforward 🤔 https://github.com/pantsbuild/pants/blob/adb05447f504a4a2f48bec5047a7f0a7bff03ab4/src/python/pants/core/util_rules/wrap_source.py#L76-L82
b
sorry, I don't have insight, I was just reflecting on the error message. Can you reduce your example?
h
Try adding
/
as a source root
it won't harm your existing source roots (the innermost one is used) but if blah's path isn't under any source root, this will give it one
p
Ooooh interesting that worked.
So maybe I need a source root where observatory_api is? it is currently under openapi/BUILD
h
Your source code should already have source roots set up appropriately? This is just for the generated code, which did not
p
I think I see. I have
Copy code
openapi
   openapi.yaml
   BUILD
observatory_api <- this use to be checked in
I then generate the openapi python bindings via an adhoc tool and the java backend. I deleted the observatory_api. If I have a source root at /openapi... would the generated python module be at openapi.observatory_api?
h
Try it and see! I don't think so though. It'll output to wherever the adhoc tool outputs, some relative path, and then some time later Pants will try and apply source root discovery to that path.