Skip to content

Conversation

Pennycook
Copy link
Contributor

There was a circular dependency between platform.py and preprocessor.py:

  • Platform stores Macro and MacroFunction objects; and
  • MacroExpander requires a Platform.

Breaking this dependency enables Platform arguments in preprocessor.py to be decorated with the correct type-hints. This code structure is also a better reflection of how Platform is used by the preprocessor.

Related issues

Proposed changes

  • Move Platform definition from platform.py to preprocessor.py
  • Delete platform.py, because it no longer contains anything.
  • Update all references to platform.Platform to use preprocessor.Platform instead.

Reviewing the code, it is clear that a Platform doesn't really represent a "platform" in the sense we mean it elsewhere. It's really something like a "preprocessor state", and we construct a different Platform for each file in a codebase. As a follow-up to this PR I intend to rename Platform and tidy it up, but I wanted to make sure simply moving the class didn't break anything before going further.

There was a circular dependency between platform.py and preprocessor.py:
- Platform stores Macro and MacroFunction objects; and
- MacroExpander requires a Platform.

Breaking this dependency enables Platform arguments in preprocessor.py to be
decorated with the correct type-hints. This code structure is also a better
reflection of how Platform is used by the preprocessor.

Signed-off-by: John Pennycook <john.pennycook@intel.com>
@Pennycook Pennycook added this to the 2.x milestone Aug 6, 2025
@Pennycook Pennycook requested a review from Copilot August 6, 2025 10:58
@Pennycook Pennycook added the refactor Improvements to code structure label Aug 6, 2025
@Pennycook Pennycook changed the title Move Platform class into preprocessor.py Move Platform class into preprocessor.py Aug 6, 2025
Copy link
Contributor

@Copilot 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

This PR resolves a circular import dependency between platform.py and preprocessor.py by moving the Platform class definition from platform.py to preprocessor.py, enabling proper type hints for Platform arguments in the preprocessor module.

  • Move Platform class from platform.py to preprocessor.py
  • Delete the now-empty platform.py file
  • Update all import statements to use preprocessor.Platform instead of platform.Platform

Reviewed Changes

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

Show a summary per file
File Description
codebasin/platform.py File deleted entirely as Platform class moved to preprocessor.py
codebasin/preprocessor.py Added Platform class definition and updated MacroExpander type hint
codebasin/finder.py Updated imports to use Platform from preprocessor module
tests/operators/test_operators.py Updated imports to use Platform from preprocessor module
tests/macro_expansion/test_macro_expansion.py Updated imports to use Platform from preprocessor module

Pennycook and others added 2 commits August 6, 2025 12:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: John Pennycook <john.pennycook@intel.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: John Pennycook <john.pennycook@intel.com>
@Pennycook Pennycook force-pushed the refactor/platform-class branch from 3b713bd to 5091f4b Compare August 6, 2025 11:04
@Pennycook
Copy link
Contributor Author

Accepting Copilot's changes didn't include the sign-off this time for some reason, so I've had to force-push.

@Pennycook Pennycook merged commit dcea187 into P3HPC:main Aug 6, 2025
3 of 4 checks passed
@Pennycook Pennycook deleted the refactor/platform-class branch August 6, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Improvements to code structure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant