Exemple #1
0
    def from_json(json_obj):
        """Deserialize object from dictionary"""

        version = distutils.version.StrictVersion()
        version_obj = json_obj.get(Metadata.VERSION, None)
        if version_obj:
            version.parse(version_obj)

        area = None
        area_obj = json_obj.get(Metadata.AREA, None)
        if area_obj:
            area = Area.from_json(area_obj)

        begin = None
        begin_obj = json_obj.get(Metadata.BEGIN, None)
        if begin_obj:
            begin = dateutil.parser.parse(begin_obj)
            if begin:
                begin = begin.date()

        end = None
        end_obj = json_obj.get(Metadata.END, None)
        if end_obj:
            end = dateutil.parser.parse(end_obj)
            if end:
                end = end.date()

        return Metadata(area=area, begin=begin, end=end, version=version)
Exemple #2
0
 def _impl():
     try:
         r = Request(
             'http://emma-project.org/versions.json',
             headers={
                 'User-Agent':
                 'PyEMMA-{emma_version}-Py-{python_version}-{platform}'.
                 format(emma_version=current,
                        python_version=platform.python_version(),
                        platform=platform.platform(terse=True))
             } if not testing else {})
         encoding_args = {} if six.PY2 else {'encoding': 'ascii'}
         with closing(urlopen(r, timeout=30)) as response:
             payload = str(response.read(), **encoding_args)
         versions = json.loads(payload)
         latest_json = tuple(filter(lambda x: x['latest'],
                                    versions))[0]['version']
         latest = parse(latest_json)
         if parse(current) < latest:
             import warnings
             warnings.warn(
                 "You are not using the latest release of PyEMMA."
                 " Latest is {latest}, you have {current}.".format(
                     latest=latest, current=current),
                 category=UserWarning)
     except Exception:
         import logging
         logging.getLogger('pyemma').exception("error during version check")
Exemple #3
0
def __nvcc_args():
    return []
    gxx = os.environ.get('GXX')
    recent_torch_version = version.parse("1.7") <= version.parse(
        torch.__version__)
    # Old versions of pytorch did not add the -ccbin command-line option.
    if gxx is not None and not recent_torch_version:
        print("AAH: Added ccbin command-line argument")
        return ['-ccbin', gxx]
    else:
        return []
Exemple #4
0
 def _impl():
     import warnings
     from six.moves.urllib.request import urlopen, Request
     import six
     try:
         r = Request(
             'http://emma-project.org/versions.json',
             headers={
                 'User-Agent':
                 'PyEMMA-{emma_version}-Py-{python_version}-{platform}-{addr}'
                 .format(emma_version=current,
                         python_version=platform.python_version(),
                         platform=platform.platform(terse=True),
                         addr=uuid.getnode())
             } if not testing else {})
         with closing(urlopen(r, timeout=30)) as response:
             args = {'encoding': 'ascii'} if six.PY3 else {}
             payload = str(response.read(), **args)  # py3: encoding ascii
         versions = json.loads(payload)
         latest_json = tuple(filter(lambda x: x['latest'],
                                    versions))[0]['version']
         latest = parse(latest_json)
         if parse(current) < latest:
             warnings.warn(
                 "You are not using the latest release of PyEMMA."
                 " Latest is {latest}, you have {current}.".format(
                     latest=latest, current=current),
                 category=UserWarning)
         if sys.version_info[0] < 3:
             warnings.warn(
                 "Python 2.7 usage is deprecated. "
                 "Future versions of PyEMMA will not support it. "
                 "Please upgrade your Python installation.",
                 category=UserWarning)
     except Exception:
         import logging
         logging.getLogger('pyemma').debug("error during version check",
                                           exc_info=True)
def main(argv=None):
    '''Command line options.'''

    if argv is None:
        argv = sys.argv
    else:
        sys.argv.extend(argv)

    parser = ArgumentParser()
    parser.add_argument('-u', '--url', dest='url', required=True, help="base url (has to contain versions json)")
    parser.add_argument('-o', '--output', dest='output')
    parser.add_argument('-a', '--add_version', dest='version')
    parser.add_argument('-v', '--verbose', dest='verbose', action='store_true')
    parser.add_argument('-l', '--latest-version', dest='latest', action='store_true')

    args = parser.parse_args()

    URL = args.url
    # get dict
    versions = json.load(urlopen(URL + '/versions.json'))
    # add new version
    if args.version:
        versions.append(make_version_dict(URL, args.version))

    # create Version objects to compare them
    version_objs = [parse(s['version']) for s in versions]

    # unify and sort
    version_objs = set(version_objs)
    version_objs = sorted(list(version_objs))

    versions = [make_version_dict(URL, str(v)) for v in version_objs if v != 'devel']

    # last element should be the highest version
    versions[-1]['latest'] = True
    versions.append(make_version_dict(URL, 'devel', '', False))

    if args.verbose:
        print("new versions json:")
        json.dump(versions, sys.stdout, indent=1)
        print()

    if args.latest:
        print(find_latest(versions)['version'])
        return 0

    if args.output:
        with open(args.output, 'w') as v:
            json.dump(versions, v, indent=1)
            v.flush()
