Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

boa version currently used in emscripten forge #334

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ff6a064
hacky emscripten experiments
DerThorsten Feb 10, 2022
f9224fc
hacky hack
DerThorsten Feb 10, 2022
f90dc50
Merge branch 'emscripten' into master
DerThorsten Feb 14, 2022
00e9f92
Merge pull request #2 from DerThorsten/master
DerThorsten Feb 14, 2022
210a62d
emscripten wip
DerThorsten Feb 17, 2022
ab5013e
wip
DerThorsten Mar 2, 2022
3500b3d
hack to not install pip by default
DerThorsten Mar 13, 2022
38e20c4
hack to set emsdk dir
DerThorsten Mar 14, 2022
252287a
fixed
DerThorsten Mar 14, 2022
9ad2be7
renaming EMSDK_DIR
DerThorsten Mar 14, 2022
d90c12b
using monkeypatch
DerThorsten Mar 18, 2022
bd613a7
fixed monkeypatch
DerThorsten Mar 18, 2022
8e33dbf
improved monkeypatching
DerThorsten Mar 18, 2022
abbe512
conda monkeypatch
DerThorsten Mar 18, 2022
cd388a3
cleanup monkeypatch
DerThorsten Mar 25, 2022
f0cc3d0
merged
DerThorsten May 16, 2022
19964be
wip
DerThorsten May 17, 2022
e1bcfd4
wip
DerThorsten May 17, 2022
b453309
added post build callback
DerThorsten May 17, 2022
d601415
improved callback
DerThorsten May 18, 2022
0479d2b
wip
DerThorsten May 18, 2022
1f61682
adding final names
DerThorsten Jun 20, 2022
75aeabe
Add emscripten wasm filetype patch
martinRenou Aug 8, 2022
92064d2
Merge pull request #5 from martinRenou/postcb
DerThorsten Aug 8, 2022
172c1dc
make it non opt
DerThorsten Oct 17, 2022
b5e3e2e
Merge branch 'main' into postcb
DerThorsten Oct 24, 2022
a42b870
updated for new conda-bld
DerThorsten Dec 1, 2022
41581ca
Merge remote-tracking branch 'upstream/main' into newoba
DerThorsten Dec 12, 2022
65d2e34
added python api
DerThorsten Dec 29, 2022
c5d52c1
hotfix to remove breakpoint
DerThorsten Jul 14, 2023
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 @@ -182,6 +183,8 @@ def main(config=None):
command = args.command

init_api_context()
api_ctx = api.Context()
api_ctx.add_pip_as_python_dependency = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check / do you know if conda-build does something similar?

init_global_config(args)

from boa.core.run_build import run_build
Expand Down
13 changes: 10 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 @@ -237,7 +241,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 @@ -279,6 +282,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 = []
cph_kwargs = {}
Expand Down Expand Up @@ -388,6 +392,10 @@ 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 not None:
env["CONDA_EMSDK_DIR"] = emsdk_dir

# forcing shiny colors everywhere
env["CLICOLOR_FORCE"] = 1
env["AM_COLOR_TESTS"] = "always"
Expand Down Expand Up @@ -628,7 +636,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
5 changes: 3 additions & 2 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 Expand Up @@ -219,7 +220,7 @@ def ms_depends(self, typ="run"):
# since channel names can be full urls many of these characters are potentially valid
for c in "=!@#$%^&*;\"'\\|<>?/":
if c in spec.name:
breakpoint()

sys.exit(
"Error: bad character '%s' in package name "
"dependency '%s'" % (c, spec.name)
Expand All @@ -238,7 +239,7 @@ def ms_depends(self, typ="run"):
parts[1],
parts[2],
)
sys.exit(msg)
raise RuntimeError(msg)
specs.append(spec)

return specs
Expand Down
177 changes: 177 additions & 0 deletions boa/core/monkeypatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
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

try:
from conda_build.conda_interface import string_types
except ImportError:
string_types = str
from conda_build.post import filetypes_for_platform


filetypes_for_platform["emscripten"] = ["wasm"]


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
import os
Expand Down
22 changes: 17 additions & 5 deletions boa/core/run_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (C) 2021, QuantStack
# SPDX-License-Identifier: BSD-3-Clause

from .monkeypatch import *
import argparse
import os
import glob
Expand Down Expand Up @@ -196,7 +197,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 @@ -224,6 +225,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 @@ -311,7 +315,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 @@ -412,7 +416,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 @@ -421,7 +425,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 @@ -497,7 +501,7 @@ def run_build(args: argparse.Namespace) -> None:
for recipe in all_recipes:
while True:
try:
build_recipe(
sorted_outputs,final_names = build_recipe(
args.command,
recipe["recipe_file"],
cbc,
Expand All @@ -511,9 +515,17 @@ def run_build(args: argparse.Namespace) -> None:
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
Loading