Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
kif committed Feb 22, 2024
2 parents 9ea10ff + 56d50ba commit 2ba21bc
Show file tree
Hide file tree
Showing 44 changed files with 1,887 additions and 882 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
dahu 2024.02
============
* Move to meson-build
* Update BM29
* Update ID02
* Update ID27

from version 0.4 -> 0.5
=======================

Expand Down
356 changes: 17 additions & 339 deletions LICENSE

Large diffs are not rendered by default.

194 changes: 94 additions & 100 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Bootstrap helps you to test scripts without installing them
by patching your PYTHONPATH on the fly
Expand All @@ -11,72 +10,95 @@
__authors__ = ["Frédéric-Emmanuel Picca", "Jérôme Kieffer"]
__contact__ = "[email protected]"
__license__ = "MIT"
__date__ = "06/02/2020"

__date__ = "22/02/2024"

import sys
import os
import shutil
import distutils.util
import subprocess
import logging

if sys.version_info[:2] < (3, 11):
import tomli
else:
import tomllib as tomli
logging.basicConfig()
logger = logging.getLogger("bootstrap")


def is_debug_python():
"""Returns true if the Python interpreter is in debug mode."""
try:
import sysconfig
except ImportError: # pragma nocover
# Python < 2.7
import distutils.sysconfig as sysconfig
def get_project_name(root_dir):
"""Retrieve project name by running python setup.py --name in root_dir.
if sysconfig.get_config_var("Py_DEBUG"):
return True
:param str root_dir: Directory where to run the command.
:return: The name of the project stored in root_dir
"""
print(f"Getting project name in {root_dir}")

with open(os.path.join(root_dir, "pyproject.toml")) as f:
pyproject = tomli.loads(f.read())
return pyproject.get("project", {}).get("name")

return hasattr(sys, "gettotalrefcount")

