Skip to content

Commit

Permalink
Only pip install once
Browse files Browse the repository at this point in the history
  • Loading branch information
larsevj committed Apr 22, 2024
1 parent e91094c commit 5c7625f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 121 deletions.
123 changes: 2 additions & 121 deletions komodo/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,59 +53,6 @@ def dfs(package_name: str, pkg_order: List[str], visited: Set[str]):
return pkg_order


# When running cmake we pass the option -DDEST_PREFIX=fakeroot, this is an
# absolute hack to be able to build opm-common and sunbeam with the ~fakeroot
# implementation used by komodo.
#
# See sunbeam/CMakeLists.txt for a more detailed description of the issue.
# When/if the opm project updates the generated opm-common-config.cmake to work
# with "make DESTDIR=" the DEST_PREFIX cmake flag can be removed.


def cmake(
package_name,
ver,
pkgpath,
prefix,
builddir,
makeopts,
jobs,
fakeroot,
ld_lib_path=None,
bin_path=None,
cmake="cmake",
):
bdir = f"{package_name}-{ver}-build"
if builddir is not None:
bdir = os.path.join(builddir, bdir)

fakeprefix = fakeroot + prefix

flags = [
"-DCMAKE_BUILD_TYPE=Release",
f"-DBOOST_ROOT={fakeprefix}",
"-DBUILD_SHARED_LIBS=ON",
f"-DCMAKE_PREFIX_PATH={fakeprefix}",
f"-DCMAKE_MODULE_PATH={fakeprefix}/share/cmake/Modules",
f"-DCMAKE_INSTALL_PREFIX={prefix}",
f"-DDEST_PREFIX={fakeroot}",
]

Path(bdir).mkdir(parents=True, exist_ok=True)
with pushd(bdir):
os.environ["LD_LIBRARY_PATH"] = ld_lib_path
_pre_PATH = os.environ["PATH"] # pylint: disable=invalid-name
os.environ["PATH"] = bin_path

print(f"Installing {package_name} ({ver}) from source with cmake")
shell([cmake, pkgpath, *flags, makeopts])
print(shell(f"make -j{jobs}"))
print(shell(f"make DESTDIR={fakeroot} install"))

del os.environ["LD_LIBRARY_PATH"]
os.environ["PATH"] = _pre_PATH


def sh(
package_name,
ver,
Expand Down Expand Up @@ -143,20 +90,6 @@ def sh(
print(f"Installing {package_name} ({ver}) from sh")
shell(cmd)


def rsync(package_name, ver, pkgpath, prefix, fakeroot, makeopts=None):
print(f"Installing {package_name} ({ver}) with rsync")
# assume a root-like layout in the pkgpath dir, and just copy it
shell(
[
"rsync -am",
makeopts,
f"{pkgpath}/",
fakeroot + prefix,
],
)


def download(package_name, ver, prefix, url, hash_str, fakeroot, destination):
print(f"Installing {package_name} ({ver}) with download")

Expand Down Expand Up @@ -204,27 +137,6 @@ def download(package_name, ver, prefix, url, hash_str, fakeroot, destination):
)


def pip_install(package_name, ver, prefix, dlprefix, fakeroot, pip="pip", makeopts=""):
ver = strip_version(ver)
if ver == LATEST_PACKAGE_ALIAS:
ver = latest_pypi_version(package_name)
cmd = [
pip,
f"install {package_name}=={strip_version(ver)}",
f"--root {fakeroot}",
f"--prefix {prefix}",
"--no-index",
"--no-deps",
"--ignore-installed",
f"--cache-dir {dlprefix}",
f"--find-links {dlprefix}",
makeopts,
]

print(f"Installing {package_name} ({ver}) from pip")
shell(cmd)


def noop(package_name, ver):
print(f"Doing nothing for noop package {package_name} ({ver})")

Expand Down Expand Up @@ -317,30 +229,8 @@ def resolve(input_str):
makeopts = f"{makeopts} {extra_makeopts}"
makeopts = resolve(makeopts)

if make == "cmake":
cmake(
package_name=package_name,
ver=ver,
pkgpath=pkgpath,
prefix=prefix,
builddir=builddir,
makeopts=makeopts,
jobs=jobs,
fakeroot=fakeroot,
ld_lib_path=ld_lib_path,
bin_path=bin_path,
cmake=cmk,
)
elif make == "pip":
pip_install(
package_name=package_name,
ver=ver,
prefix=prefix,
dlprefix=dlprefix,
fakeroot=fakeroot,
pip=pip,
makeopts=makeopts,
)
if make == "pip":
continue
elif make == "sh":
sh(
package_name=package_name,
Expand All @@ -358,15 +248,6 @@ def resolve(input_str):
cmake=cmk,
makeopts=makeopts,
)
elif make == "rsync":
rsync(
package_name=package_name,
ver=ver,
pkgpath=pkgpath,
prefix=prefix,
fakeroot=fakeroot,
makeopts=makeopts,
)
elif make == "noop":
noop(package_name=package_name, ver=ver)
elif make == "download":
Expand Down
1 change: 1 addition & 0 deletions komodo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def install_previously_downloaded_pip_packages(
str(release_root),
"--no-index",
"--no-deps",
"--compile",
"--ignore-installed",
# assuming fetch.py has done "pip download" to this directory:
f"--cache-dir {downloads_directory}",
Expand Down
1 change: 1 addition & 0 deletions komodo/data/setup-py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ $PIP install $OPTS . \
--root $FAKEROOT \
--no-deps \
--no-cache-dir \
--compile \
--prefix $PREFIX 1>&2

0 comments on commit 5c7625f

Please sign in to comment.