Skip to content

Commit c3c0634

Browse files
author
Alan Christie
committed
Compose now adds nf config
Jote now checks for local nf config
1 parent ae96b1f commit c3c0634

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/jote/compose.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
cpus: {cpus}.0
3636
"""
3737

38+
_NF_CONFIG_CONTENT: str = """
39+
docker {
40+
enabled = true
41+
runOptions = '-u $(id -u):$(id -g)'
42+
}
43+
"""
44+
3845

3946
def _get_docker_compose_version() -> str:
4047

@@ -66,6 +73,7 @@ def __init__(self, collection: str,
6673
job: str,
6774
test: str,
6875
image: str,
76+
image_type: str,
6977
memory: str,
7078
cores: int,
7179
project_directory: str,
@@ -85,6 +93,7 @@ def __init__(self, collection: str,
8593
self._job: str = job
8694
self._test: str = test
8795
self._image: str = image
96+
self._image_type: str = image_type
8897
self._cores: int = cores
8998
self._project_directory: str = project_directory
9099
self._working_directory: str = working_directory
@@ -121,7 +130,9 @@ def create(self) -> str:
121130
Compose._COMPOSE_VERSION = _get_docker_compose_version()
122131
print(f'# docker-compose ({Compose._COMPOSE_VERSION})')
123132

124-
# Make the test directory...
133+
# Make the test directory
134+
# (where the test is launched from)
135+
# and the project directory (a /project sud-directory of test)
125136
test_path = self.get_test_path()
126137
project_path: str = self.get_test_project_path()
127138
inst_path: str = f'{project_path}/{INSTANCE_DIRECTORY}'
@@ -152,6 +163,14 @@ def create(self) -> str:
152163
with open(compose_path, 'wt', encoding='UTF-8') as compose_file:
153164
compose_file.write(compose_content)
154165

166+
if self._image_type == 'nextflow':
167+
# Write a nextflow config to the project path
168+
# (this is where the non-container-based nextflow is executed)
169+
# and where nextflow will, by default, look for the config.
170+
nf_cfg_path: str = f'{project_path}/nextflow.config'
171+
with open(nf_cfg_path, 'wt', encoding='UTF-8') as nf_cfg_file:
172+
nf_cfg_file.write(_NF_CONFIG_CONTENT)
173+
155174
print('# Created')
156175

157176
return project_path

src/jote/jote.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
_IMAGE_TYPE_NEXTFLOW: str = 'nextflow'
4141
_DEFAULT_IMAGE_TYPE: str = _IMAGE_TYPE_SIMPLE
4242

43+
# User HOME directory.
44+
# Used to check for netflow files if nextflow is executed.
45+
# The user CANNOT have any pf their own nextflow config.
46+
_USR_HOME: str = os.environ.get('HOME', '')
47+
4348

4449
def _print_test_banner(collection: str,
4550
job_name: str,
@@ -304,6 +309,17 @@ def _run_nextflow(command: str, project_path: str)\
304309
assert command
305310
assert project_path
306311

312+
# The user cannot have a nextflow config in their home directory.
313+
# Nextflow looks here and any config will be merged with the test config.
314+
if _USR_HOME:
315+
home_config: str = os.path.join(_USR_HOME, '.nextflow', 'config')
316+
if os.path.exists(home_config) and os.path.isfile(home_config):
317+
print('! FAILURE')
318+
print('! A nextflow test but'
319+
f' you have your own config file ({home_config})')
320+
print('! You cannot test Jobs and have your own config file')
321+
return 1, '', ''
322+
307323
cwd = os.getcwd()
308324
os.chdir(project_path)
309325

@@ -502,6 +518,7 @@ def _test(args: argparse.Namespace,
502518
job,
503519
job_test_name,
504520
job_image,
521+
job_image_type,
505522
job_image_memory,
506523
job_image_cores,
507524
job_project_directory,

0 commit comments

Comments
 (0)