FullControlXYZ / fullcontrol

Python version of FullControl for toolpath design (and more) - the readme below is best source of information
GNU General Public License v3.0
672 stars 78 forks source link

Migrate to pydantic>2.0 #99

Closed miwaniza closed 3 months ago

miwaniza commented 3 months ago

Migration to latest pydantic with bump-pydantic tool highlighted the issues with gcode in some device setting files. Sorted them out, too.

fullcontrol-xyz commented 3 months ago

I can't see any changes in the device settings files. The start and end gcode parameters are shown as changed, but I've compared the two strings and can't find a difference. What was changed?

Also, for the pydantic, I believe we make it work for any version with the following code:

from pydantic import BaseModel, __version__

if int(__version__.split('.')[0]) >= 2:
    from pydantic import model_validator as validator
    validator_args = {"mode": "before"}
else:
    from pydantic import root_validator as validator
    validator_args = {"pre": True}

class BaseModelPlus(BaseModel):
...
...
...
    @classmethod
    @validator(**validator_args)
    def check_card_number_omitted(cls, values):

Please implement that unless you see any issues.

fullcontrol-xyz commented 3 months ago

The pydantic update is now implemented in commit bf8066836df2c0adc2e7d82ae9dc794dbb9dfce0

It required a few changes to some other bits of the repo too.

Thanks for raising the issue! requirements.txt and pyproject.toml have been updated to allow all versions of pydantic. The updated fullcontrol code checks which version of pydantic is installed and implements the appropriate function for the installed version.

See my comment above about device settings files. Please raise a new pr for that aspect if it is valid.

miwaniza commented 3 months ago

I can't see any changes in the device settings files. The start and end gcode parameters are shown as changed, but I've compared the two strings and can't find a difference. What was changed?

That's about line endings. Somewhere it was CR LF inserted within the gcode strings, so I removed them, because pylance used to highlight that these line breaks can't be within the string.

miwaniza commented 3 months ago

Also, for the pydantic, I believe we make it work for any version with the following code:

No, it won't, because pydantic also have updated decorators, e.g. to @model_validator

AndyGlx commented 3 months ago

Ah that makes sense with the CR LF. Github didn't highlight the changes and they didn't manifest when I cipy/pasted

I believe the pydantic code does work (I tested it on two versions of pydantic) cos the correct validator is selected and applied dynamically