Skip to content

refactor: add EntityPath enum#265

Merged
ktro2828 merged 2 commits into
mainfrom
refactor/entity-paths
Feb 10, 2026
Merged

refactor: add EntityPath enum#265
ktro2828 merged 2 commits into
mainfrom
refactor/entity-paths

Conversation

@ktro2828
Copy link
Copy Markdown
Collaborator

@ktro2828 ktro2828 commented Feb 10, 2026

What

This pull request refactors how entity paths are managed throughout the viewer module by introducing a new EntityPath enum. This change replaces hardcoded string constants and class variables with strongly-typed enum members, improving code maintainability, readability, and reducing the risk of typos. The update is applied consistently across helper, builder, config, and viewer files, and ensures that all entity path references use the new enum. Additionally, the format_entity function is updated to accept both strings and EntityPath members, and several type annotations are improved for clarity.

Entity Path Refactoring:

  • Introduced a new EntityPath enum in t4_devkit/viewer/config.py to centralize and standardize entity path definitions, replacing previous string constants and class variables. [1] [2]
  • Updated all usages of entity path strings (like "map", "map/base_link", etc.) in files such as rendering.py, builder.py, and viewer.py to use the new EntityPath enum members. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21]

Function and Type Improvements:

  • Modified format_entity to accept both str and EntityPath arguments, and updated its docstring and usage examples accordingly. [1] [2]
  • Improved type annotations for function parameters, especially for optional and union types in viewer.py, making the code clearer and more robust. [1] [2] [3]

Test and Import Updates:

  • Updated tests and imports to use the new EntityPath enum where appropriate.

These changes modernize the codebase, making it easier to maintain and less error-prone when dealing with entity paths.

@github-actions github-actions Bot added the refactor Refactoring code or increasing performance label Feb 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 10, 2026

☂️ Python Coverage

current status: ❌

Overall Coverage

Lines Covered Coverage Threshold Status
4215 3491 83% 50% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
t4_devkit/helper/rendering.py 18% 🔴
t4_devkit/viewer/builder.py 87% 🟢
t4_devkit/viewer/config.py 98% 🟢
t4_devkit/viewer/viewer.py 87% 🟢
TOTAL 72% 🔴

updated for commit: 42846bf by action🐍

@ktro2828 ktro2828 force-pushed the refactor/entity-paths branch from 35d1f71 to 3994d01 Compare February 10, 2026 00:33
@ktro2828 ktro2828 self-assigned this Feb 10, 2026
@github-actions github-actions Bot added the ci Continuous Integration (CI) processes and testing label Feb 10, 2026
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 force-pushed the refactor/entity-paths branch from 3994d01 to 4dbd006 Compare February 10, 2026 08:54
@ktro2828 ktro2828 requested a review from Copilot February 10, 2026 08:55
@ktro2828 ktro2828 marked this pull request as ready for review February 10, 2026 08:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors viewer entity path handling by introducing a centralized EntityPath enum and migrating existing hardcoded path strings to enum members.

Changes:

  • Added EntityPath enum and updated format_entity to accept str | EntityPath.
  • Replaced string-based entity paths across viewer/builder/helper modules with enum usage.
  • Updated viewer tests to cover enum-based entity path formatting.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/viewer/test_viewer.py Extends format_entity tests to cover EntityPath inputs.
t4_devkit/viewer/viewer.py Migrates viewer logging/timeline/entity path construction to EntityPath.
t4_devkit/viewer/config.py Introduces EntityPath and updates ViewerConfig typing + format_entity signature/docs.
t4_devkit/viewer/builder.py Switches blueprint view origins to use EntityPath.
t4_devkit/helper/rendering.py Updates helper rendering entity roots to use EntityPath.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

render_ways(parser, root_entity)

render_geographic_borders(parser, f"{self.config.geocoordinate_entity}/vector_map")
render_geographic_borders(parser, f"{EntityPath.GEOCOORDINATE}/{EntityPath.VECTOR_MAP}")
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

EntityPath is an Enum; interpolating it via an f-string can yield the enum's name (e.g., EntityPath.GEOCOORDINATE) rather than the intended value (geocoordinate), depending on Python/Enum behavior. Build this path with format_entity(EntityPath.GEOCOORDINATE, EntityPath.VECTOR_MAP) or use .value for both enum members to guarantee the correct string.

Suggested change
render_geographic_borders(parser, f"{EntityPath.GEOCOORDINATE}/{EntityPath.VECTOR_MAP}")
render_geographic_borders(parser, format_entity(EntityPath.GEOCOORDINATE, EntityPath.VECTOR_MAP))

Copilot uses AI. Check for mistakes.
Comment on lines 431 to 433
if color_mode == PointCloudColorMode.SEGMENTATION:
if not isinstance(pointcloud, SegmentationPointCloud):
raise TypeError(
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

SegmentationPointCloud is referenced at runtime in an isinstance check, but it is no longer imported in the shown TYPE_CHECKING block (and there is no runtime import in this diff). If there isn't another runtime import elsewhere in this module, this will raise NameError. Ensure SegmentationPointCloud is imported at runtime (not under TYPE_CHECKING).

Copilot uses AI. Check for mistakes.
Comment on lines 29 to 30


Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

To make EntityPath reliably behave like a plain string across all call sites (logging, serialization, f-strings, etc.), consider switching to StrEnum (if the supported Python version allows it) or explicitly overriding __str__/__format__ to return self.value. This avoids subtle issues where an enum may stringify to EntityPath.MAP instead of map.

Suggested change
def __str__(self) -> str:
"""Return the underlying string value of the entity path."""
return self.value
def __format__(self, format_spec: str) -> str:
"""Format the underlying string value of the entity path."""
return format(self.value, format_spec)

Copilot uses AI. Check for mistakes.
Comment thread t4_devkit/viewer/config.py Outdated
…to EntityPath enumerations

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 force-pushed the refactor/entity-paths branch from 4dbd006 to 42846bf Compare February 10, 2026 09:06
@ktro2828 ktro2828 merged commit 2f24a68 into main Feb 10, 2026
4 of 5 checks passed
@ktro2828 ktro2828 deleted the refactor/entity-paths branch February 10, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration (CI) processes and testing refactor Refactoring code or increasing performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants