11#!/usr/bin/env python3
22
33import sys
4+
45sys .dont_write_bytecode = True
56import os
67import shutil
1011import glob
1112import platform
1213
13-
1414PROJ_ROOT = pathlib .Path (__file__ ).parent
1515
1616
@@ -20,13 +20,12 @@ def _run(*args, env=None, cwd=None):
2020 On error, exit with child's return code.
2121 """
2222 cwd = cwd or PROJ_ROOT
23- args = [str (arg ) for arg in args ]
2423 sys .stderr .write ('[CMD] ' )
2524 if env is not None :
2625 env_str = ' ' .join (f'{ k } ={ shlex .quote (v )} ' for k , v in env .items ())
2726 sys .stderr .write (f'{ env_str } ' )
2827 env = {** os .environ , ** env }
29- escaped_cmd = ' ' .join (shlex .quote (arg ) for arg in args )
28+ escaped_cmd = ' ' .join (shlex .quote (str ( arg ) ) for arg in args )
3029 sys .stderr .write (f'{ escaped_cmd } \n ' )
3130 ret_code = subprocess .run (args , cwd = str (cwd ), env = env ).returncode
3231 if ret_code != 0 :
@@ -53,11 +52,11 @@ def _arg2bool(arg):
5352 return arg .lower () in ('true' , 'yes' , '1' )
5453
5554
56- COMMANDS = set ()
55+ COMMANDS = []
5756
5857
5958def command (fn ):
60- COMMANDS .add (fn .__name__ )
59+ COMMANDS .append (fn .__name__ )
6160 return fn
6261
6362
@@ -67,28 +66,28 @@ def build():
6766
6867
6968@command
70- def serve (port = None ):
71- port = port or 8000
72- docs_dir = PROJ_ROOT / 'build' / 'docs'
73- _run ('python3' , '-m' , 'http.server' , port , cwd = docs_dir )
69+ def test (all = False , patch_path = '1' , * args ):
70+ env = {'TEST_QUESTDB_PATCH_PATH' : patch_path }
71+ if _arg2bool (all ):
72+ env ['TEST_QUESTDB_INTEGRATION' ] = '1'
73+ _run ('python3' , 'test/test.py' , '-v' , * args ,
74+ env = env )
7475
7576
7677@command
7778def doc (http_serve = False , port = None ):
7879 _run ('python3' , '-m' , 'sphinx.cmd.build' ,
79- '-b' , 'html' , 'docs' , 'build/docs' ,
80- env = {'PYTHONPATH' : str (PROJ_ROOT / 'src' )})
80+ '-b' , 'html' , 'docs' , 'build/docs' ,
81+ env = {'PYTHONPATH' : str (PROJ_ROOT / 'src' )})
8182 if _arg2bool (http_serve ):
8283 serve (port )
8384
8485
8586@command
86- def test (all = False , patch_path = '1' , * args ):
87- env = {'TEST_QUESTDB_PATCH_PATH' : patch_path }
88- if _arg2bool (all ):
89- env ['TEST_QUESTDB_INTEGRATION' ] = '1'
90- _run ('python3' , 'test/test.py' , '-v' , * args ,
91- env = env )
87+ def serve (port = None ):
88+ port = port or 8000
89+ docs_dir = PROJ_ROOT / 'build' / 'docs'
90+ _run ('python3' , '-m' , 'http.server' , port , cwd = docs_dir )
9291
9392
9493@command
@@ -105,11 +104,16 @@ def cibuildwheel(*args):
105104 # Python version.
106105 python = '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3'
107106 _run (python , '-m' ,
108- 'cibuildwheel' ,
109- '--platform' , plat ,
110- '--output-dir' , 'dist' ,
111- '--archs' , platform .machine (),
112- * args )
107+ 'cibuildwheel' ,
108+ '--platform' , plat ,
109+ '--output-dir' , 'dist' ,
110+ '--archs' , platform .machine (),
111+ * args )
112+
113+
114+ @command
115+ def cw (* args ):
116+ cibuildwheel (args )
113117
114118
115119@command
@@ -133,6 +137,17 @@ def clean():
133137 _rm (PROJ_ROOT / 'src' , '**/*.html' )
134138
135139
140+ @command
141+ def venv ():
142+ if pathlib .Path ('venv' ).exists ():
143+ sys .stderr .write ('venv already exists, delete it, or run command clean\n ' )
144+ return
145+ _run ('python3' , '-m' , 'venv' , 'venv' )
146+ _run ('venv/bin/python3' , '-m' , 'pip' , 'install' , '-U' , 'pip' )
147+ _run ('venv/bin/python3' , '-m' , 'pip' , 'install' , '-r' , 'dev_requirements.txt' )
148+ sys .stdout .write ('NOTE: remember to activate the environment: source venv/bin/activate\n ' )
149+
150+
136151def main ():
137152 if len (sys .argv ) < 2 :
138153 sys .stderr .write ('Usage: python3 proj.py <command>\n ' )
0 commit comments