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 duplicated includes #645

Merged
merged 2 commits into from
Jul 23, 2024
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
29 changes: 18 additions & 11 deletions python/podio_gen/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,17 +591,24 @@ def _build_include_for_class(self, classname, include_from: IncludeFrom) -> str:

def _sort_includes(self, includes):
"""Sort the includes in order to try to have the std includes at the bottom"""
package_includes = sorted(i for i in includes if self.package_name in i)
podio_includes = sorted(i for i in includes if "podio" in i)
stl_includes = sorted(i for i in includes if "<" in i and ">" in i)

package_includes = []
podio_includes = []
stl_includes = []
upstream_includes = []
if self.upstream_edm:
upstream_includes = sorted(
i for i in includes if self.upstream_edm.options["includeSubfolder"] in i
)

# Are their includes that fulfill more than one of the above conditions? Are
# there includes that fulfill none?
for include in (inc for inc in includes if inc):
if self.package_name in include:
package_includes.append(include)
elif "podio" in include:
podio_includes.append(include)
elif "<" in include and ">" in include:
stl_includes.append(include)
elif self.upstream_edm and self.upstream_edm.options["includeSubfolder"] in include:
upstream_includes.append(include)
else:
print(f"Warning: unable to include '{include}'")

package_includes.sort()
podio_includes.sort()
stl_includes.sort()
upstream_includes.sort()
return package_includes + upstream_includes + podio_includes + stl_includes