Skip to content
Snippets Groups Projects
Commit 427002d6 authored by payno's avatar payno
Browse files

first commit with the structure of the project

parents
No related branches found
No related tags found
No related merge requests found
Showing with 966 additions and 0 deletions
# Build files
build
dist
ESRF_Orange3_Add_on.egg-info
Orange/version.py
doc/build
*.so
*.pyd
*.pyc
MANIFEST
# Cython generated files
__pycache__
# Editor files
.idea
.idea/*
*~
.project
.pydevproject
.settings/*
.DS_Store
# Windows temp files
Thumbs.db
# PyLint, Coverage reports
.pylint_cache/*
htmlcov/*
# Tmp files
*tmp
tmp*
*.edf
*.info
*.cfg
*.xml
*.db
*.tar.bz2
dataset/
datasets/
*.egg-info*
# notebook checkpoints
*.ipynb_checkpoints/
# notebook nbconvert
*.nbconvert.ipynb
# octave files
octave-workspace
LICENSE 0 → 100644
The xas library goal is to provide some usefull process for acquisition/reconstruction automation.
xas is distributed under the MIT license.
xas is using the Qt library. A word of caution is to be provided. If users develop and distribute software using modules accessing Qt by means of Riverbank Computing Qt bindings PyQt4 or PyQt5, those users will be conditioned by the license of their PyQt4/5 software (GPL or commercial). If the end user does not own a commercial license of PyQt4 or PyQt5 and wishes to be free of any distribution condition, (s)he should be able to use PySide because it uses the LGPL license.
It can also be used as an Orange3 add-on. If you wan't to distribute Orange you must stick to there license (GNU [GPL-3.0]+ license)
The MIT license follows:
Copyright (c) European Synchrotron Radiation Facility (ESRF)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Bootstrap helps you to test scripts without installing them
by patching your PYTHONPATH on the fly
example: ./bootstrap.py ipython
"""
__authors__ = ["Frédéric-Emmanuel Picca", "Jérôme Kieffer"]
__contact__ = "jerome.kieffer@esrf.eu"
__license__ = "MIT"
__date__ = "02/03/2018"
import sys
import os
import distutils.util
import subprocess
import logging
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
if sysconfig.get_config_var("Py_DEBUG"):
return True
return hasattr(sys, "gettotalrefcount")
def _distutils_dir_name(dname="lib"):
"""
Returns the name of a distutils build directory
"""
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
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)
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
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 run_file(filename, argv):
"""
Execute a script trying first to use execfile, then a subprocess
:param str filename: Script to execute
:param list[str] argv: Arguments passed to the filename
"""
full_args = [filename]
full_args.extend(argv)
try:
logger.info("Execute target using exec")
# execfile is considered as a local call.
# Providing globals() as locals will force to feed the file into
# globals() (for examples imports).
# Without this any function call from the executed file loses imports
try:
old_argv = sys.argv
sys.argv = full_args
logger.info("Patch the sys.argv: %s", sys.argv)
logger.info("Executing %s.main()", filename)
print("########### EXECFILE ###########")
module_globals = globals().copy()
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", "")})
print("########### SUBPROCESS ###########")
run = subprocess.Popen(full_args, shell=False, env=env)
run.wait()
def run_entry_point(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)
"""
import importlib
elements = entry_point.split("=")
target_name = elements[0].strip()
elements = elements[1].split(":")
module_name = elements[0].strip()
function_name = elements[1].strip()
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:
old_argv = sys.argv
sys.argv = full_args
print("########### IMPORTLIB ###########")
module = importlib.import_module(module_name)
if hasattr(module, function_name):
func = getattr(module, function_name)
func()
else:
logger.info("Function %s not found", function_name)
finally:
sys.argv = old_argv
def find_executable(target):
"""Find a filename from a script name.
- Check the script name as file path,
- Then checks if the name is a target of the setup.py
- Then search the script from the PATH environment variable.
:param str target: Name of the script
:returns: Returns a tuple: kind, name.
"""
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)
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)
if __name__ == "__main__":
if len(sys.argv) < 2:
logger.warning("usage: ./bootstrap.py <script>\n")
script = None
else:
script = sys.argv[1]
if script:
logger.info("Executing %s from source checkout", script)
else:
logging.info("Running iPython by default")
sys.path.insert(0, LIBPATH)
logger.info("Patched sys.path with %s", LIBPATH)
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)
else:
logger.error("Script %s not found", script)
else:
logger.info("Patch the sys.argv: %s", sys.argv)
sys.path.insert(2, "")
try:
from IPython import embed
except Exception as err:
logger.error("Unable to execute iPython, using normal Python")
logger.error(err)
import code
code.interact()
else:
embed()
Files: *
Copyright: 2019 European Synchrotron Radiation Facility
License: MIT
# coding: utf-8
#/*##########################################################################
# Copyright (C) 2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#############################################################################*/
__authors__ = ["H.Payno"]
__license__ = "MIT"
__date__ = "15/05/2017"
import unittest
from ..widgets import test as test_widgets
def suite(loader=None, pattern='test*.py'):
test_suite = unittest.TestSuite()
test_suite.addTest(test_widgets.suite())
return test_suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "07/06/2019"
from numpy.distutils.misc_util import Configuration
def configuration(parent_package='', top_path=None):
config = Configuration('widgets', parent_package, top_path)
config.add_subpackage('test')
return config
if __name__ == "__main__":
from numpy.distutils.core import setup
setup(configuration=configuration)
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
__authors__ = ["H.Payno"]
__license__ = "MIT"
__date__ = "06/06/2019"
import unittest
def suite():
test_suite = unittest.TestSuite()
test_suite.addTests([
])
return test_suite
-r requirements.txt
orange3
#!/usr/bin/env python
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""Run the tests of the project.
This script expects a suite function in <project_package>.test,
which returns a unittest.TestSuite.
test coverage dependencies: coverage, lxml.
"""
__authors__ = ["Jérôme Kieffer", "Thomas Vincent"]
__date__ = "29/11/2016"
__license__ = "MIT"
import distutils.util
import logging
import os
import subprocess
import sys
import time
import unittest
# from silx.gui import plot
# needed for gitlab unit test. Otherwise fail in an
# `ImportError: dlopen: cannot load any more object with static TLS`
logging.basicConfig(level=logging.ERROR)
logger = logging.getLogger("run_tests")
logger.setLevel(logging.ERROR)
logger.info("Python %s %s", sys.version, tuple.__itemsize__ * 8)
try:
import resource
except ImportError:
resource = None
logger.warning("resource module missing")
try:
import importlib
except:
importer = __import__
else:
importer = importlib.import_module
try:
import numpy
except Exception as error:
logger.warning("Numpy missing: %s", error)
else:
logger.info("Numpy %s", numpy.version.version)
try:
import h5py
except Exception as error:
logger.warning("h5py missing: %s", error)
else:
logger.info("h5py %s", h5py.version.version)
def get_project_name(root_dir):
"""Retrieve project name by running python setup.py --name in root_dir.
:param str root_dir: Directory where to run the command.
:return: The name of the project stored in root_dir
"""
logger.debug("Getting project name in %s", root_dir)
p = subprocess.Popen([sys.executable, "setup.py", "--name"],
shell=False, cwd=root_dir, stdout=subprocess.PIPE)
name, _stderr_data = p.communicate()
logger.debug("subprocess ended with rc= %s", p.returncode)
return name.split()[-1].decode('ascii')
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
PROJECT_NAME = "tomwer"
logger.info("Project name: %s", PROJECT_NAME)
class ProfileTextTestResult(unittest.TextTestRunner.resultclass):
def __init__(self, *arg, **kwarg):
unittest.TextTestRunner.resultclass.__init__(self, *arg, **kwarg)
self.logger = logging.getLogger("memProf")
self.logger.setLevel(min(logging.INFO, logging.root.level))
self.logger.handlers.append(logging.FileHandler("profile.log"))
def startTest(self, test):
unittest.TextTestRunner.resultclass.startTest(self, test)
if resource:
self.__mem_start = \
resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
self.__time_start = time.time()
def stopTest(self, test):
unittest.TextTestRunner.resultclass.stopTest(self, test)
# see issue 311. For other platform, get size of ru_maxrss in "man getrusage"
if sys.platform == "darwin":
ratio = 1e-6
else:
ratio = 1e-3
if resource:
memusage = (resource.getrusage(resource.RUSAGE_SELF).ru_maxrss -
self.__mem_start) * ratio
else:
memusage = 0
self.logger.info("Time: %.3fs \t RAM: %.3f Mb\t%s",
time.time() - self.__time_start, memusage, test.id())
def report_rst(cov, package, version="0.0.0", base=""):
"""
Generate a report of test coverage in RST (for Sphinx inclusion)
:param cov: test coverage instance
:param str package: Name of the package
:param str base: base directory of modules to include in the report
:return: RST string
"""
import tempfile
fd, fn = tempfile.mkstemp(suffix=".xml")
os.close(fd)
cov.xml_report(outfile=fn)
from lxml import etree
xml = etree.parse(fn)
classes = xml.xpath("//class")
line0 = "test coverage report for %s" % package
res = [line0, "=" * len(line0), ""]
res.append("Measured on *%s* version %s, %s" %
(package, version, time.strftime("%d/%m/%Y")))
res += ["",
".. csv-table:: test suite coverage",
' :header: "Name", "Stmts", "Exec", "Cover"',
' :widths: 35, 8, 8, 8',
'']
tot_sum_lines = 0
tot_sum_hits = 0
for cl in classes:
name = cl.get("name")
fname = cl.get("filename")
if not os.path.abspath(fname).startswith(base):
continue
lines = cl.find("lines").getchildren()
hits = [int(i.get("hits")) for i in lines]
sum_hits = sum(hits)
sum_lines = len(lines)
cover = 100.0 * sum_hits / sum_lines if sum_lines else 0
if base:
name = os.path.relpath(fname, base)
res.append(' "%s", "%s", "%s", "%.1f %%"' %
(name, sum_lines, sum_hits, cover))
tot_sum_lines += sum_lines
tot_sum_hits += sum_hits
res.append("")
res.append(' "%s total", "%s", "%s", "%.1f %%"' %
(package, tot_sum_lines, tot_sum_hits,
100.0 * tot_sum_hits / tot_sum_lines if tot_sum_lines else 0))
res.append("")
return os.linesep.join(res)
def build_project(name, root_dir):
"""Run python setup.py build for the project.
Build directory can be modified by environment variables.
: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 = "lib.%s-%i.%i" % (platform,
sys.version_info[0], sys.version_info[1])
if os.environ.get("PYBUILD_NAME") == name:
# we are in the debian packaging way
home = os.environ.get("PYTHONPATH", "").split(os.pathsep)[-1]
elif os.environ.get("BUILDPYTHONPATH"):
home = os.path.abspath(os.environ.get("BUILDPYTHONPATH", ""))
else:
home = os.path.join(root_dir, "build", architecture)
logger.warning("Building %s to %s", name, home)
p = subprocess.Popen([sys.executable, "setup.py", "build"],
shell=False, cwd=root_dir)
logger.debug("subprocess ended with rc= %s", p.wait())
return home
from argparse import ArgumentParser
epilog = """
"""
parser = ArgumentParser(description='Run the tests.',
epilog=epilog)
parser.add_argument("-i", "--insource",
action="store_true", dest="insource", default=False,
help="Use the build source and not the installed version")
parser.add_argument("-c", "--coverage", dest="coverage",
action="store_true", default=False,
help=("Report code coverage" +
"(requires 'coverage' and 'lxml' module)"))
parser.add_argument("-m", "--memprofile", dest="memprofile",
action="store_true", default=False,
help="Report memory profiling")
parser.add_argument("-v", "--verbose", default=0,
action="count", dest="verbose",
help="Increase verbosity. Option -v prints additional " +
"INFO messages. Use -vv for full verbosity, " +
"including debug messages and test help strings.")
parser.add_argument("-x", "--no-gui", dest="gui", default=True,
action="store_false",
help="Disable the test of the graphical use interface")
parser.add_argument("-g", "--no-opengl", dest="opengl", default=True,
action="store_false",
help="Disable tests using OpenGL")
parser.add_argument("-o", "--no-opencl", dest="opencl", default=True,
action="store_false",
help="Disable the test of the OpenCL part")
parser.add_argument("-l", "--low-mem", dest="low_mem", default=False,
action="store_true",
help="Disable test with large memory consumption (>100Mbyte")
parser.add_argument("--qt-binding", dest="qt_binding", default=None,
help="Force using a Qt binding, from 'PyQt4', 'PyQt5', or 'PySide'")
parser.add_argument("--web", dest="web_log", default=False,
help="Force unit test to export his log to graylog'",
action="store_true")
default_test_name = PROJECT_NAME
parser.add_argument("test_name", nargs='*',
default=(default_test_name,),
help="test names to run (Default: %s)" % default_test_name)
options = parser.parse_args()
sys.argv = [sys.argv[0]]
test_verbosity = 1
if options.verbose == 1:
logging.root.setLevel(logging.INFO)
logger.info("Set log level: INFO")
test_verbosity = 2
elif options.verbose > 1:
logging.root.setLevel(logging.DEBUG)
logger.info("Set log level: DEBUG")
test_verbosity = 2
if options.coverage:
logger.info("Running test-coverage")
import coverage
try:
cov = coverage.Coverage(omit=["*test*", "*third_party*", "*/setup.py"])
except AttributeError:
cov = coverage.coverage(omit=["*test*", "*third_party*", "*/setup.py"])
cov.start()
previous_web_log_value = os.environ.get("ORANGE_WEB_LOG")
os.environ["ORANGE_WEB_LOG"] = str(options.web_log)
if options.web_log is False:
from tomwer.web import config
config.grayport_host = None
if options.qt_binding and options.gui:
binding = options.qt_binding.lower()
if binding == "pyqt4":
logger.info("Force using PyQt4")
import PyQt4 #noqa
elif binding == "pyqt5":
logger.info("Force using PyQt5")
import PyQt5 #noqa
elif binding == "pyside":
logger.info("Force using PySide")
import PySide #noqa
# else:
# raise ValueError("Qt binding '%s' is unknown" % options.qt_binding)
os.environ["_TOMWER_NO_GUI_UNIT_TESTS"] = str(not options.gui)
# Prevent importing from source directory
if (os.path.dirname(os.path.abspath(__file__)) ==
os.path.abspath(sys.path[0])):
removed_from_sys_path = sys.path.pop(0)
logger.info("Patched sys.path, removed: '%s'", removed_from_sys_path)
# import module
if not options.insource:
try:
module = importer(PROJECT_NAME)
except:
logger.warning(
"%s missing, using built (i.e. not installed) version",
PROJECT_NAME)
options.insource = True
if options.insource:
build_dir = build_project(PROJECT_NAME, PROJECT_DIR)
sys.path.insert(0, build_dir)
logger.warning("Patched sys.path, added: '%s'", build_dir)
module = importer(PROJECT_NAME)
PROJECT_VERSION = getattr(module, 'version', '')
PROJECT_PATH = module.__path__[0]
# Run the tests
runnerArgs = {}
runnerArgs["verbosity"] = test_verbosity
if options.memprofile:
runnerArgs["resultclass"] = ProfileTextTestResult
runner = unittest.TextTestRunner(**runnerArgs)
logger.warning("test %s %s from %s",
PROJECT_NAME, PROJECT_VERSION, PROJECT_PATH)
test_module_name = PROJECT_NAME + '.test'
logger.info('Import %s', test_module_name)
test_module = importer(test_module_name)
test_suite = unittest.TestSuite()
if options.test_name[0] == PROJECT_NAME:
main_test_suite = "%s.test.suite" % PROJECT_NAME
project_test_suite = getattr(test_module, 'suite')
test_suite.addTest(project_test_suite())
if options.gui is True:
from orangecontrib.xas.test import suite as orangecontrib_suite
test_suite.addTest(orangecontrib_suite())
else:
test_suite.addTest(
unittest.defaultTestLoader.loadTestsFromNames(options.test_name))
result = runner.run(test_suite)
for test, reason in result.skipped:
logger.warning('Skipped %s (%s): %s',
test.id(), test.shortDescription() or '', reason)
if result.wasSuccessful():
logger.info("test suite succeeded")
exit_status = 0
else:
logger.warning("test suite failed")
exit_status = 1
if options.coverage:
cov.stop()
cov.save()
with open("coverage.rst", "w") as fn:
fn.write(report_rst(cov, PROJECT_NAME, PROJECT_VERSION, PROJECT_PATH))
# reset the if ORANGE_WEB_LOG value
if previous_web_log_value is None:
del os.environ["ORANGE_WEB_LOG"]
else:
os.environ["ORANGE_WEB_LOG"] = previous_web_log_value
del os.environ["_TOMWER_NO_GUI_UNIT_TESTS"]
sys.exit(exit_status)
This diff is collapsed.
#!/usr/bin/env python
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
"""Unique place where the version number is defined.
provides:
* version = "1.2.3" or "1.2.3-beta4"
* version_info = named tuple (1,2,3,"beta",4)
* hexversion: 0x010203B4
* strictversion = "1.2.3b4
* debianversion = "1.2.3~beta4"
* calc_hexversion: the function to transform a version_tuple into an integer
This is called hexversion since it only really looks meaningful when viewed as the
result of passing it to the built-in hex() function.
The version_info value may be used for a more human-friendly encoding of the same information.
The hexversion is a 32-bit number with the following layout:
Bits (big endian order) Meaning
1-8 PY_MAJOR_VERSION (the 2 in 2.1.0a3)
9-16 PY_MINOR_VERSION (the 1 in 2.1.0a3)
17-24 PY_MICRO_VERSION (the 0 in 2.1.0a3)
25-28 PY_RELEASE_LEVEL (0xA for alpha, 0xB for beta, 0xC for release candidate and 0xF for final)
29-32 PY_RELEASE_SERIAL (the 3 in 2.1.0a3, zero for final releases)
Thus 2.1.0a3 is hexversion 0x020100a3.
"""
from __future__ import absolute_import, print_function, division
__authors__ = ["Henri Payno"]
__license__ = "MIT"
__copyright__ = "European Synchrotron Radiation Facility, Grenoble, France"
__date__ = "06/07/2019"
__status__ = "production"
__docformat__ = 'restructuredtext'
__all__ = ["date", "version_info", "strictversion", "hexversion",
"debianversion", "calc_hexversion"]
RELEASE_LEVEL_VALUE = {"dev": 0,
"alpha": 10,
"beta": 11,
"gamma": 11,
"rc": 12,
"final": 15}
MAJOR = 0
MINOR = 1
MICRO = 0
RELEV = "dev" # <16
SERIAL = 1 # <16
date = __date__
from collections import namedtuple
_version_info = namedtuple("version_info",
["major", "minor", "micro", "releaselevel",
"serial"])
version_info = _version_info(MAJOR, MINOR, MICRO, RELEV, SERIAL)
strictversion = version = debianversion = "%d.%d.%d" % version_info[:3]
if version_info.releaselevel != "final":
version += "-%s%s" % version_info[-2:]
debianversion += "~adev%i" % version_info[
-1] if RELEV == "dev" else "~%s%i" % version_info[-2:]
prerel = "a" if RELEASE_LEVEL_VALUE.get(version_info[3], 0) < 10 else "b"
if prerel not in "ab":
prerel = "a"
strictversion += prerel + str(version_info[-1])
def calc_hexversion(major=0, minor=0, micro=0, releaselevel="dev", serial=0):
"""Calculate the hexadecimal version number from the tuple version_info:
:param major: integer
:param minor: integer
:param micro: integer
:param relev: integer or string
:param serial: integer
:return: integerm always increasing with revision numbers
"""
try:
releaselevel = int(releaselevel)
except ValueError:
releaselevel = RELEASE_LEVEL_VALUE.get(releaselevel, 0)
hex_version = int(serial)
hex_version |= releaselevel * 1 << 4
hex_version |= int(micro) * 1 << 8
hex_version |= int(minor) * 1 << 16
hex_version |= int(major) * 1 << 24
return hex_version
hexversion = calc_hexversion(*version_info)
if __name__ == "__main__":
print(version)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment