-
Notifications
You must be signed in to change notification settings - Fork 28
Refactor cfstore to dataclasses #124
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
Conversation
a303d96 to
5a4b537
Compare
simon-ess
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is a clear improvement!
server/recceiver/cfstore.py
Outdated
| cf_channel["properties"].append( | ||
| create_recordType_property( | ||
| owner, iocs[channels_dict[cf_channel["name"]][-1]]["recordType"] | ||
| ioc_info.owner, iocs[channels_iocs[cf_channel["name"]][-1]]["recordType"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a .recordType here? We use .owner above on the same object...
(These objects are very confusing to follow... this is clearly going to be an improvement but ugh)
server/recceiver/cfstore.py
Outdated
| alias_channel["properties"] = __merge_property_lists( | ||
| [ | ||
| create_active_property(owner), | ||
| create_time_property(owner, iocTime), | ||
| ], | ||
| alias, | ||
| alias_channel, | ||
| processor.managed_properties, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do this in the above row when you're declaring the dict? 🔧
|
|
||
| if iocid not in iocs: | ||
| _log.warning("IOC Env Info not found: {iocid}".format(iocid=iocid)) | ||
| _log.warning("IOC Env Info %s not found in ioc list: %s", ioc_info, iocs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please improve this msg/phrasing while we're at it? I hate "IOC Env Info"
server/recceiver/cfstore.py
Outdated
| ): | ||
| for cf_channel in old_channels: | ||
| if ( | ||
| len(new_channels) == 0 or cf_channel.name in records_to_delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason not to do not new_channels or ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still seems to apply
5c64534 to
2c90757
Compare
2c90757 to
2add230
Compare
anderslindho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll end the review here, as it looks unfinished from 2add230
2a666e8 to
3375756
Compare
012aae6 to
919b9fa
Compare
In favour of create_property_blah
log the whole object when available use inbuilt log formatting rather than f strings or .format (should improve performance)
919b9fa to
3f68066
Compare
anderslindho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty good, but IMO we should be fixing these remaining idiomatic python/PEP-8 issues before merge. Can all be in a single new commit if you want, TBH.
server/recceiver/cfstore.py
Outdated
| Active = enum.auto() | ||
| Inactive = enum.auto() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about this, StrEnum is def the way to go - don't think we have any other option for CFPropertyName.
| from . import interfaces | ||
| from .interfaces import CommitTransaction | ||
| from .processors import ConfigAdapter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should prob convert the project to use abs imports - could be done together with splitting up cfstore.py 💭
| cf_query_limit: int = DEFAULT_QUERY_LIMIT | ||
|
|
||
| @classmethod | ||
| def loads(cls, conf: ConfigAdapter) -> "CFConfig": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loads usually means "load from string" (and then load is typically from file), but I guess this is OK because from_configadapter would be a bit odd/is not immediately clear (that class is a bit strange TBH)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree that I expect loads to be from a string, but I would otherwise interpret load as just kind of generic. So maybe it would be better in this case?
211d19b to
26d6654
Compare
|
@anderslindho I dropped the override commit, only supported on 3.12 and above. |
| cf_query_limit: int = DEFAULT_QUERY_LIMIT | ||
|
|
||
| @classmethod | ||
| def loads(cls, conf: ConfigAdapter) -> "CFConfig": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do agree that I expect loads to be from a string, but I would otherwise interpret load as just kind of generic. So maybe it would be better in this case?
| def from_dict(cls, prop_dict: Dict[str, str]) -> "CFProperty": | ||
| """Create CFProperty from Channelfinder json output. | ||
| Args: | ||
| prop_dict: Dictionary representing a property from Channelfinder. | ||
| """ | ||
| return cls( | ||
| name=prop_dict.get("name", ""), | ||
| owner=prop_dict.get("owner", ""), | ||
| value=prop_dict.get("value"), | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you really need this function? You can also allow defaults in the class definition and just do
CFProperty(**some_dict)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its the frustrating 'channels' field in the prop_dict :( that blocks doing it that way.
| @classmethod | ||
| def from_dict(cls, channel_dict: Dict[str, Any]) -> "CFChannel": | ||
| """Create CFChannel from Channelfinder json output. | ||
| Args: | ||
| channel_dict: Dictionary representing a channel from Channelfinder. | ||
| """ | ||
| return cls( | ||
| name=channel_dict.get("name", ""), | ||
| owner=channel_dict.get("owner", ""), | ||
| properties=[CFProperty.from_dict(p) for p in channel_dict.get("properties", [])], | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above.
| CFPropertyName.HOSTNAME.value, | ||
| CFPropertyName.IOC_NAME.value, | ||
| CFPropertyName.IOC_ID.value, | ||
| CFPropertyName.IOC_IP.value, | ||
| CFPropertyName.PV_STATUS.value, | ||
| CFPropertyName.TIME.value, | ||
| CFPropertyName.RECCEIVER_ID.value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need the .values here? Can we not just work with the enum entities?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of a general question tbh - everywhere I saw the enums used they were used as their .value version. Can't they be let be except when you are printing them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CFPropertyName is a tricky case as you mentioned, in that this is the 'default' property names. You can have them for the env variables and the info tags.
Personally I think there is value supporting 3.6 for the user community. It is EOL but it is the default python version on redhat and the RHEL variants. Redhat backports security fixes to 3.6 and will until 2029. Not saying we need to continue 3.6 support until then but I also don't see a big reason to drop it now |
26d6654 to
f74749e
Compare
|
|
@anderslindho name to value in https://github.com/ChannelFinder/recsync/compare/26d6654a5786ff342ad5928093d30ab2e37cd0ab..f74749eb22ba3c1f833fb382dbd903f3f8c7b865 is the only change |



Large refactor of cfstore