Exemple #6
0
    def _discover_dependencies(self, options):
        # Requirements cannot be assumed to be modules / packages
        # options['hiddenimports'].extend(self.distribution.install_requires)

        if version.parse(sys.version[0:3]) >= version.parse('3.4'):
            for package in self.distribution.packages:
                options['hiddenimports'].extend(collect_submodules(package))

        module_files = self._compile_modules()
        required_module_files, required_binary_files = self._compile_requirements(
        )

        for required_file in required_module_files:
            try:
                options['hiddenimports'].append(module_files[required_file])
            except KeyError:
                log.logger.debug(
                    'Unable to collect module for {}'.format(required_file))

        for required_file in required_binary_files:
            # FIXME: Add to binaries rather than simply appending to pathex.
            options['pathex'].append(os.path.dirname(required_file))

        options['pathex'] = list(set(options['pathex']))
Exemple #7
0
def is_numpy_newer_than(version):
    return parse(np.__version__) > parse(version)
Exemple #8
0
    def run(self):
        entry_points = {}
        gui_scripts = []

        entry_points_map = EntryPoint.parse_map(self.distribution.entry_points)
        for entry_key in entry_keys:
            with suppress(KeyError):
                entry_points.update(entry_points_map[entry_key])
                if entry_key == 'gui_scripts':
                    gui_scripts.extend(entry_points_map[entry_key].keys())

        try:
            options = {}
            for key, value in dict(
                    self.distribution.command_options['build_exe']).items():
                options[key] = value[1]
        except (KeyError, TypeError):
            options = {}

        scripts = copy(self.distribution.scripts)
        self.distribution.scripts = []
        for required_directory in [self.build_temp, self.build_exe]:
            shutil.rmtree(required_directory, ignore_errors=True)
            os.makedirs(required_directory, exist_ok=True)

        for entry_point in entry_points.values():
            scripts.append(self._generate_script(entry_point, self.build_temp))

        lib_dirs = ['lib', 'lib{}'.format(build_dir()[3:])]
        for lib_dir in lib_dirs:
            shutil.rmtree(
                os.path.join(self.build_base, lib_dir), ignore_errors=True)

        self.run_command('build')

        for default_option in ['pathex', 'hiddenimports', 'binaries']:
            options.setdefault(default_option, [])

        # by convention, all paths appended to py_options must be absolute
        options['hiddenimports'].extend(self.distribution.install_requires)
        for lib_dir in lib_dirs:
            if os.path.isdir(os.path.join(self.build_base, lib_dir)):
                options['pathex'].append(
                    os.path.abspath(os.path.join(self.build_base, lib_dir)))

        if not options['pathex']:
            raise ValueError('Unable to find lib directory!')

        if version.parse(sys.version[0:3]) >= version.parse('3.4'):
            for package in self.distribution.packages:
                options['hiddenimports'].extend(collect_submodules(package))

        options['specpath'] = os.path.abspath(self.build_temp)
        options['pathex'].append(os.path.abspath(self.build_temp))

        for i, tp in enumerate(options.setdefault('datas', [])):
            options['datas'][i][0] = os.path.abspath(options['datas'][i][0])

        if not self.optimize_imports:
            self._discover_dependencies(options)

        executables = []
        for script, executable in zip(scripts, self.executables):
            executable = executable or Executable(script)
            executable.script = script
            executable._options = dict(options, **executable.options)
            executable._options['name'] = '.'.join(
                ntpath.basename(script).split('.')[:-1])
            if executable._options['name'] in gui_scripts:
                executable._options['console'] = False

            executables.append(executable)

        for executable in executables:
            rename_script(executable)

        names = [executable.options['name'] for executable in executables]
        for executable in executables:
            self._freeze(executable, self.build_temp, self.build_exe)

        for name in names[1:]:
            move_tree(
                os.path.join(self.build_exe, name),
                os.path.join(self.build_exe, names[0]))

        move_tree(os.path.join(self.build_exe, names[0]), self.build_exe)

        shutil.rmtree(self.build_temp, ignore_errors=True)

        # TODO: Compare file hashes to make sure we haven't replaced files with a different version
        for name in names:
            shutil.rmtree(
                os.path.join(self.build_exe, name), ignore_errors=True)