gwforg / gwf

A flexible, pragmatic workflow tool.
https://gwf.app/
GNU General Public License v3.0
31 stars 12 forks source link

Import problem with gwf 1.8.1 #398

Closed simondrue closed 1 year ago

simondrue commented 1 year ago

Hi,

After updating to gwf 1.8.1 I've had the following problem when importing functions in other files:

The structure for my current project is as follows:

project
├── output
│   └── ...
├── README.md
├── src
│   ├── __init__.py
│   ├── nanopore_templates.py
│   └── wf_utils.py
└── workflow.py

When running gwf status I get the following error:

Traceback (most recent call last):
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/bin/gwf", line 8, in <module>
    sys.exit(main())
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/click/decorators.py", line 38, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/gwf/plugins/status.py", line 169, in status
    workflow = Workflow.from_config(obj)
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/gwf/workflow.py", line 236, in from_config
    return cls.from_path(config["file"])
  File "/home/simond/miniconda3/envs/nanopore_splice_variant_pipeline/lib/python3.7/site-packages/gwf/workflow.py", line 223, in from_path
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/faststorage/project/MomaDiagnosticsHg38/NO_BACKUP/users/simond/nanopore/nanopore-splice-variant-pipeline-N411/workflow.py", line 15, in <module>
    from src.nanopore_templates import length_dist_from_fastqs
ModuleNotFoundError: No module named 'src'

This has worked for previous versions of gwf, and is in line with the documentation found here: https://gwf.app/guide/patterns/#dynamically-generating-a-workflow and the error does not occur when running python workflow.py.

Thanks for a great tool! 🚀

Kind regard Simon

dansondergaard commented 1 year ago

Thank you for reporting this! I'm aware of the problem and will fix it when I have time to roll a new release. Until then you can fix it by inserting this snippet at the top of your workflow file:

import os
import os.path
sys.path.insert(0, os.path.dirname(__file__))
dansondergaard commented 1 year ago

Fixed in 1.8.2.