1+ import logging
2+ import os
13import subprocess
4+ from dataclasses import field
25from pathlib import Path
6+ from typing import Optional
37
48from sqlalchemy import create_engine
59from sqlalchemy .orm import sessionmaker
610import requests
711
812this_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
1850def 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+
3265def 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+
4478def 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
0 commit comments