basyx-python-sdk icon indicating copy to clipboard operation
basyx-python-sdk copied to clipboard

server: entrypoints `run_*.py` are written as scripts

Open hpoeche opened this issue 1 month ago • 1 comments

To create the Python WSGI application, the docker images execute a script from server/app/services (run_repository.py, run_registry.py, run_discovery.py) which sets the global application variable. These script's code is written directly to the file and is not wrapped inside functions or a if __name__ == "__main__" guard. Therefore this code can only and will always be executed when the script is imported (e.g. import app.services.run_repositroy). This complicates unit testing unnecessary, because it requires re-importing the script over and over again.

We should wrap the code that lives at file level today inside a main() function and only execute it, when the script is run directly. This could look equivalent to this:

def main() -> WSGIApp:
	...
	
if __name__ == "__main__":
	application = main()

hpoeche avatar Oct 05 '26 09:10 hpoeche

While restructuring these scripts: setup_logger() is identical in run_repository.py and run_registry.py, and build_storage() is nearly identical (the repository variant also returns the DictSupplementaryFileContainer):

https://github.com/eclipse-basyx/basyx-python-sdk/blob/2773ac069d3163cbbd32c3c634813d38bbe521ad/server/app/services/run_repository.py#L25-L40 https://github.com/eclipse-basyx/basyx-python-sdk/blob/2773ac069d3163cbbd32c3c634813d38bbe521ad/server/app/services/run_registry.py#L22-L37

Moving them into one shared module would leave a single copy.

zrgt avatar Oct 22 '26 15:10 zrgt