-
Notifications
You must be signed in to change notification settings - Fork 1.9k
scipy: update to v1.15.2 #3136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
T-Dynamos
wants to merge
3
commits into
kivy:develop
Choose a base branch
from
T-Dynamos:scipy_update
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+446
−1,295
Draft
scipy: update to v1.15.2 #3136
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
import os | ||
import subprocess | ||
import shutil | ||
import sh | ||
from pathlib import Path | ||
from os.path import join | ||
from pythonforandroid.recipe import Recipe | ||
from pythonforandroid.recommendations import read_ndk_version | ||
from pythonforandroid.logger import info, shprint, info_main | ||
from pythonforandroid.util import ensure_dir | ||
import hashlib | ||
|
||
FLANG_FILES = { | ||
"package-flang-aarch64.tar.bz2": "775f362c758abe8d3173edc7be9ced3730ff14c64d44743017c3af7ceb0a6610", | ||
"package-flang-host.tar.bz2": "04fe24d67ee7eb5a4223299c610013585e75c56467e4b185ed929a3d17e3d077", | ||
"package-flang-x86_64.tar.bz2": "2061a0e3179f4afa55516ce3858582d25ea7b108ff762d9fb4ec8a03b49b36d2", | ||
"package-install.tar.bz2": "d37dc6a58b495807f015c7fec08a57ff95d52ad0d0553cbf573b0215d8a1707c", | ||
} | ||
|
||
|
||
class GFortranRecipe(Recipe): | ||
# flang support in NDK by @termux (on github) | ||
name = "fortran" | ||
toolchain_ver = 0 | ||
url = "https://github.com/termux/ndk-toolchain-clang-with-flang/releases/download/" | ||
|
||
def match_sha256(self, file_path, expected_hash): | ||
sha256 = hashlib.sha256() | ||
with open(file_path, "rb") as f: | ||
for chunk in iter(lambda: f.read(8192), b""): | ||
sha256.update(chunk) | ||
file_hash = sha256.hexdigest() | ||
return file_hash == expected_hash | ||
|
||
@property | ||
def ndk_version(self): | ||
ndk_version = read_ndk_version(self.ctx.ndk_dir) | ||
minor_to_letter = {0: ""} | ||
minor_to_letter.update( | ||
{n + 1: chr(i) for n, i in enumerate(range(ord("b"), ord("b") + 25))} | ||
) | ||
return f"{ndk_version.major}{minor_to_letter[ndk_version.minor]}" | ||
|
||
def get_cache_dir(self): | ||
dir_name = self.get_dir_name() | ||
return join(self.ctx.build_dir, "other_builds", dir_name) | ||
|
||
def get_fortran_dir(self): | ||
toolchain_name = f"android-r{self.ndk_version}-api-{self.ctx.ndk_api}" | ||
return join( | ||
self.get_cache_dir(), f"{toolchain_name}-flang-v{self.toolchain_ver}" | ||
) | ||
|
||
def get_incomplete_files(self): | ||
incomplete_files = [] | ||
cache_dir = self.get_cache_dir() | ||
for file, sha256sum in FLANG_FILES.items(): | ||
_file = join(cache_dir, file) | ||
if not (os.path.exists(_file) and self.match_sha256(_file, sha256sum)): | ||
incomplete_files.append(file) | ||
return incomplete_files | ||
|
||
def download_if_necessary(self): | ||
assert self.ndk_version == "27c" | ||
if len(self.get_incomplete_files()) == 0: | ||
return | ||
self.download() | ||
|
||
def download(self): | ||
cache_dir = self.get_cache_dir() | ||
ensure_dir(cache_dir) | ||
for file in self.get_incomplete_files(): | ||
_file = join(cache_dir, file) | ||
if os.path.exists(_file): | ||
os.remove(_file) | ||
self.download_file(f"{self.url}r{join(self.ndk_version, file)}", _file) | ||
|
||
def extract_tar(self, file_path: Path, dest: Path, strip=1): | ||
shprint( | ||
sh.tar, | ||
"xf", | ||
str(file_path), | ||
"--strip-components", | ||
str(strip), | ||
"-C", | ||
str(dest) if dest else ".", | ||
) | ||
|
||
def create_flang_wrapper(self, path: Path, target: str): | ||
script = f"""#!/usr/bin/env bash | ||
if [ "$1" != "-cpp" ] && [ "$1" != "-fc1" ]; then | ||
`dirname $0`/flang-new --target={target}{self.ctx.ndk_api} -D__ANDROID_API__={self.ctx.ndk_api} "$@" | ||
else | ||
`dirname $0`/flang-new "$@" | ||
fi | ||
""" | ||
path.write_text(script) | ||
path.chmod(0o755) | ||
|
||
def unpack(self, arch): | ||
info_main("Unpacking fortran") | ||
|
||
flang_folder = self.get_fortran_dir() | ||
if os.path.exists(flang_folder): | ||
info("{} is already unpacked, skipping".format(self.name)) | ||
return | ||
|
||
toolchain_path = Path( | ||
join(self.ctx.ndk_dir, "toolchains/llvm/prebuilt/linux-x86_64") | ||
) | ||
cache_dir = Path(os.path.abspath(self.get_cache_dir())) | ||
|
||
# clean tmp folder | ||
tmp_folder = Path(os.path.abspath(f"{flang_folder}-tmp")) | ||
shutil.rmtree(tmp_folder, ignore_errors=True) | ||
tmp_folder.mkdir(parents=True) | ||
os.chdir(tmp_folder) | ||
|
||
self.extract_tar(cache_dir / "package-install.tar.bz2", None, strip=4) | ||
self.extract_tar(cache_dir / "package-flang-host.tar.bz2", None) | ||
|
||
sysroot_path = tmp_folder / "sysroot" | ||
shutil.copytree(toolchain_path / "sysroot", sysroot_path) | ||
|
||
self.extract_tar( | ||
cache_dir / "package-flang-aarch64.tar.bz2", | ||
sysroot_path / "usr/lib/aarch64-linux-android", | ||
) | ||
self.extract_tar( | ||
cache_dir / "package-flang-x86_64.tar.bz2", | ||
sysroot_path / "usr/lib/x86_64-linux-android", | ||
) | ||
|
||
# Fix lib/clang paths | ||
version_output = subprocess.check_output( | ||
[str(tmp_folder / "bin/clang"), "--version"], text=True | ||
) | ||
clang_version = next( | ||
(line for line in version_output.splitlines() if "clang version" in line), | ||
"", | ||
) | ||
major_ver = clang_version.split("clang version ")[-1].split(".")[0] | ||
|
||
lib_path = tmp_folder / f"lib/clang/{major_ver}/lib" | ||
src_lib_path = toolchain_path / f"lib/clang/{major_ver}/lib" | ||
shutil.rmtree(lib_path, ignore_errors=True) | ||
lib_path.mkdir(parents=True) | ||
|
||
for item in src_lib_path.iterdir(): | ||
shprint(sh.cp, "-r", str(item), str(lib_path)) | ||
|
||
# Create flang wrappers | ||
targets = [ | ||
"aarch64-linux-android", | ||
"armv7a-linux-androideabi", | ||
"i686-linux-android", | ||
"x86_64-linux-android", | ||
] | ||
|
||
for target in targets: | ||
wrapper_path = tmp_folder / f"bin/{target}-flang" | ||
self.create_flang_wrapper(wrapper_path, target) | ||
shutil.copy( | ||
wrapper_path, tmp_folder / f"bin/{target}{self.ctx.ndk_api}-flang" | ||
) | ||
|
||
tmp_folder.rename(flang_folder) | ||
|
||
@property | ||
def bin_path(self): | ||
return f"{self.get_fortran_dir()}/bin" | ||
|
||
def get_host_platform(self, arch): | ||
return { | ||
"arm64-v8a": "aarch64-linux-android", | ||
"armeabi-v7a": "armv7a-linux-androideabi", | ||
"x86_64": "x86_64-linux-android", | ||
"x86": "i686-linux-android", | ||
}[arch] | ||
|
||
def get_fortran_bin(self, arch): | ||
return join(self.bin_path, f"{self.get_host_platform(arch)}-flang") | ||
|
||
def get_fortran_flags(self, arch): | ||
return f"--target={self.get_host_platform(arch)}{self.ctx.ndk_api} -D__ANDROID_API__={self.ctx.ndk_api}" | ||
|
||
|
||
recipe = GFortranRecipe() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shebang*