Skip to content

Commit 5e4e22a

Browse files
authored
Merge pull request #79 from robfalck/uv
Added some options for compatibility with brew and uv.
2 parents cd73019 + e3ac029 commit 5e4e22a

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

build_pyoptsparse.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'uninstall': False,
3737
'pyoptsparse_version': None, # Parsed pyOptSparse version, set by finish_setup()
3838
'make_name': 'make',
39-
'fall_back': False
39+
'fall_back': False,
40+
'pip_cmd': 'pip'
4041
}
4142

4243
# Information about the host, status, and constants
@@ -184,6 +185,9 @@ def process_command_line():
184185
parser.add_argument("-p", "--prefix",
185186
help=f"Where to install if not a conda/venv environment. Default: {opts['prefix']}",
186187
default=opts['prefix'])
188+
parser.add_argument("--pip-cmd",
189+
help=f"pip command to use. Set to to --pip-cmd=='uv pip' if using uv. Default: {opts['pip_cmd']}",
190+
default=opts['pip_cmd'])
187191
parser.add_argument("-s", "--snopt-dir",
188192
help="Include SNOPT from SNOPT-DIR. Default: no SNOPT",
189193
default=opts['snopt_dir'])
@@ -250,6 +254,7 @@ def process_command_line():
250254

251255
opts['prefix'] = args.prefix
252256
opts['build_pyoptsparse'] = not args.no_install
257+
opts['pip_cmd'] = args.pip_cmd
253258
opts['snopt_dir'] = args.snopt_dir
254259
opts['hsl_tar_file'] = args.hsl_tar_file
255260
opts['verbose'] = args.verbose
@@ -487,11 +492,11 @@ def pip_install(pip_install_args, pkg_desc='packages'):
487492
Each token of the command line is a separate member of the list. The
488493
is prepended with 'python -m pip install'; '-q' is added when not verbose.
489494
"""
490-
cmd_list = ['python', '-m', 'pip', 'install']
495+
cmd_list = opts['pip_cmd'].split() + ['install']
491496
if opts['verbose'] is False:
492497
cmd_list.append('-q')
493498
cmd_list.extend(pip_install_args)
494-
note(f'Installing {pkg_desc} with pip')
499+
note(f'Installing {pkg_desc} with {opts["pip_cmd"]}')
495500
run_cmd(cmd_list)
496501
note_ok()
497502

@@ -1158,7 +1163,7 @@ def check_sanity():
11581163
check_make(errors)
11591164
required_cmds.extend(['git', os.environ['CC'], os.environ['CXX'], os.environ['FC']])
11601165
if opts['build_pyoptsparse'] is True:
1161-
required_cmds.extend(['pip', 'swig'])
1166+
required_cmds.extend(['swig'])
11621167

11631168
if opts['compile_required'] is False:
11641169
required_cmds.append(opts['conda_cmd'])
@@ -1197,17 +1202,17 @@ def check_sanity():
11971202

11981203
def select_intel_compilers():
11991204
""" Set environment variables to use Intel compilers. """
1200-
os.environ['CC'] = 'icc'
1201-
os.environ['CXX'] = 'icpc'
1202-
os.environ['FC'] = 'ifort'
1205+
os.environ['CC'] = os.environ.get('CC', 'icc')
1206+
os.environ['CXX'] = os.environ.get('CXX', 'icpc')
1207+
os.environ['FC'] = os.environ.get('FC', 'ifort')
12031208
sys_info['gcc_major_ver'] = -1
12041209
sys_info['gcc_is_apple_clang'] = False
12051210

12061211
def select_gnu_compilers():
12071212
""" Set environment variables to use GNU compilers. """
1208-
os.environ['CC'] = 'gcc'
1209-
os.environ['CXX'] = 'g++'
1210-
os.environ['FC'] = 'gfortran'
1213+
os.environ['CC'] = os.environ.get('CC', 'gcc')
1214+
os.environ['CXX'] = os.environ.get('CXX', 'g++')
1215+
os.environ['FC'] = os.environ.get('FC', 'gfortran')
12111216
gcc_ver = subprocess.run(['gcc', '-dumpversion'], capture_output=True)
12121217
sys_info['gcc_major_ver'] = int(gcc_ver.stdout.decode('UTF-8').split('.')[0])
12131218
gcc_version = subprocess.run(['gcc', '--version'], capture_output=True)

0 commit comments

Comments
 (0)