palantir / palantir/conjure-python

Valid conjure definition results in circular python import

Open
#62 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
27
Forks
19
Avg merge
12h 22m
Merged PRs (30d)
15

Description

What happened?

I modified the https://github.com/palantir/conjure-java-example to introduce a circular dependency between packages:

--- a/recipe-example-api/src/main/conjure/recipe-example-api.yml
+++ b/recipe-example-api/src/main/conjure/recipe-example-api.yml
@@ -14,6 +14,7 @@ types:
         alias: string

       BakeStep:
+        package: com.palantir.conjure.examples.recipe.api.step
         fields:
           temperature: Temperature
           durationInSeconds: integer

This causes two python packages to be created (expected):
conjure_examples_recipe_api:

from ..conjure_examples_recipe_api_step import BakeStep
from abc import ABCMeta, abstractmethod
from conjure_python_client import ConjureBeanType, ConjureDecoder, ConjureEncoder, ConjureEnumType, ConjureFieldDefinition, ConjureUnionType, ListType, Service
from typing import List, Set

class Recipe(ConjureBeanType):
[...]

conjure_examples_recipe_api_step:

from ..conjure_examples_recipe_api import Temperature
from conjure_python_client import ConjureBeanType, ConjureFieldDefinition

class BakeStep(ConjureBeanType):
[...]

This python code cannot be imported due to the circular dependency:

>>> import sys
>>> sys.path.append("/src/ahiggins/conjure-java-example/recipe-example-api/recipe-example-api-python/python/")
>>> from recipe_example_api.conjure_examples_recipe_api import Temperature

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-428f65a0c05a> in <module>
      1 import sys, os
      2 sys.path.append("/src/ahiggins/conjure-java-example/recipe-example-api/recipe-example-api-python/python/")
----> 3 from recipe_example_api.conjure_examples_recipe_api import Temperature

/src/ahiggins/conjure-java-example/recipe-example-api/recipe-example-api-python/python/recipe_example_api/conjure_examples_recipe_api/__init__.py in <module>
----> 1 from ..conjure_examples_recipe_api_step import BakeStep
      2 from abc import ABCMeta, abstractmethod
      3 from conjure_python_client import ConjureBeanType, ConjureDecoder, ConjureEncoder, ConjureEnumType, ConjureFieldDefinition, ConjureUnionType, ListType, Service
      4 from typing import List, Set
      5 

/src/ahiggins/conjure-java-example/recipe-example-api/recipe-example-api-python/python/recipe_example_api/conjure_examples_recipe_api_step/__init__.py in <module>
----> 1 from ..conjure_examples_recipe_api import Temperature
      2 from conjure_python_client import ConjureBeanType, ConjureFieldDefinition
      3 
      4 class BakeStep(ConjureBeanType):
      5 

ImportError: cannot import name 'Temperature'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the circular dependency from the modified recipe-example-api.yml in the conjure-java-example project. Inspect the generated conjure_examples_recipe_api/init.py and conjure_examples_recipe_api_step/init.py files and the generator entry point that produces them. Done means a valid definition with circular package references generates Python packages that can be imported successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.