meerk40t / meerk40t

Hackable Laser software for K40 / GRBL / Fibre Lasers
MIT License
276 stars 72 forks source link

Revert python statements that are incompatible with Python 3.6 #2690

Closed jpirnay closed 6 months ago

jpirnay commented 6 months ago

We still need Python 3.6 for Raspberry Pi 32 bit compiles - the walrus operator (if-assignment if flag:=condition:) has been introduced with python 3.8 and is hence unsupported.

Summary by Sourcery

Revert Python code to remove the walrus operator for compatibility with Python 3.6 and add a CI workflow to run unittests on Python 3.6.

Bug Fixes:

CI:

sourcery-ai[bot] commented 6 months ago

Reviewer's Guide by Sourcery

This PR reverts Python 3.8+ syntax (specifically the walrus operator ':=') to make the code compatible with Python 3.6, which is needed for Raspberry Pi 32-bit builds. The changes primarily involve restructuring conditional assignments into separate statements.

Architecture diagram for new CI workflow

graph TD;
    A[GitHub Actions] -->|Triggers| B[Unittest Workflow];
    B -->|Runs on| C[Windows 2019];
    B -->|Python Version| D[Python 3.6];
    B --> E[Checkout Code];
    B --> F[Setup Python];
    B --> G[Cache Python Environment];
    B --> H[Install Dependencies];
    B --> I[List Environment];
    B --> J[Run Unittests];
    subgraph Workflow Steps
        E --> F --> G --> H --> I --> J
    end

Class diagram for updated conditional assignments

classDiagram
    class OpCut {
        +add_reference(node, pos, kwargs)
        -valid_node_for_reference(node)
        -_children
    }
    class OpEngrave {
        +add_reference(node, pos, kwargs)
        -valid_node_for_reference(node)
        -_children
    }
    class ImageProperty {
        +update_image()
        +calculate_contours()
        -node
        -matrix
        -parameters
    }
    class Wxmtree {
        +refresh_tree(node, level, source)
        -elements
        -wxtree
    }
    class Wxutils {
        +set_color_according_to_theme(control, background, foreground)
    }
    note for OpCut "Reverted walrus operator in add_reference method"
    note for OpEngrave "Reverted walrus operator in add_reference method"
    note for ImageProperty "Reverted walrus operator in update_image and calculate_contours methods"
    note for Wxmtree "Reverted walrus operator in refresh_tree method"
    note for Wxutils "Reverted walrus operator in set_color_according_to_theme method"

File-Level Changes

Change Details Files
Replace walrus operator assignments with traditional assignment statements
  • Split walrus operator assignments into separate variable assignment and conditional check
  • Convert inline assignments in if-statements to two-line statements
  • Maintain logical equivalence while using Python 3.6 compatible syntax
meerk40t/core/node/op_cut.py
meerk40t/core/node/op_engrave.py
meerk40t/gui/propertypanels/imageproperty.py
meerk40t/gui/wxmtree.py
meerk40t/gui/wxutils.py
Add Python 3.6 specific CI workflow
  • Create new GitHub Actions workflow for Python 3.6 testing
  • Configure workflow to run on Windows 2019 with Python 3.6
  • Set up caching and dependency installation for the test environment
.github/workflows/unittest-py36.yml

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).