Skip to content

Commit 0dd6ac0

Browse files
authored
Merge pull request #40 from INCATools/allow-docker
Allow docker to be used in builds of sqlite
2 parents 52b1d67 + d0f2f66 commit 0dd6ac0

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

src/semsql/builder/builder.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
1+
import logging
2+
import os
13
import subprocess
4+
from dataclasses import field
25
from pathlib import Path
6+
from typing import Optional
37

48
from sqlalchemy import create_engine
59
from sqlalchemy.orm import sessionmaker
610
import requests
711

812
this_path = Path(__file__).parent
913

10-
def make(target: str):
14+
15+
class DockerConfig:
16+
"""
17+
Configuration for running ODK Docker image
18+
"""
19+
odk_version: str = None ## not used yet
20+
memory: str = None
21+
22+
23+
def make(target: str, docker_config: Optional[DockerConfig] = None):
1124
"""
1225
Builds a target such as a SQLite file using the build.Makefile
1326
1427
:param target: Make target
28+
:param docker_config: if passed, use ODK docker with the specific config
1529
"""
16-
subprocess.run(['make', '-f', this_path / 'build.Makefile', target])
30+
path_to_makefile = str(this_path / 'build.Makefile')
31+
if docker_config is not None:
32+
mem = docker_config.memory
33+
if mem is None:
34+
mem = '4g'
35+
pwd = os.getcwd()
36+
pre = ['docker', 'run',
37+
'-m', mem,
38+
'-v', f'{pwd}/:/work',
39+
'-v', f'{this_path}/:/builder',
40+
'-w', '/work',
41+
'--rm', '-ti', 'obolibrary/odkfull']
42+
path_to_makefile = '/builder/build.Makefile'
43+
else:
44+
pre = []
45+
cmd = pre + ['make', target, '-f', path_to_makefile]
46+
logging.info(f'CMD={cmd}')
47+
subprocess.run(cmd)
48+
1749

1850
def db_from_owl(input: str) -> str:
1951
"""
@@ -29,6 +61,7 @@ def db_from_owl(input: str) -> str:
2961
else:
3062
raise ValueError(f'Path must be an OWL file')
3163

64+
3265
def download_obo_sqlite(ontology: str, destination: str):
3366
"""
3467
Downloads pre-made SQLite file
@@ -41,6 +74,7 @@ def download_obo_sqlite(ontology: str, destination: str):
4174
r = requests.get(url, allow_redirects=True)
4275
open(destination, 'wb').write(r.content)
4376

77+
4478
def connect(owl_file: str):
4579
"""
4680
Generates a SQLite connection to an OWL file
@@ -52,4 +86,4 @@ def connect(owl_file: str):
5286
engine = create_engine(f'sqlite:///{db}')
5387
Session = sessionmaker(bind=engine)
5488
session = Session()
55-
return session
89+
return session

src/semsql/builder/cli.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ def main(verbose: int, quiet: bool):
2626

2727
@main.command()
2828
@click.argument('path')
29-
def make(path):
29+
@click.option('--docker/--no-docker',
30+
default=False,
31+
show_default=True,
32+
help="Uses ODK docker image"
33+
)
34+
def make(path, docker):
3035
"""
3136
Makes a specified target, such as a db file
3237
@@ -36,7 +41,11 @@ def make(path):
3641
3742
(assumes envo.owl is in the same folder)
3843
"""
39-
builder.make(path)
44+
if docker:
45+
docker_config = builder.DockerConfig()
46+
else:
47+
docker_config = None
48+
builder.make(path, docker_config=docker_config)
4049

4150

4251
@main.command()

0 commit comments

Comments
 (0)