Skip to content

Commit

Permalink
numpy: bump version and update
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Mar 21, 2024
1 parent a2d26a0 commit 4c4f2fb
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 37 deletions.
12 changes: 6 additions & 6 deletions recipes/numpy/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
sources:
"1.26.0":
url: "https://github.com/numpy/numpy/releases/download/v1.26.0/numpy-1.26.0.tar.gz"
sha256: "f93fc78fe8bf15afe2b8d6b6499f1c73953169fad1e9a8dd086cdff3190e7fdf"
"1.26.4":
url: "https://github.com/numpy/numpy/releases/download/v1.26.4/numpy-1.26.4.tar.gz"
sha256: "2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"
patches:
"1.26.0":
- patch_file: "patches/1.26.0-patch-meson.patch"
patch_description: ""
"1.26.4":
- patch_file: "patches/1.26.4-patch-meson.patch"
patch_description: "Build only the core C library"
patch_type: "conan"
68 changes: 51 additions & 17 deletions recipes/numpy/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import os
import textwrap

from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.env import Environment
from conan.tools.files import copy, export_conandata_patches, get, apply_conandata_patches, rmdir, move_folder_contents, mkdir
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import copy, export_conandata_patches, get, apply_conandata_patches, rmdir, move_folder_contents, mkdir, save
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"
required_conan_version = ">=1.60.0 <2 || >=2.0.6"


class PackageConan(ConanFile):
class NumpyConan(ConanFile):
name = "numpy"
description = "NumPy is the fundamental package for scientific computing with Python."
description = "Portable, core C math library from NumPy"
license = "BSD 3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://numpy.org/doc/stable/reference/c-api/coremath.html"
Expand Down Expand Up @@ -44,50 +45,83 @@ def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("openblas/0.3.20")
self.requires("openblas/0.3.26")
self.requires("cpython/3.10.0", transitive_headers=True, transitive_libs=True)

def build_requirements(self):
self.tool_requires("cpython/<host_version>")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/2.0.3")
self.tool_requires("pkgconf/2.1.0")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

@property
def _meson_root(self):
return self.source_path.joinpath("vendored-meson", "meson")

def generate(self):
venv = VirtualBuildEnv(self)
venv.generate()

# NumPy can only be built with its vendored Meson
env = Environment()
env.prepend_path("PATH", os.path.join(self.source_folder, "vendored-meson", "entrypoint"))
env.prepend_path("PATH", str(self._meson_root))
env.vars(self).save_script("conanbuild_meson")

tc = MesonToolchain(self)
tc.project_options["allow-noblas"] = False
tc.project_options["blas-order"] = ["openblas"]
tc.project_options["lapack-order"] = ["openblas"]
tc.generate()

tc = PkgConfigDeps(self)
tc.generate()

def build(self):
@staticmethod
def _chmod_plus_x(name):
os.chmod(name, os.stat(name).st_mode | 0o111)

def _patch_sources(self):
apply_conandata_patches(self)
# Add missing wrapper scripts to the vendored meson
save(self, self._meson_root.joinpath("meson"),
textwrap.dedent("""\
#!/usr/bin/env bash
meson_dir=$(dirname "$0")
export PYTHONDONTWRITEBYTECODE=1
exec "$meson_dir/meson.py" "$@"
"""))
self._chmod_plus_x(self._meson_root.joinpath("meson"))
save(self, self._meson_root.joinpath("meson.cmd"),
textwrap.dedent("""\
@echo off
set PYTHONDONTWRITEBYTECODE=1
CALL python %~dp0/meson.py %*
"""))

def build(self):
self._patch_sources()
meson = Meson(self)
meson.configure()
meson.build()

