UCL / SkullBaseNavigation

Other
2 stars 1 forks source link

Discussion: Workaround the impossibility to use relative imports in Python scripts #64

Open tdowrick opened 3 years ago

tdowrick commented 3 years ago

In GitLab by @RolandGuichard on Jun 11, 2019, 14:33

It looks like from here and here that relative imports are impossible when running a top-level script in Python.

This caused us to move the config.py from skullbasenavigation/ to sbn/ which is not ideal.

What would be a good workaround this ? Two ideas have emerged:

Since we need some kind of launcher, I was wondering if we could actually come with a solution that would reuse the launch idea and resolve the relative imports ?

tdowrick commented 3 years ago

In GitLab by @RolandGuichard on Jun 11, 2019, 14:34

@ThomasDowrick and @AnastasisGeorgoulas do you have comments/suggestions on this ? I am happy to investigate that solution if you think it worth.

tdowrick commented 3 years ago

In GitLab by @AnastasisGeorgoulas on Jun 14, 2019, 09:05

Putting the config in /sbn might be the simplest solution.

I've tried creating a wrapper (leaving the config in the same location) but am still running into the same problem.

I don't think creating an entrypoint would help, because we don't really have an installable package - although we could try installing it for Slicer's python.

tdowrick commented 3 years ago

In GitLab by @RolandGuichard on Jun 14, 2019, 09:09

Just to be sure, install what in Slicer's Python ?

tdowrick commented 3 years ago

In GitLab by @AnastasisGeorgoulas on Jun 14, 2019, 09:40

I meant turning our code into a python package (so create a setup.py) and installing it with pip. Then I think the imports should work more easily (even without defining an entrypoint).

tdowrick commented 3 years ago

In GitLab by @RolandGuichard on Jun 14, 2019, 09:43

But wasn't the issue about pipping the crcmode in Slicer ? I don't see yet how packaging the skullbasenavigation will solve this (unless I miss something).

tdowrick commented 3 years ago

In GitLab by @AnastasisGeorgoulas on Jun 14, 2019, 09:46

These are separate issues. Installing crcmod is a requirement for installing sksurgery-bk (which in turn would be a requirement of this package, if we make one). But the problem here is with our code finding the configuration file and where to put that.

tdowrick commented 3 years ago

In GitLab by @RolandGuichard on Jun 14, 2019, 10:11

Yes, sure. But maybe a reasonable mid-point solution, as we discussed, would be to run the pyIGTLink server as a process in the launcher and leave the config in sbn. ¯_(ツ)_/¯.