Repository: nf-core/tools

Issue:
Cirular import of ModuleLint
<!--
# nf-core/tools bug report

Hi there!

Thanks for telling us about a problem with the nf-core/tools package.
Please delete this text and anything that's not relevant from the template below:
-->

## Description of the bug

<!-- A clear and concise description of what the bug is. -->

I cannot run individual unittests from vscode due to a circular import. 

## Steps to reproduce

Steps to reproduce the behaviour:

```python
import nf_core.modules.lint
```
```pytb
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-90faefaf9286> in <module>
----> 1 import nf_core.modules.lint

~/projects/2020/nf-core-tools/nf_core/modules/__init__.py in <module>
      2 from .create import ModuleCreate
      3 from .test_yml_builder import ModulesTestYmlBuilder
----> 4 from .lint import ModuleLint
      5 from .bump_versions import ModuleVersionBumper
      6 from .module_utils import ModuleException

~/projects/2020/nf-core-tools/nf_core/modules/lint/__init__.py in <module>
     24 import rich
     25 from nf_core.utils import rich_force_colors
---> 26 from nf_core.lint.pipeline_todos import pipeline_todos
     27 import sys
     28 

~/projects/2020/nf-core-tools/nf_core/lint/__init__.py in <module>
     22 import nf_core.lint_utils
     23 from nf_core.lint_utils import console
---> 24 from nf_core.modules import ModuleLint
     25 
     26 log = logging.getLogger(__name__)

ImportError: cannot import name 'ModuleLint' from partially initialized module 'nf_core.modules' (most likely due to a circular import) (/home/sturm/projects/2020/nf-core-tools/nf_core/modules/__init__.py)
```

## Expected behaviour

<!-- A clear and concise description of what you expected to happen. -->

## System

- Hardware: desktop
- Executor: local
- OS: Arch linux
- Version of nf-core/tools: checked out at `8635612b3ee3b1e414414553c4fd72cb048464d3`
- Python version: 3.8.10

## Nextflow Installation

irrelevant




Discussion:
Sorry, I hit the submit button too early. The issue is now complete. 

Resolving patch:
diff --git a/nf_core/lint/__init__.py b/nf_core/lint/__init__.py
--- a/nf_core/lint/__init__.py
+++ b/nf_core/lint/__init__.py
@@ -20,8 +20,8 @@
 
 import nf_core.utils
 import nf_core.lint_utils
+import nf_core.modules.lint
 from nf_core.lint_utils import console
-from nf_core.modules.lint import ModuleLint
 
 log = logging.getLogger(__name__)
 
@@ -44,7 +44,9 @@ def run_linting(
 
     # Verify that the requested tests exist
     if key:
-        all_tests = set(PipelineLint._get_all_lint_tests(release_mode)).union(set(ModuleLint._get_all_lint_tests()))
+        all_tests = set(PipelineLint._get_all_lint_tests(release_mode)).union(
+            set(nf_core.modules.lint.ModuleLint._get_all_lint_tests())
+        )
         bad_keys = [k for k in key if k not in all_tests]
         if len(bad_keys) > 0:
             raise AssertionError(
@@ -66,7 +68,7 @@ def run_linting(
     lint_obj._list_files()
 
     # Create the modules lint object
-    module_lint_obj = ModuleLint(pipeline_dir)
+    module_lint_obj = nf_core.modules.lint.ModuleLint(pipeline_dir)
 
     # Verify that the pipeline is correctly configured
     try:
@@ -77,7 +79,7 @@ def run_linting(
     # Run only the tests we want
     if key:
         # Select only the module lint tests
-        module_lint_tests = list(set(key).intersection(set(ModuleLint._get_all_lint_tests())))
+        module_lint_tests = list(set(key).intersection(set(nf_core.modules.lint.ModuleLint._get_all_lint_tests())))
     else:
         # If no key is supplied, run the default modules tests
         module_lint_tests = ("module_changes", "module_version")


Test patch: