Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion boa/cli/boa.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import sys
import argparse

from boa.core.monkeypatch import *
from boa.core.config import init_global_config
from boa._version import __version__
from mamba.utils import init_api_context
import libmambapy as api

from conda_build.conda_interface import cc_conda_build

Expand Down Expand Up @@ -121,6 +122,8 @@ def main(config=None):
command = args.command

init_api_context()
api_ctx = api.Context()
api_ctx.add_pip_as_python_dependency = False
init_global_config(args)

from boa.core.run_build import run_build
Expand Down
14 changes: 11 additions & 3 deletions boa/core/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
"""
Module that does most of the heavy lifting for the ``conda build`` command.
"""
from __future__ import absolute_import, division, print_function


from __future__ import absolute_import, division, print_function
from .monkeypatch import *
import conda_build
import fnmatch
import io
import os
import glob
from os.path import isdir, isfile, join
import shutil
import sys
Expand Down Expand Up @@ -236,7 +240,6 @@ def select_files(files, include_files, exclude_files):


def bundle_conda(metadata, initial_files, env, files_selector=None):

files = post_process_files(metadata, initial_files)

# first filter is so that info_files does not pick up ignored files
Expand Down Expand Up @@ -278,6 +281,7 @@ def bundle_conda(metadata, initial_files, env, files_selector=None):
files = select_files(files, include_files, files_selector.get("exclude"))

basename = metadata.dist()

tmp_archives = []
final_outputs = []
ext = ".tar.bz2"
Expand Down Expand Up @@ -377,6 +381,11 @@ def write_build_scripts(m, script, build_file):

env["CONDA_BUILD_STATE"] = "BUILD"

emsdk_dir = os.environ.get("CONDA_EMSDK_DIR")
if emsdk_dir is None:
raise RuntimeError("emsdk_dir is none")
env["CONDA_EMSDK_DIR"] = emsdk_dir

