diff --git a/rmageddon/lint.py b/rmageddon/lint.py index 8131ce2..86b88b3 100644 --- a/rmageddon/lint.py +++ b/rmageddon/lint.py @@ -82,7 +82,10 @@ def check_files_exist(self): self.passed.append((1, 'Dir {} found.'.format(files))) if os.path.isfile(self.pf('environment.yml')): - with open(self.pf('environment.yml'), 'r') as fh: + self.load_environment_config() + + def load_environment_config(self): + with open(self.pf('environment.yml'), 'r') as fh: yaml = YAML() self.conda_config = yaml.load(fh) @@ -187,11 +190,11 @@ def check_conda_environment(self): 'conda-forge', 'bioconda' ] - + # Check that the mandatory conda env declarations are there - for declaration in mand_conda_settings: - if not self.conda_config.get(declaration): - self.failed.append((3, f"The conda env declaration \'{declaration}\' is missing.")) + for setting in mand_conda_settings: + if not self.conda_config.get(setting): + self.failed.append((3, f"The conda environment setting \'{setting}\' is missing.")) return # Check the name regex @@ -203,10 +206,9 @@ def check_conda_environment(self): Make sure, it follows the guidelines.")) return - # Check that channels 'default' and 'r' are present + # Find missing channels missing_channels = list([ch for ch in mand_channel_settings if not ch in self.conda_config.get('channels')]) - for ch in missing_channels: self.failed.append((3, f"Channel {ch} was not defined.")) return diff --git a/tests/lint_examples/bad_example/environment.yml b/tests/lint_examples/bad_example/environment.yml index 214ea4f..5cad9f0 100644 --- a/tests/lint_examples/bad_example/environment.yml +++ b/tests/lint_examples/bad_example/environment.yml @@ -1,4 +1,4 @@ -name: qbicsoftware-dd-ranalyses-1.0 +name: qtest000_1_ranalysis_123 channels: - bioconda - r diff --git a/tests/test_lint.py b/tests/test_lint.py index ef17cca..5a2d02b 100644 --- a/tests/test_lint.py +++ b/tests/test_lint.py @@ -103,6 +103,15 @@ def test_rpackage_empty_warn(self): expectations = {"failed": 1, "warned": 0, "passed": 0} self.assess_lint_status(lint_obj, **expectations) + def test_semantic_version_container_fail(self): + """ If the container version does not follow the sematic versioning + style-guide, the linting should fail.""" + lint_obj = lint.RContainerLint(PATH_BAD_EXAMPLE) + lint_obj.load_environment_config() + lint_obj.check_conda_environment() + expectations = {"failed": 1, "warned": 0, "passed": 0} + self.assess_lint_status(lint_obj, **expectations) + def test_rpackage_pass(self): """ Check if the rpackages.txt is formatted correctly """ lint_obj = lint.RContainerLint(PATH_MINIMAL_WORKING_EXAMPLE)