Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change logic for generating import statement #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kasegao
Copy link

@kasegao kasegao commented Sep 1, 2024

close #62

The original logic had issues generating import statements in some cases where only the intermediate paths matched (for details, please see issue #62).

This PR contains two changes.
First, it fixes the relative import bug described in #62.
Second, it makes sure that imports are relative even when importing from the root. This helps with path resolution when importing generated code from the destination project.

Comment on lines +109 to +110
else:
break
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parent paths are different, the loop should exit.

# common/a/name.proto includes common/b/include.proto
# The basic name: include_p2p
module_name: str = message_path_list[-1].replace(".proto", "") + self.config.file_name_suffix
# Add non-shared parts: b.include_p2p
module_name = ".".join(message_path_list[index + 1 : -1] + (module_name,))

logger.info((self._fd.name, other_fd.name, index))
if index != -1:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When importing generated files from the destination project, paths should always be relative, even if they start from the root.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The generation logic for import statements has issues in some cases
1 participant