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

Fix relative includes in case the files are next to each other #27

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions protobuf_to_pydantic/plugin/field_desc_proto_to_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def _add_other_module_pkg(self, other_fd: FileDescriptorProto, type_str: str) ->
for _index in range(min(len(fd_path_list), len(message_path_list))):
if message_path_list[_index] == fd_path_list[_index]:
index = _index
# 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,))

module_name: str = (
".".join(message_path_list[index + 1 : -1])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if message_path_list[index + 1 : -1] returned an empty list, the module_name at this point started with a dot due to the + "." in the next line.

+ "."
+ message_path_list[-1].replace(".proto", "")
+ self.config.file_name_suffix
)
logger.info((self._fd.name, other_fd.name, index))
if index != -1:
# Add relative parts: ..b.include_p2p
module_name = "." * (len(message_path_list) - (index + 1)) + module_name
self._add_import_code(module_name, type_str)

Expand Down