Skip to content

Commit

Permalink
setup_helper: add support for .conda packages
Browse files Browse the repository at this point in the history
  • Loading branch information
pauleve committed Jan 20, 2025
1 parent 948defc commit 2b6701d
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions colomoto/setup_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import sys
import tarfile
import tempfile

try:
from urllib.request import urlretrieve, urlopen
Expand Down Expand Up @@ -77,17 +78,35 @@ def prepare_dest(dest):

def conda_package_extract(conda_url, prefix):
print("downloading {}".format(conda_url))
localfile = urlretrieve(conda_url)[0]
fmt = conda_url.split(".")[-1]
def match_member(m):
return m.name.split('/')[0] != 'info'
with tarfile.open(localfile, "r:%s"%fmt) as tar:
members = [m for m in tar.getmembers() if match_member(m)]
for m in members:
dest = os.path.join(prefix, m.name)
print("installing %s" % dest)
tar.extractall(prefix, members)
os.unlink(localfile)
tmpd = tempfile.mkdtemp("_colomoto")
try:
fn = conda_url.split("/")[-1]
localfile = urlretrieve(conda_url, os.path.join(tmpd, fn))[0]
fmt = conda_url.split(".")[-1]

if fmt == "conda":
try:
from conda_package_handling.api import transmute
except ImportError:
print("You must run \n\n\tpip install conda-package-handling\n",
file=sys.stderr)
sys.exit(1)
errors = transmute(localfile, ".tar.bz2")
if errors:
raise Exception(f"Failed to convert conda package ({errors})")
localfile = localfile[:-len(fmt)] + "tar.bz2"
fmt = "bz2"

def match_member(m):
return m.name.split('/')[0] != 'info'
with tarfile.open(localfile, "r:%s"%fmt) as tar:
members = [m for m in tar.getmembers() if match_member(m)]
for m in members:
dest = os.path.join(prefix, m.name)
print("installing %s" % dest)
tar.extractall(prefix, members)
finally:
shutil.rmtree(tmpd)

def is_installed(progname):
if sys.version_info[0] < 3:
Expand Down

0 comments on commit 2b6701d

Please sign in to comment.