def package(self):
copy(self, "LICENSE*.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(self, "LICENSE*.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
meson = Meson(self)
meson.install()
python_minor = Version(self.dependencies["cpython"].ref.version).minor
pkg_root = os.path.join(self.package_folder, "lib", f"python3.{python_minor}", "site-packages", "numpy")
copy(self, "*.a", pkg_root, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
python_lib = os.path.join(self.package_folder, "lib", f"python3.{python_minor}")
pkg_root = os.path.join(python_lib, "site-packages", "numpy")
copy(self, "*.a", pkg_root, os.path.join(self.package_folder, "lib"), keep_path=False)
mkdir(self, os.path.join(self.package_folder, "include"))
move_folder_contents(self, os.path.join(pkg_root, "core", "include"), os.path.join(self.package_folder, "include"))
rmdir(self, os.path.join(self.package_folder, "lib", f"python3.{python_minor}"))
rmdir(self, python_lib)
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.components["npymath"].set_property("pkg_config_name", "npymath")
self.cpp_info.components["npymath"].libs = ["npymath", "npyrandom"]
self.cpp_info.components["npymath"].requires = [
"openblas::openblas",
"cpython::cpython"
]
self.cpp_info.components["npymath"].requires = ["openblas::openblas", "cpython::cpython"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["npymath"].system_libs = ["m"]
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
--- meson.build
+++ meson.build
@@ -22,7 +22,6 @@
@@ -20,7 +20,6 @@

cc = meson.get_compiler('c')
cpp = meson.get_compiler('cpp')
-cy = meson.get_compiler('cython')

# Check compiler is recent enough (see the SciPy Toolchain Roadmap for details)
if cc.get_id() == 'gcc'
@@ -34,9 +33,6 @@
@@ -32,9 +31,6 @@
error('NumPy requires at least vc142 (default with Visual Studio 2019) ' + \
'when building with MSVC')
endif
Expand All @@ -18,11 +18,12 @@
endif

py = import('python').find_installation(pure: false)

--- numpy/meson.build
+++ numpy/meson.build
@@ -265,18 +265,11 @@
'py.typed'
]
@@ -234,18 +234,11 @@
python_sources += ['_distributor_init_local.py']
endif

-py.install_sources(
- python_sources,
Expand All @@ -39,7 +40,7 @@

pure_subdirs = [
'_pyinstaller',
@@ -300,34 +293,6 @@
@@ -270,34 +263,6 @@

np_dir = py.get_install_dir() / 'numpy'

Expand Down Expand Up @@ -74,7 +75,7 @@
compilers = {
'C': cc,
'CPP': cpp,
@@ -401,14 +366,5 @@
@@ -369,14 +334,5 @@
endif
endforeach

Expand Down
8 changes: 4 additions & 4 deletions recipes/numpy/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.layout import basic_layout
from conan.tools.cmake import cmake_layout
from conan.tools.meson import Meson
import os

Expand All @@ -11,15 +11,15 @@ class TestPackageConan(ConanFile):
test_type = "explicit"

def layout(self):
basic_layout(self)
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.tool_requires("meson/1.2.1")
self.tool_requires("meson/1.4.0")
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/2.0.3")
self.tool_requires("pkgconf/2.1.0")

def build(self):
meson = Meson(self)
Expand Down
2 changes: 1 addition & 1 deletion recipes/numpy/all/test_package/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('test_package', 'c')
package_dep = dependency('npymath')
package_dep = dependency('c')
executable('test_package',
sources : ['test_package.c'],
dependencies : [package_dep])
3 changes: 2 additions & 1 deletion recipes/numpy/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Based on https://github.com/numpy/numpy/blob/v1.26.0/numpy/core/tests/examples/limited_api/limited_api.c
// Based on https://github.com/numpy/numpy/blob/v1.26.4/numpy/core/tests/examples/limited_api/limited_api.c

#define Py_LIMITED_API 0x03060000
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION

#include <Python.h>
#include <numpy/arrayobject.h>
Expand Down
2 changes: 1 addition & 1 deletion recipes/numpy/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"1.26.0":
"1.26.4":
folder: all

0 comments on commit 4c4f2fb

Please sign in to comment.