Skip to content

Commit

Permalink
Shift igraph configuration into the setup.py.
Browse files Browse the repository at this point in the history
This ensures that it gets built as part of the normal installation procedure,
even if the entire thing is a bit messy.
  • Loading branch information
LTLA committed Jan 1, 2025
1 parent f68f79c commit af43b65
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
36 changes: 0 additions & 36 deletions extern/build_igraph.sh

This file was deleted.

48 changes: 47 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class CMakeExtension(Extension):
def __init__(self, name):
super().__init__(name, sources=[])


class build_ext(build_ext_orig):
def run(self):
for ext in self.extensions:
Expand All @@ -28,6 +29,50 @@ def build_cmake(self, ext):
build_lib = pathlib.Path(self.build_lib)
outpath = os.path.join(build_lib.absolute(), ext.name)

# Firstly, downloading and building the igraph library.
install_dir = os.path.join(os.getcwd(), "installed")
if not os.path.exists(install_dir):
version = "0.10.15"
if not os.path.exists("extern"):
os.mkdir("extern")

src_dir = os.path.join("extern", "igraph-" + version)
if not os.path.exists(src_dir):
tarball = os.path.join("extern", "igraph.tar.gz")
if not os.path.exists(tarball):
import urllib.request
target_url = " https://github.com/igraph/igraph/releases/download/" + version + "/igraph-" + version + ".tar.gz"
urllib.request.urlretrieve(target_url, tarball)
import tarfile
with tarfile.open(tarball, "r") as tf:
tf.extractall("extern")

Check failure

Code scanning / CodeQL

Arbitrary file write during tarfile extraction High

This file extraction depends on a
potentially untrusted source
.

build_dir = os.path.join("extern", "build-" + version)
os.mkdir("installed")

cmd = [
"cmake",
"-S", src_dir,
"-B", build_dir,
"-DCMAKE_POSITION_INDEPENDENT_CODE=true",
"-DIGRAPH_WARNINGS_AS_ERRORS=OFF",
"-DCMAKE_INSTALL_PREFIX=" + install_dir
]
if os.name != "nt":
cmd.append("-DCMAKE_BUILD_TYPE=Release")
if "MORE_CMAKE_OPTIONS" in os.environ:
cmd += os.environ["MORE_CMAKE_OPTIONS"].split()
self.spawn(cmd)

if not self.dry_run:
cmd = ['cmake', '--build', build_dir]
if os.name == "nt":
cmd += ["--config", "Release"]
self.spawn(cmd)
cmd = ['cmake', '--install', build_dir]
self.spawn(cmd)

# Now building the scranpy binary.
if not os.path.exists(build_temp):
import assorthead
import mattress
Expand All @@ -40,7 +85,8 @@ def build_cmake(self, ext):
"-DPYTHON_EXECUTABLE=" + sys.executable,
"-DASSORTHEAD_INCLUDE_DIR=" + assorthead.includes(),
"-DMATTRESS_INCLUDE_DIR=" + mattress.includes(),
"-DKNNCOLLE_INCLUDE_DIR=" + knncolle.includes()
"-DKNNCOLLE_INCLUDE_DIR=" + knncolle.includes(),
"-DCMAKE_PREFIX_PATH=" + install_dir
]
if os.name != "nt":
cmd.append("-DCMAKE_BUILD_TYPE=Release")
Expand Down

0 comments on commit af43b65

Please sign in to comment.