nils-braun / b2luigi

Task scheduling and batch running for basf2 jobs made simple
GNU General Public License v3.0
17 stars 11 forks source link

v0.9.0 has a circular import error #188

Closed MarcelHoh closed 1 year ago

MarcelHoh commented 1 year ago

In v0.9.0 I receive a circular import error:

  File "test.py", line 1, in <module>
    import b2luigi
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/__init__.py", line 5, in <module>
    from b2luigi.cli.process import process
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/cli/process.py", line 2, in <module>
    from b2luigi.cli import runner
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/cli/runner.py", line 7, in <module>
    from b2luigi.batch.workers import SendJobWorkerSchedulerFactory
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/batch/workers.py", line 8, in <module>
    from b2luigi.batch.processes.gbasf2 import Gbasf2Process
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/batch/processes/gbasf2.py", line 20, in <module>
    from b2luigi.basf2_helper.utils import get_basf2_git_hash
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/basf2_helper/__init__.py", line 2, in <module>
    from b2luigi.basf2_helper.tasks import (Basf2FileMergeTask, Basf2nTupleMergeTask, Basf2PathTask, Basf2Task, HaddTask,
  File "/afs/desy.de/user/h/hohmann/.local/lib/python3.8/site-packages/b2luigi/basf2_helper/tasks.py", line 14, in <module>
    class Basf2Task(b2luigi.DispatchableTask):
AttributeError: partially initialized module 'b2luigi' has no attribute 'DispatchableTask' (most likely due to a circular import)

I tested the same script on version 0.8.2 and did not get an error. A simple test script:

import b2luigi
class testTask(b2luigi.Task):
    param = b2luigi.ListParameter(default=[0,1,2], hashed=True)

    def output(self):
        yield self.add_to_output('test.txt')
    def run(self):
        with open(self.get_output_file_name('test.txt'), 'w') as f:
            f.write('test')

if __name__ == '__main__':
    b2luigi.process(testTask())

I suspect it is due to the reshuffling of imports that was done in https://github.com/nils-braun/b2luigi/commit/b80fbedb8a78633524f1eb326ca56f314599cb5d.

MarcelHoh commented 1 year ago

A simple fix is to move the process import (https://github.com/nils-braun/b2luigi/blob/main/b2luigi/__init__.py#L5) down a few lines, to the last line of that block.

meliache commented 1 year ago

Thanks for reporting. I mistakenly configured my editor to automatically sort imports with isort when I edit a file. I should disable that for b2luigi. Somehow I commited that change when bumping the version and it seems I wasn't careful about looking at the test results for that.