Skip to content

Commit

Permalink
black the code
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Dec 11, 2023
1 parent 75a9f05 commit cba668e
Show file tree
Hide file tree
Showing 509 changed files with 31,788 additions and 22,830 deletions.
64 changes: 46 additions & 18 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ def _setuptools_dir_name(dname="lib"):
Returns the name of a setuptools build directory
"""
platform = sysconfig.get_platform()
architecture = "%s.%s-%i.%i" % (dname, platform,
sys.version_info[0], sys.version_info[1])
architecture = "%s.%s-%i.%i" % (
dname,
platform,
sys.version_info[0],
sys.version_info[1],
)
if is_debug_python():
architecture += "-pydebug"
return architecture
Expand All @@ -51,10 +55,12 @@ def _setuptools_scripts_name():
def _get_available_scripts(path):
res = []
try:
res = " ".join([s.rstrip('.py') for s in os.listdir(path)])
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 ?"]
res = [
"no script available, did you ran "
"'python setup.py build' before bootstrapping ?"
]
return res


Expand All @@ -65,7 +71,7 @@ def execfile(fullpath, globals=None, locals=None):
data = f.read()
except UnicodeDecodeError:
raise SyntaxError("Not a Python script")
code = compile(data, fullpath, 'exec')
code = compile(data, fullpath, "exec")
exec(code, globals, locals)


Expand All @@ -92,16 +98,20 @@ def run_file(filename, argv):
logger.info("Executing %s.main()", filename)
print("########### EXECFILE ###########")
module_globals = globals().copy()
module_globals['__file__'] = filename
module_globals["__file__"] = filename
execfile(filename, module_globals, module_globals)
finally:
sys.argv = old_argv
except SyntaxError as error:
logger.error(error)
logger.info("Execute target using subprocess")
env = os.environ.copy()
env.update({"PYTHONPATH": LIBPATH + os.pathsep + os.environ.get("PYTHONPATH", ""),
"PATH": os.environ.get("PATH", "")})
env.update(
{
"PYTHONPATH": LIBPATH + os.pathsep + os.environ.get("PYTHONPATH", ""),
"PATH": os.environ.get("PATH", ""),
}
)
print("########### SUBPROCESS ###########")
run = subprocess.Popen(full_args, shell=False, env=env)
run.wait()
Expand All @@ -116,14 +126,20 @@ def run_entry_point(entry_point, argv):
(NAME = PACKAGE.MODULE:FUNCTION [EXTRA])
"""
import importlib

elements = entry_point.split("=")
target_name = elements[0].strip()
elements = elements[1].split(":")
module_name = elements[0].strip()
# Take care of entry_point optional "extra" requirements declaration
function_name = elements[1].split()[0].strip()

logger.info("Execute target %s (function %s from module %s) using importlib", target_name, function_name, module_name)
logger.info(
"Execute target %s (function %s from module %s) using importlib",
target_name,
function_name,
module_name,
)
full_args = [target_name]
full_args.extend(argv)
try:
Expand Down Expand Up @@ -155,6 +171,7 @@ def find_executable(target):

# search the file from setup.py
import setup

config = setup.get_project_configuration()
# scripts from project configuration
if "scripts" in config:
Expand All @@ -181,15 +198,22 @@ def find_executable(target):

def main(argv):
parser = argparse.ArgumentParser(
prog="bootstrap", usage="./bootstrap.py <script>", description=__doc__)
prog="bootstrap", usage="./bootstrap.py <script>", description=__doc__
)
parser.add_argument("script", nargs=argparse.REMAINDER)
group = parser.add_mutually_exclusive_group()
group.add_argument(
"-m", nargs=argparse.REMAINDER, dest='module',
help="run library module as a script (terminates option list)")
"-m",
nargs=argparse.REMAINDER,
dest="module",
help="run library module as a script (terminates option list)",
)
group.add_argument(
"-j", "--jupyter", action='store_true',
help="Start jupyter notebook rather than IPython console")
"-j",
"--jupyter",
action="store_true",
help="Start jupyter notebook rather than IPython console",
)
options = parser.parse_args()

if options.jupyter:
Expand All @@ -200,7 +224,10 @@ def main(argv):

logger.info("Start Jupyter notebook")
from notebook.notebookapp import main as notebook_main
os.environ["PYTHONPATH"] = LIBPATH + os.pathsep + os.environ.get("PYTHONPATH", "")

os.environ["PYTHONPATH"] = (
LIBPATH + os.pathsep + os.environ.get("PYTHONPATH", "")
)
notebook_main(argv=[])

elif options.script:
Expand All @@ -218,6 +245,7 @@ def main(argv):
elif options.module:
logging.info("Running module %s", options.module)
import runpy

module = options.module[0]
try:
old = sys.argv
Expand All @@ -234,14 +262,15 @@ def main(argv):
logger.error("Unable to execute iPython, using normal Python")
logger.error(err)
import code

code.interact()
else:
start_ipython(argv=[])


