Skip to content

Commit f4655fe

Browse files
dpadschaubh
authored andcommitted
Enable building and installing Basilisk via pip install.
- `python conanfile.py` still works as before and is recommended for development usage. - Added broader platform support by building using the limited Python API. - Added missing runtime dependencies (originally installed as dependencies of 'conan').
1 parent 136f9ea commit f4655fe

File tree

10 files changed

+284
-208
lines changed

10 files changed

+284
-208
lines changed

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CMakeCache.txt
55
.DS_Store
66
dist/
77
dist3/
8-
.pytest_cache
8+
.pytest_cache
99
docs/html
1010
docs/build
1111
docs/source/Documentation/*
@@ -32,7 +32,6 @@ cmake-build*/*
3232
*.toc
3333
src/cmake-build-debug/*
3434
supportData/*/__init__.py
35-
src/utilities/MonteCarlo/__init__.py
3635
src/utilities/vizProtobuffer/__init__.py
3736
src/utilities/vizProtobuffer/vizMessage.pb.cc
3837
src/utilities/vizProtobuffer/vizMessage.pb.h
@@ -49,3 +48,10 @@ src/moduleTemplates/autoCppModule/*
4948
**/__pycache__/
5049
venv/
5150
.venv/
51+
52+
# VSCode
53+
.devcontainer
54+
55+
# Python packaging
56+
*.egg-info
57+
build/

conanfile.py

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
warningColor = '\033[93m'
1818
endColor = '\033[0m'
1919

20+
# TODO: Remove this check (deprecated, same as managePipEnvironment flag below).
2021
try:
2122
from conans import __version__ as conan_version
2223
if int(conan_version[0]) >= 2:
@@ -39,15 +40,24 @@
3940
bskModuleOptionsBool = {
4041
"opNav": False,
4142
"vizInterface": True,
42-
"buildProject": True
43+
"buildProject": True,
44+
45+
# XXX: Set managePipEnvironment to True to keep the old behaviour of
46+
# managing the `pip` environment directly (upgrading, installing Python
47+
# packages, etc.). This behaviour is deprecated using the new pip-based
48+
# installation, and should only be required for users who are still calling
49+
# this file with `python conanfile.py ...`.
50+
# TODO: Remove all managePipEnvironment behaviour!
51+
"managePipEnvironment": True
4352
}
4453
bskModuleOptionsString = {
45-
"autoKey": "",
46-
"pathToExternalModules": ""
54+
"autoKey": "", # TODO: Remove, used only for managePipEnvironment.
55+
"pathToExternalModules": "",
56+
"pyLimitedAPI": "",
4757
}
4858
bskModuleOptionsFlag = {
4959
"clean": False,
50-
"allOptPkg": False
60+
"allOptPkg": False # TODO: Remove, used only for managePipEnvironment.
5161
}
5262

5363
# this statement is needed to enable Windows to print ANSI codes in the Terminal
@@ -72,15 +82,6 @@ class BasiliskConan(ConanFile):
7282
options = {"generator": "ANY"}
7383
default_options = {"generator": ""}
7484

75-
# ensure latest pip is installed
76-
if is_running_virtual_env() or platform.system() == "Windows":
77-
cmakeCmdString = 'python -m pip install --upgrade pip'
78-
else:
79-
cmakeCmdString = 'python3 -m pip install --upgrade pip'
80-
print(statusColor + "Updating pip:" + endColor)
81-
print(cmakeCmdString)
82-
os.system(cmakeCmdString)
83-
8485
for opt, value in bskModuleOptionsBool.items():
8586
options.update({opt: [True, False]})
8687
default_options.update({opt: value})
@@ -119,10 +120,30 @@ class BasiliskConan(ConanFile):
119120
pass
120121

121122
def system_requirements(self):
123+
if not self.options.managePipEnvironment:
124+
return # Don't need to manage any pip requirements
125+
126+
# TODO: Remove everything here, which only runs if we have set
127+
# managePipEnvironment (i.e. conanfile.py-based build).
128+
129+
# ensure latest pip is installed
130+
if is_running_virtual_env() or platform.system() == "Windows":
131+
cmakeCmdString = 'python -m pip install --upgrade pip'
132+
else:
133+
cmakeCmdString = 'python3 -m pip install --upgrade pip'
134+
print(statusColor + "Updating pip:" + endColor)
135+
print(cmakeCmdString)
136+
os.system(cmakeCmdString)
137+
122138
reqFile = open('requirements.txt', 'r')
123139
required = reqFile.read().replace("`", "").split('\n')
124140
reqFile.close()
125141
pkgList = [x.lower() for x in required]
142+
pkgList += [
143+
# XXX: Add build system requirements which were removed from requirements.txt.
144+
"conan>=1.40.1, <2.00.0",
145+
"parse>=1.18.0",
146+
]
126147

