Breaking: Redesign structure to use plugin structure#165
Breaking: Redesign structure to use plugin structure#165oliwenmandiamond merged 35 commits intomainfrom
Conversation
There was a problem hiding this comment.
To me, the name plugins is a bit less clear and specific then the name models. I also think it's slightly confusing having lots of _converters.py files outside of the converters directory but maybe there's no way around this.
Also, are you against having the option of doing
from daq_config_server.models import MyModelAs we could presumably keep the other improvements to the module structure but also add models to daq_config_sever.models.__init__.py, allowing you to import them in whichever way you prefer.
| import xmltodict | ||
|
|
||
| from daq_config_server.models.converters.beamline_parameters import ( | ||
| from daq_config_server.core._base_model import ConfigModel |
There was a problem hiding this comment.
Can we avoid importing from private modules that are in different directories?
I think we should expose ConfigModel in daq_config_server.core.__init__.py
I was going to comment the same thing |
|
Yeah, I can rename back to models, no problem
Yeah, could maybe even just put it at the top of daq_config_server.models
The point is NOT to share the same namespace as other models / plugins / whatever. They should be isolated and not depend on one another / have visibility of each other. Otherwise, what's the point of the separate model structure if we then force them into the same namespace anyway? We might as well just put everything into a single massive file |
|
Personally I don't think the import structure has to exactly reflect the internal file structure.
This would make it horrible for developers for work on. The internal file structure to me is a separate decision to how we want to design the public interface. I have a preference for a fairly flat import structure and a more organised file structure, but not a strong one so happy to be overuled |
Exactly! This is the core issue. You are trying to use both structures, so you remove the advantages of one way and then give it all the disadvantages of the other. One needs to be picked! Now you are indirectly causing them all share the the same namespace which can easily cause confusion and name conflicts. For example, to make a comparison, lets take Instead of using As I mentioned previously, it may not seem like an issue right now because only really MX are using it. But if me and many other developers want to also use this service, this will quickly get out of hand. |
|
I think you're both actually almost on the same page here, we all agree that something like
|
Yes, having core / common models at the top level is perfectly fine, as long as that is where it actually lives. So it would look like this imports are now from daq_config_server.models import MyCommonModel
from daq_config_server.models.specific_thing1 import MySpecificModel
from daq_config_server.models.specific_thing2 import MySpecificModelSo common things from a quick glance would be |
|
@olliesilvester @jacob720 I think this is ready for review now. Apologies on size of change. The main clean up I've done is:
I will raise a separate issue so that external repositories can only import what they need, which is ConfigServer and the models package. |
|
I'm also happy to go around all the external repos and apply the breaking change to them so it all rolls out smoothly |
olliesilvester
left a comment
There was a problem hiding this comment.
Thanks, the structure is nicer I think. I haven't gone through all the tests and logic just yet
| from ._converter_utils import ConverterParseError | ||
| import daq_config_server.converters._file_converter_map as file_converter_map | ||
| from daq_config_server.converters._converter_utils import ConverterParseError | ||
| from daq_config_server.models._base_model import ConfigModel | ||
|
|
||
|
|
||
| def get_converted_file_contents(file_path: Path) -> dict[str, Any]: |
There was a problem hiding this comment.
Should: expose get_converted_file_contents in converters/__init__.py, so that other files don't have to import from this private file.
There was a problem hiding this comment.
Putting something in __all__ signals that it is part of the public API and intended for external use. It is and should only be used inside this package I believe so doesn't make sense to.
There was a problem hiding this comment.
I think you're maybe mixing up what's publicly available to those using daq-config-server as a library, and public/private parts internal to the repo
Since get_converted_file_contents is defined in the converters module but is used by the app module, we should indicate that get_converted_file_contents is okay to use in other modules. Same goes for my other comments
There was a problem hiding this comment.
We could go even further and make another module that exposes the external API in a neater way. Maybe for a separate issue though
oliwenmandiamond
left a comment
There was a problem hiding this comment.
I haven't updated any logic or tests, only structure (except when the tests where failing due to state persisting)
| from ._converter_utils import ConverterParseError | ||
| import daq_config_server.converters._file_converter_map as file_converter_map | ||
| from daq_config_server.converters._converter_utils import ConverterParseError | ||
| from daq_config_server.models._base_model import ConfigModel | ||
|
|
||
|
|
||
| def get_converted_file_contents(file_path: Path) -> dict[str, Any]: |
There was a problem hiding this comment.
Putting something in __all__ signals that it is part of the public API and intended for external use. It is and should only be used inside this package I believe so doesn't make sense to.
olliesilvester
left a comment
There was a problem hiding this comment.
Thanks, I'm happy with this. It'll probably become obvious if the structure is sensible as we start using all these bits a bit more
|
@jacob720 you good with me merging this now? |
|
Yeah looks good! |
Fixes #164