# forcing shiny colors everywhere
env["CLICOLOR_FORCE"] = 1
env["AM_COLOR_TESTS"] = "always"
Expand Down Expand Up @@ -617,7 +626,6 @@ def build(
if m.skip():
# console.print(utils.get_skip_message(m))
return {}

with utils.path_prepended(m.config.build_prefix):
env = environ.get_dict(m=m)

Expand Down
2 changes: 1 addition & 1 deletion boa/core/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
from rich.console import Console

boa_config = None
Expand Down
2 changes: 1 addition & 1 deletion boa/core/jinja_support.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
import os
from functools import partial
from conda_build.jinja_context import cdt
Expand Down
1 change: 1 addition & 0 deletions boa/core/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause
from .monkeypatch import *

import hashlib
import os
Expand Down
163 changes: 163 additions & 0 deletions boa/core/monkeypatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import os
import sys


###############################################
# CONDA MONKEY-PATCH
###############################################
from conda.base import constants
KNOWN_SUBDIRS = PLATFORM_DIRECTORIES = (
"noarch",
"linux-32",
"linux-64",
"linux-aarch64",
"linux-armv6l",
"linux-armv7l",
"linux-ppc64",
"linux-ppc64le",
"linux-s390x",
"osx-64",
"osx-arm64",
"win-32",
"win-64",
"zos-z",
"emscripten-32"
)
constants.KNOWN_SUBDIRS = KNOWN_SUBDIRS
constants.PLATFORM_DIRECTORIES = PLATFORM_DIRECTORIES


###############################################
# CONDA-BUILD MONKEY-PATCH
###############################################

from conda_build import exceptions, utils, variants, environ
from conda_build.conda_interface import non_x86_linux_machines
from conda_build import metadata
from conda_build import utils,environ
from conda_build.features import feature_list
from conda_build.conda_interface import string_types


def ns_cfg(config):
# Remember to update the docs of any of this changes
plat = config.host_subdir
d = dict(
linux=plat.startswith('linux-'),
linux32=bool(plat == 'linux-32'),
linux64=bool(plat == 'linux-64'),
arm=plat.startswith('linux-arm'),
osx=plat.startswith('osx-'),
emscripten=plat.startswith('emscripten-'),
emscripten32=bool(plat == 'emscripten-32'),
emscripten64=bool(plat == 'emscripten-64'),
unix=plat.startswith(('linux-', 'osx-', 'emscripten-')),
win=plat.startswith('win-'),
win32=bool(plat == 'win-32'),
win64=bool(plat == 'win-64'),
x86=plat.endswith(('-32', '-64')),
x86_64=plat.endswith('-64'),
os=os,
environ=os.environ,
nomkl=bool(int(os.environ.get('FEATURE_NOMKL', False)))
)

defaults = variants.get_default_variant(config)
py = config.variant.get('python', defaults['python'])
# there are times when python comes in as a tuple
if not hasattr(py, 'split'):
py = py[0]
# go from "3.6 *_cython" -> "36"
# or from "3.6.9" -> "36"
py = int("".join(py.split(' ')[0].split('.')[:2]))

d["build_platform"] = config.build_subdir

d.update(dict(py=py,
py3k=bool(30 <= py < 40),
py2k=bool(20 <= py < 30),
py26=bool(py == 26),
py27=bool(py == 27),
py33=bool(py == 33),
py34=bool(py == 34),
py35=bool(py == 35),
py36=bool(py == 36),))

np = config.variant.get('numpy')
if not np:
np = defaults['numpy']
if config.verbose:
utils.get_logger(__name__).warn("No numpy version specified in conda_build_config.yaml. "
"Falling back to default numpy value of {}".format(defaults['numpy']))
d['np'] = int("".join(np.split('.')[:2]))

pl = config.variant.get('perl', defaults['perl'])
d['pl'] = pl

lua = config.variant.get('lua', defaults['lua'])
d['lua'] = lua
d['luajit'] = bool(lua[0] == "2")

for machine in non_x86_linux_machines:
d[machine] = bool(plat.endswith('-%s' % machine))

for feature, value in feature_list:
d[feature] = value
d.update(os.environ)

# here we try to do some type conversion for more intuitive usage. Otherwise,
# values like 35 are strings by default, making relational operations confusing.
# We also convert "True" and things like that to booleans.
for k, v in config.variant.items():
if k not in d:
try:
d[k] = int(v)
except (TypeError, ValueError):
if isinstance(v, string_types) and v.lower() in ('false', 'true'):
v = v.lower() == 'true'
d[k] = v
return d


metadata.ns_cfg = ns_cfg



DEFAULT_SUBDIRS = {
"linux-64",
"linux-32",
"linux-s390x",
"linux-ppc64",
"linux-ppc64le",
"linux-armv6l",
"linux-armv7l",
"linux-aarch64",
"win-64",
"win-32",
"osx-64",
"osx-arm64",
"zos-z",
"noarch",
"emscripten-32"
}

utils.DEFAULT_SUBDIRS = DEFAULT_SUBDIRS



def get_shlib_ext(host_platform):
# Return the shared library extension.
if host_platform.startswith('win'):
return '.dll'
elif host_platform in ['osx', 'darwin']:
return '.dylib'
elif host_platform.startswith('linux') or host_platform.startswith("emscripten"):
return '.so'
elif host_platform == 'noarch':
# noarch packages should not contain shared libraries, use the system
# platform if this is requested
return get_shlib_ext(sys.platform)
else:
raise NotImplementedError(host_platform)
environ.get_shlib_ext = get_shlib_ext

2 changes: 1 addition & 1 deletion boa/core/recipe_handling.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
import os
import re
import time
Expand Down
2 changes: 1 addition & 1 deletion boa/core/recipe_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
from boa.core.solver import get_solver
import copy
import json
Expand Down
2 changes: 1 addition & 1 deletion boa/core/render.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
from ruamel.yaml import YAML
import jinja2
from boa.core.jinja_support import jinja_functions
Expand Down
23 changes: 17 additions & 6 deletions boa/core/run_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
import os
import glob
import json
Expand Down Expand Up @@ -194,7 +194,7 @@ def build_recipe(
continue_on_failure: bool = False,
rerun_build: bool = False,
):

print("in build_recipe")
ydoc = render(recipe_path, config=config)
# We need to assemble the variants for each output
variants = {}
Expand Down Expand Up @@ -222,6 +222,9 @@ def build_recipe(
# the final metadata
sorted_outputs = to_build_tree(ydoc, variants, config, cbc, selected_features)

# the actual filenames like `pyjs-0.1.0-hc96583f_0` without ending (ie the filename without .tar.bz2)
final_names = []

# then we need to solve and build from the bottom up
# we can't first solve all packages without finalizing everything
#
Expand Down Expand Up @@ -309,7 +312,7 @@ def build_recipe(
continue

final_name = meta.dist()

final_names.append(final_name)
# TODO this doesn't work for noarch!
if skip_existing:
final_name = meta.dist()
Expand Down Expand Up @@ -410,7 +413,7 @@ def build_recipe(
raise e
else:
console.print_exception(show_locals=False)
exit(1)
raise e

for o in sorted_outputs:
if o in failed_outputs:
Expand All @@ -419,7 +422,7 @@ def build_recipe(
print("\n\n")
console.print(o)

return sorted_outputs
return sorted_outputs,final_names


def extract_features(feature_string):
Expand Down Expand Up @@ -468,7 +471,7 @@ def run_build(args):
for recipe in all_recipes:
while True:
try:
build_recipe(
sorted_outputs,final_names = build_recipe(
args.command,
recipe["recipe_file"],
cbc,
Expand All @@ -482,9 +485,17 @@ def run_build(args):
rerun_build=rerun_build,
)
rerun_build = False
if getattr(args, "post_build_callback", None) is not None:
args.post_build_callback(
recipe=recipe,
target_platform=args.target_platform,
sorted_outputs=sorted_outputs,
final_names=final_names
)
except BoaRunBuildException:
rerun_build = True
except Exception as e:
print(e)
raise e
else:
break
4 changes: 3 additions & 1 deletion boa/core/solver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
import os
import tempfile

Expand Down Expand Up @@ -46,6 +46,7 @@ def get_solver(subdir, output_folder="local"):
os.makedirs(pkg_cache, exist_ok=True)

if not solver_cache.get(subdir):
print("GET SOLVER")
solver_cache[subdir] = MambaSolver([], subdir, output_folder)

return solver_cache[subdir], pkg_cache
Expand Down Expand Up @@ -158,6 +159,7 @@ def replace_channels(self):

start_prio = len(self.channels) + len(self.index)
for subdir, channel in self.local_index:
print(f"{subdir=} {channel=}")
if not subdir.loaded():
continue

Expand Down
2 changes: 1 addition & 1 deletion boa/core/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
import json
import logging
import os
Expand Down
Loading