Skip to content

Commit 10a005d

Browse files
author
Lukas Heumos
authored
Merge pull request #10 from qbicsoftware/feature/#8
FIX/#8
2 parents ac713e3 + 522dc2c commit 10a005d

6 files changed

Lines changed: 72 additions & 38 deletions

File tree

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ sudo: required
22
language: python
33
dist: xenial
44
python:
5-
- '2.7'
6-
- '3.4'
7-
- '3.5'
85
- '3.6'
96
- '3.7'
107
install:

rmageddon/lint.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ def lint_rproject(self):
5353
with click.progressbar(check_functions, label='Running R projects tests', item_show_func=repr) as fnames:
5454
for fname in fnames:
5555
getattr(self, fname)()
56-
if len(self.failed) > 0:
57-
logging.error("Found test failures in '{}', halting lint run.".format(fname))
58-
break
5956

6057
def check_files_exist(self):
6158
""" Check, that files like Dockerfile and the conda
@@ -140,7 +137,7 @@ def check_dockerfile(self):
140137
]
141138
for label in expected_labels:
142139
if not any(label == x for x in labels.keys()):
143-
self.failed.append((2, 'You havent\'t set LABEL \'{}\' in the Dockerfile.'.format(label)))
140+
self.failed.append((2, f'You havent\'t set LABEL \'{label}\' in the Dockerfile.'))
144141
return
145142

146143
# 3. Check if labels are empty
@@ -193,9 +190,7 @@ def check_conda_environment(self):
193190
# Check that the mandatory conda env declarations are there
194191
for declaration in mand_conda_settings:
195192
if not self.conda_config.get(declaration):
196-
self.failed.append((3, "The conda env declaration \'{dec}\' is missing.".format(
197-
dec=declaration
198-
)))
193+
self.failed.append((3, f"The conda env declaration \'{declaration}\' is missing."))
199194
return
200195

201196
# Check the name regex
@@ -212,27 +207,28 @@ def check_conda_environment(self):
212207
if not ch in self.conda_config.get('channels')])
213208

214209
for ch in missing_channels:
215-
self.failed.append((3, "Channel {ch} was not defined.".format(ch=ch)))
210+
self.failed.append((3, f"Channel {ch} was not defined."))
216211
return
217212

218-
# Check that the dependency for r-base is there, and a version is set.
213+
# Check that the dependency for r-base is there
219214
rbase = list([basepkg for basepkg in self.conda_config.get("dependencies") if 'r-base' in basepkg])
220215
if not rbase:
221216
self.failed.append((3, "Could not find the \'r-base\' dependency."))
222217
return
223218

224-
# Check that a version is given for the r-base pkg
225-
if not '=' in rbase[0]:
226-
self.failed.append((3, "Could not determine that \'r-base\' has a version tag."))
227-
return
228-
229-
# Check that the version is numeric
230-
version = rbase[0].strip().split('=')[-1].replace('.', '')
231-
if not version.isdigit():
232-
self.failed.append((3, "The version tag \'{tag}\' was not numeric!".format(
233-
tag=rbase[0].strip().split('=')[-1]
234-
)))
235-
return
219+
# Check that every dependency has a version tag and that it's numerical
220+
dependencies = list([basepkg for basepkg in self.conda_config.get("dependencies")])
221+
for dependency in dependencies:
222+
strip = dependency.strip().split('=')
223+
version = strip[-1] if len(strip) > 1 else None
224+
if not version:
225+
self.failed.append((3, f"No version was supplied for {dependency}"
226+
))
227+
return
228+
cleaned_version = version.replace('.', '')
229+
if not cleaned_version.isdigit():
230+
self.failed.append((3, f"The version tag \'{version}\' was not numeric!"))
231+
return
236232

237233
self.passed.append((3, 'The conda environment seems to be OK.'))
238234

@@ -242,10 +238,10 @@ def pf(self, file_path):
242238

243239
def print_results(self):
244240
logging.info("===========\n LINT RESULTS\n=================\n" +
245-
"{0:>4} build steps passed".format(len(self.passed)) +
246-
"{0:>4} build steps had warnings".format(len(self.warned)) +
247-
"{0:>4} build steps failed".format(len(self.failed))
248-
)
241+
"{0:>4} build steps passed".format(len(self.passed)) +
242+
"{0:>4} build steps had warnings".format(len(self.warned)) +
243+
"{0:>4} build steps failed".format(len(self.failed))
244+
)
249245
if len(self.passed) > 0:
250246
logging.debug(
251247
"Test Passed:\n {}".format("\n ".join(["#{}: {}".format(eid, msg) for eid, msg in self.passed])))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44
import sys
55

6-
version = '0.2.1'
6+
version = '0.2.2'
77

88
with open('README.md') as f:
99
readme = f.read()

tests/lint_examples/awesome_working_example/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ channels:
55
- defaults
66
dependencies:
77
- r-base=3.4.3
8-
- r-ggplot2
8+
- r-ggplot2=3.2.0

tests/lint_examples/minimal_working_example/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ channels:
55
- defaults
66
dependencies:
77
- r-base=3.4.3
8-
- r-ggplot2
8+
- r-ggplot2=3.2.0

tests/test_lint.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def listfiles(path):
2323
files_found = []
2424
for (_, _, files) in os.walk(path):
2525
files_found.extend(files)
26+
2627
return files_found
2728

2829

@@ -92,7 +93,7 @@ def test_dockerfile_without_base_image(self):
9293
"""
9394
lint_obj = lint.RContainerLint(PATH_BAD_DOCKERFILE)
9495
lint_obj.lint_rproject()
95-
expectations = {"failed": 1, "warned": 2, "passed": 1}
96+
expectations = {"failed": 2, "warned": 2, "passed": 1}
9697
self.assess_lint_status(lint_obj, **expectations)
9798