def build_project(name, root_dir):
"""Build locally the project using meson
def _distutils_dir_name(dname="lib"):
"""
Returns the name of a distutils build directory
:param str name: Name of the project.
:param str root_dir: Root directory of the project
:return: The path to the directory were build was performed
"""
platform = distutils.util.get_platform()
architecture = "%s.%s-%i.%i" % (dname, platform,
sys.version_info[0], sys.version_info[1])
if is_debug_python():
architecture += "-pydebug"
return architecture

extra = []
libdir = "lib"
if sys.platform == "win32":
libdir = "Lib"
# extra = ["--buildtype", "plain"]

build = os.path.join(root_dir, "build")
if not(os.path.isdir(build) and os.path.isdir(os.path.join(build, name))):
p = subprocess.Popen(["meson", "setup", "build"],
shell=False, cwd=root_dir, env=os.environ)
p.wait()
p = subprocess.Popen(["meson", "configure", "--prefix", "/"] + extra,
shell=False, cwd=build, env=os.environ)
p.wait()
p = subprocess.Popen(["meson", "install", "--destdir", "."],
shell=False, cwd=build, env=os.environ)
logger.debug("meson install ended with rc= %s", p.wait())

home = None
if os.environ.get("PYBUILD_NAME") == name:
# we are in the debian packaging way
home = os.environ.get("PYTHONPATH", "").split(os.pathsep)[-1]
if not home:
if os.environ.get("BUILDPYTHONPATH"):
home = os.path.abspath(os.environ.get("BUILDPYTHONPATH", ""))
else:
if sys.platform == "win32":
home = os.path.join(build, libdir, "site-packages")
else:
python_version = f"python{sys.version_info.major}.{sys.version_info.minor}"
home = os.path.join(build, libdir, python_version, "site-packages")
home = os.path.abspath(home)

def _distutils_scripts_name():
"""Return the name of the distrutils scripts sirectory"""
f = "scripts-{version[0]}.{version[1]}"
return f.format(version=sys.version_info)
cnt = 0
while not os.path.isdir(home):
cnt += 1
home = os.path.split(home)[0]
for _ in range(cnt):
n = os.listdir(home)[0]
home = os.path.join(home, n)

logger.warning("Building %s to %s", name, home)

def _get_available_scripts(path):
res = []
try:
res = " ".join([s.rstrip('.py') for s in os.listdir(path)])
except OSError:
res = ["no script available, did you ran "
"'python setup.py build' before bootstrapping ?"]
return res
return home


if sys.version_info[0] >= 3: # Python3
def execfile(fullpath, globals=None, locals=None):
"Python3 implementation for execfile"
with open(fullpath) as f:
try:
data = f.read()
except UnicodeDecodeError:
raise SyntaxError("Not a Python script")
code = compile(data, fullpath, 'exec')
exec(code, globals, locals)
def execfile(fullpath, globals=None, locals=None):
"Python3 implementation for execfile"
with open(fullpath) as f:
try:
data = f.read()
except UnicodeDecodeError:
raise SyntaxError("Not a Python script")
code = compile(data, fullpath, 'exec')
exec(code, globals, locals)


def run_file(filename, argv):
Expand Down Expand Up @@ -117,18 +139,16 @@ def run_file(filename, argv):
run.wait()


def run_entry_point(entry_point, argv):
def run_entry_point(target_name, entry_point, argv):
"""
Execute an entry_point using the current python context
(http://setuptools.readthedocs.io/en/latest/setuptools.html#automatic-script-creation)
:param str entry_point: A string identifying a function from a module
(NAME = PACKAGE.MODULE:FUNCTION)
:param argv: list of arguments
"""
import importlib
elements = entry_point.split("=")
target_name = elements[0].strip()
elements = elements[1].split(":")
elements = entry_point.split(":")
module_name = elements[0].strip()
function_name = elements[1].strip()

Expand Down Expand Up @@ -162,54 +182,27 @@ def find_executable(target):
if os.path.isfile(target):
return ("path", os.path.abspath(target))

# search the file from setup.py
import setup
config = setup.get_project_configuration(dry_run=True)
# scripts from project configuration
if "scripts" in config:
for script_name in config["scripts"]:
if os.path.basename(script) == target:
return ("path", os.path.abspath(script_name))
# entry-points from project configuration
if "entry_points" in config:
for kind in config["entry_points"]:
for entry_point in config["entry_points"][kind]:
elements = entry_point.split("=")
name = elements[0].strip()
if name == target:
return ("entry_point", entry_point)

# search the file from env PATH
for dirname in os.environ.get("PATH", "").split(os.pathsep):
path = os.path.join(dirname, target)
if os.path.isfile(path):
return ("path", path)
# search the executable in pyproject.toml
with open(os.path.join(PROJECT_DIR, "pyproject.toml")) as f:
pyproject = tomli.loads(f.read())

return None, None
scripts = {}
scripts.update(pyproject.get("project", {}).get("scripts", {}))
scripts.update(pyproject.get("project", {}).get("gui-scripts", {}))

for script, entry_point in scripts.items():
if script == target:
print(script, entry_point)
return ("entry_point", target, entry_point)
return None, None

home = os.path.dirname(os.path.abspath(__file__))
LIBPATH = os.path.join(home, 'build', _distutils_dir_name('lib'))
cwd = os.getcwd()
os.chdir(home)
build = subprocess.Popen([sys.executable, "setup.py", "build"],
shell=False, cwd=os.path.dirname(os.path.abspath(__file__)))
build_rc = build.wait()
if not os.path.exists(LIBPATH):
logger.warning("`lib` directory does not exist, trying common Python3 lib")
LIBPATH = os.path.join(os.path.split(LIBPATH)[0], "lib")
os.chdir(cwd)

if build_rc == 0:
logger.info("Build process ended.")
else:
logger.error("Build process ended with rc=%s", build_rc)
sys.exit(-1)

dahu_root = os.path.dirname(os.path.abspath(__file__))
os.environ["DAHU_PLUGINS"] = os.path.join(dahu_root, "plugins")
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_NAME = get_project_name(PROJECT_DIR)
logger.info("Project name: %s", PROJECT_NAME)

if __name__ == "__main__":
LIBPATH = build_project(PROJECT_NAME, PROJECT_DIR)
if len(sys.argv) < 2:
logger.warning("usage: ./bootstrap.py <script>\n")
script = None
Expand All @@ -225,14 +218,15 @@ def find_executable(target):

if script:
argv = sys.argv[2:]
kind, target = find_executable(script)
if kind == "path":
run_file(target, argv)
elif kind == "entry_point":
run_entry_point(target, argv)
res = find_executable(script)
if res[0] == "path":
run_file(res[1], argv)
elif res[0] == "entry_point":
run_entry_point(res[1], res[2], argv)
else:
logger.error("Script %s not found", script)
else:
logging.info("Running IPython by default")
logger.info("Patch the sys.argv: %s", sys.argv)
sys.path.insert(2, "")
try:
Expand Down
3 changes: 0 additions & 3 deletions ci/requirements_rtd.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
numpy
h5py
fabio
sphinx
scipy
cython
sphinxcontrib-programoutput
silx
nbsphinx
2 changes: 0 additions & 2 deletions ci/requirements_travis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

wheel
numpy
cython
pillow
lxml
unittest2
Expand All @@ -11,4 +10,3 @@ fabio
scipy
matplotlib
numexpr
silx
93 changes: 0 additions & 93 deletions dahu/app/server.py

This file was deleted.

Loading

0 comments on commit 2ba21bc

Please sign in to comment.