if __name__ == "__main__":
home = os.path.dirname(os.path.abspath(__file__))
LIBPATH = os.path.join(home, 'build', _setuptools_dir_name('lib'))
LIBPATH = os.path.join(home, "build", _setuptools_dir_name("lib"))
cwd = os.getcwd()
os.chdir(home)
build = subprocess.Popen(
Expand All @@ -264,4 +293,3 @@ def main(argv):
logger.info("Patched sys.path with %s", LIBPATH)

main(sys.argv)

2 changes: 0 additions & 2 deletions ci/close_popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def checkColors(self, image, pixelsDescription):


class CheckWindowsPopup_NetworkDeviceDiscovery(CheckPopup):

platform = "win32"
name = "network device discovery"

Expand All @@ -141,7 +140,6 @@ def clickPosition(self):


class CheckMacOsXPopup_NameAsBeenChanged(CheckPopup):

platform = "darwin"
name = "computer renamed"

Expand Down
3 changes: 2 additions & 1 deletion ci/info_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
print(" ")

from sysconfig import get_config_vars

print("Config: " + str(get_config_vars("CONFIG_ARGS")))
print("")

Expand Down Expand Up @@ -68,7 +69,7 @@
"import {0}.QtCore; print({0}.QtCore.qVersion())".format(binding_name),
]
try:
version = subprocess.check_output(cmd, timeout=4).decode('ascii').rstrip("\n")
version = subprocess.check_output(cmd, timeout=4).decode("ascii").rstrip("\n")
except subprocess.CalledProcessError:
print("{0}: Not available".format(binding_name))
else:
Expand Down
52 changes: 34 additions & 18 deletions doc/source/Tutorials/Image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,20 @@
],
"source": [
"import time, os\n",
"\n",
"start_time = time.time()\n",
"import silx\n",
"print(\"Using silx version \",silx.version)\n",
"\n",
"print(\"Using silx version \", silx.version)\n",
"from silx.resources import ExternalResources\n",
"downloader = ExternalResources(\"pyFAI\", \"http://www.silx.org/pub/pyFAI/testimages\", \"PYFAI_DATA\")\n",
"\n",
"downloader = ExternalResources(\n",
" \"pyFAI\", \"http://www.silx.org/pub/pyFAI/testimages\", \"PYFAI_DATA\"\n",
")\n",
"fname = downloader.getfile(\"powder_200_2_0001.cbf\")\n",
"print(\"filename\", os.path.basename(fname))\n",
"import fabio\n",
"\n",
"nbins = 1000"
]
},
Expand All @@ -80,9 +86,9 @@
"source": [
"%%time\n",
"\n",
"#Display an image and the histogram of values (in log scale)\n",
"# Display an image and the histogram of values (in log scale)\n",
"img = fabio.open(fname).data\n",
"log_img = numpy.arcsinh(img) # arcsinh is well behaved log-like function\n",
"log_img = numpy.arcsinh(img) # arcsinh is well behaved log-like function\n",
"his, edges = numpy.histogram(log_img, nbins)"
]
},
Expand Down Expand Up @@ -895,10 +901,13 @@
}
],
"source": [
"fig, ax = subplots(1,2,)\n",
"center = (edges[1:] + edges[:-1])/2.0 # this is the center of the bins \n",
"fig, ax = subplots(\n",
" 1,\n",
" 2,\n",
")\n",
"center = (edges[1:] + edges[:-1]) / 2.0 # this is the center of the bins\n",
"ax[1].imshow(log_img, cmap=\"inferno\")\n",
"ax[0].plot(center,his)"
"ax[0].plot(center, his)"
]
},
{
Expand All @@ -924,17 +933,20 @@
"metadata": {},
"outputs": [],
"source": [
"#switch this to \"CPU\" to have a fail safe \n",
"# switch this to \"CPU\" to have a fail safe\n",
"devicetype = \"GPU\"\n",
"from silx.opencl.codec.byte_offset import ByteOffset\n",
"from silx.opencl.image import ImageProcessing\n",
"import pyopencl, pyopencl.array, pyopencl.elementwise\n",
"\n",
"cbf = fabio.cbfimage.CbfImage()\n",
"bo = ByteOffset(os.path.getsize(fname), img.size, devicetype=devicetype)\n",
"ash = pyopencl.elementwise.ElementwiseKernel(bo.ctx, \n",
" arguments=\"float* data, float* res\", \n",
" operation=\"res[i] = asinh(data[i])\", \n",
" name='arcsinh_kernel')\n",
"ash = pyopencl.elementwise.ElementwiseKernel(\n",
" bo.ctx,\n",
" arguments=\"float* data, float* res\",\n",
" operation=\"res[i] = asinh(data[i])\",\n",
" name=\"arcsinh_kernel\",\n",
")\n",
"ip = ImageProcessing(template=img, ctx=bo.ctx)\n",
"res = pyopencl.array.empty(bo.queue, img.shape, dtype=float32)"
]
Expand All @@ -954,11 +966,11 @@
}
],
"source": [
"%%time \n",
"%%time\n",
"raw = cbf.read(fname, only_raw=True)\n",
"dec = bo(raw, as_float=True)\n",
"ash(dec, res)\n",
"his, edges = ip.histogram(res, nbins, copy=False)\n",
"his, edges = ip.histogram(res, nbins, copy=False)\n",
"log_img = res.get()"
]
},
Expand Down Expand Up @@ -1771,10 +1783,13 @@
}
],
"source": [
"fig, ax = subplots(1,2,)\n",
"center = (edges[1:] + edges[:-1])/2.0 # this is the center of the bins \n",
"fig, ax = subplots(\n",
" 1,\n",
" 2,\n",
")\n",
"center = (edges[1:] + edges[:-1]) / 2.0 # this is the center of the bins\n",
"ax[1].imshow(log_img, cmap=\"inferno\")\n",
"ax[0].plot(center,his)"
"ax[0].plot(center, his)"
]
},
{
Expand Down Expand Up @@ -1826,9 +1841,10 @@
"raw = cbf.read(fname, only_raw=True)\n",
"dec = bo(raw, as_float=True)\n",
"ash(dec, res)\n",
"his, edges = ip.histogram(res, nbins, copy=False)\n",
"his, edges = ip.histogram(res, nbins, copy=False)\n",
"log_img = res.get()\n",
"import os\n",
"\n",
"print(os.linesep.join(bo.log_profile()))\n",
"print(os.linesep.join(ip.log_profile()))"
]
Expand Down
Loading

0 comments on commit cba668e

Please sign in to comment.