9899
def test_rpackage_empty_warn(self):
@@ -141,14 +142,13 @@ def test_conda_env_file_for_channels_and_fail(self):
141142
self.assess_lint_status(lint_obj, **expectations)
142143

143144
def test_conda_env_file_no_rversion_tag(self):
144-
""" Check that the conda env file has a name property and that it
145-
follows a certain regex, fail if not """
145+
""" Check that the r-version tag is set in the conda environment file. """
146146
lint_obj = lint.RContainerLint(PATH_BAD_EXAMPLE)
147147
lint_obj.check_files_exist()
148148
yaml = YAML()
149149
lint_obj.conda_config = yaml.load(
150150
"""
151-
name: qbicsoftware-QTEST-ranalyses-1.0
151+
name: Qtest000_a_ranalysis
152152
channels:
153153
- bioconda
154154
- r
@@ -163,14 +163,13 @@ def test_conda_env_file_no_rversion_tag(self):
163163
self.assess_lint_status(lint_obj, **expectations)
164164

165165
def test_conda_env_file_wrong_rversion_tag(self):
166-
""" Check that the conda env file has a name property and that it
167-
follows a certain regex, fail if not """
166+
""" Check that the conda env file has a NUMERICAL version tag for r-base"""
168167
lint_obj = lint.RContainerLint(PATH_BAD_EXAMPLE)
169168
lint_obj.check_files_exist()
170169
yaml = YAML()
171170
lint_obj.conda_config = yaml.load(
172171
"""
173-
name: qbicsoftware-QTEST-ranalyses-1.0
172+
name: Qtest000_a_ranalysis
174173
channels:
175174
- bioconda
176175
- r
@@ -183,3 +182,45 @@ def test_conda_env_file_wrong_rversion_tag(self):
183182
lint_obj.check_conda_environment()
184183
expectations = {"failed": 1, "warned": 2, "passed": 2}
185184
self.assess_lint_status(lint_obj, **expectations)
185+
186+
def test_missing_dependency_version(self):
187+
""" Check that every dependency has a version property."""
188+
lint_obj = lint.RContainerLint(PATH_BAD_EXAMPLE)
189+
lint_obj.check_files_exist()
190+
yaml = YAML()
191+
lint_obj.conda_config = yaml.load(
192+
"""
193+
name: Qtest000_a_ranalysis
194+
channels:
195+
- bioconda
196+
- r
197+
- defaults
198+
dependencies:
199+
- r-base=1.0
200+
- r-ggplot2
201+
"""
202+
)
203+
lint_obj.check_conda_environment()
204+
expectations = {"failed": 1, "warned": 2, "passed": 2}
205+
self.assess_lint_status(lint_obj, **expectations)
206+
207+
def test_bad_dependency_signature(self):
208+
""" Check that every dependency has a version property and that it's NUMERICAL."""
209+
lint_obj = lint.RContainerLint(PATH_BAD_EXAMPLE)
210+
lint_obj.check_files_exist()
211+
yaml = YAML()
212+
lint_obj.conda_config = yaml.load(
213+
"""
214+
name: Qtest000_a_ranalysis
215+
channels:
216+
- bioconda
217+
- r
218+
- defaults
219+
dependencies:
220+
- r-base=1.0
221+
- r-ggplot2=2.0dev
222+
"""
223+
)
224+
lint_obj.check_conda_environment()
225+
expectations = {"failed": 1, "warned": 2, "passed": 2}
226+
self.assess_lint_status(lint_obj, **expectations)

0 commit comments

Comments
 (0)