127148
checkStr = "Required"
128149
if self.options.allOptPkg:
@@ -268,10 +289,24 @@ def build(self):
268289
cmake.definitions["BUILD_VIZINTERFACE"] = self.options.vizInterface
269290
cmake.definitions["EXTERNAL_MODULES_PATH"] = self.options.pathToExternalModules
270291
cmake.definitions["PYTHON_VERSION"] = f"{sys.version_info.major}.{sys.version_info.minor}"
292+
293+
if self.options.pyLimitedAPI != "":
294+
cmake.definitions["PY_LIMITED_API"] = self.options.pyLimitedAPI
295+
296+
# Set the build rpath, since we don't install the targets, so that the
297+
# shared libraries can find each other using relative paths.
298+
cmake.definitions["CMAKE_BUILD_RPATH_USE_ORIGIN"] = True
299+
300+
# TODO: Set the minimum buildable MacOS version.
301+
# (This might be necessary but I'm not sure yet, leaving it here for future reference.)
302+
# cmake.definitions["CMAKE_OSX_DEPLOYMENT_TARGET"] = "10.13"
303+
271304
cmake.parallel = True
272305
print(statusColor + "Configuring cmake..." + endColor)
273306
cmake.configure()
274-
self.add_basilisk_to_sys_path()
307+
if self.options.managePipEnvironment:
308+
# TODO: Remove this, it's only needed when conanfile.py is handling pip installations.
309+
self.add_basilisk_to_sys_path()
275310
if self.options.buildProject:
276311
print(statusColor + "\nCompiling Basilisk..." + endColor)
277312
start = datetime.now()
@@ -294,7 +329,7 @@ def build(self):
294329

295330
def add_basilisk_to_sys_path(self):
296331
print("Adding Basilisk module to python\n")
297-
add_basilisk_module_command = [sys.executable, "-m", "pip", "install", "-e", "."]
332+
add_basilisk_module_command = [sys.executable, "-m", "pip", "install", "--no-build-isolation", "-e", "."]
298333
if not is_running_virtual_env() and self.options.autoKey != 's':
299334
add_basilisk_module_command.append("--user")
300335

pyproject.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[build-system]
2+
build-backend = "setuptools.build_meta"
3+
requires = [
4+
"setuptools>=64", # For PEP 660 (Allow editable installs from pyproject.toml)
5+
"setuptools-scm>=8.0", # Automatically include all Git-controlled files in sdist
6+
7+
# Requirements for building Basilisk through conanfile
8+
"conan>=1.40.1, <2.00.0",
9+
"cmake>=3.26",
10+
"parse>=1.18.0",
11+
"swig==4.2.1" # Known to work with https://github.com/nightlark/swig-pypi/pull/120
12+
]
13+
14+
[project]
15+
name = 'Basilisk'
16+
dynamic = ["version", "dependencies", "optional-dependencies"]
17+
requires-python = ">=3.8"
18+
19+
readme = "README.md"
20+
license = {file = "LICENSE"}
21+
description = "Basilisk: an Astrodynamics Simulation Framework"
22+
23+
[project.urls]
24+
homepage = 'https://hanspeterschaub.info/basilisk/'
25+
26+
[tool.setuptools]
27+
packages = [] # XXX: Leave blank, populated automatically by setup.py.
28+
include-package-data = true
29+
30+
[tool.setuptools.package-data]
31+
"*" = ["*.so", "*.dll", "*.lib", "*.pyd"] # Include all built objects.
32+
Basilisk = ["supportData/**/*"] # Include all support data.
33+
34+
[tool.setuptools.dynamic]
35+
version = {file = "docs/source/bskVersion.txt"}
36+
dependencies = {file = "requirements.txt"}
37+
38+
[tool.setuptools.dynamic.optional-dependencies]
39+
# TODO: Group optional requirements appropriately, e.g. "test", "docs"
40+
optional = {file = "requirements_optional.txt"}

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
conan>=1.40.1, <2.00.0
21
pandas
3-
parse>=1.18.0
2+
matplotlib
3+
numpy
4+
colorama
5+
tqdm
46
Pillow
57
pytest
68
pytest-html
79
pytest-xdist
8-
matplotlib
9-
numpy

0 commit comments

Comments
 (0)