Beispiel #1
0
def run_command_hooks(cmd_obj, hook_kind):
    """Run hooks registered for that command and phase.

    *cmd_obj* is a finalized command object; *hook_kind* is either
    'pre_hook' or 'post_hook'.
    """

    if hook_kind not in ('pre_hook', 'post_hook'):
        raise ValueError('invalid hook kind: %r' % hook_kind)

    hooks = getattr(cmd_obj, hook_kind, None)

    if hooks is None:
        return

    for hook in hooks.values():
        if isinstance(hook, str):
            try:
                hook_obj = resolve_name(hook)
            except ImportError:
                err = sys.exc_info()[1] # For py3k
                raise DistutilsModuleError('cannot find hook %s: %s' %
                                           (hook,err))
        else:
            hook_obj = hook

        if not hasattr(hook_obj, '__call__'):
            raise DistutilsOptionError('hook %r is not callable' % hook)

        log.info('running %s %s for command %s',
                 hook_kind, hook, cmd_obj.get_command_name())

        try :
            hook_obj(cmd_obj)
        except:
            e = sys.exc_info()[1]
            log.error('hook %s raised exception: %s\n' % (hook, e))
            log.error(traceback.format_exc())
            sys.exit(1)
Beispiel #2
0
    def get_command_class(self, command):
        klass = self.cmdclass.get(command)
        if klass:
            return klass
        for pkgname in self.get_command_packages():
            module_name = '%s.%s' % (pkgname, command)
            klass_name = command
            try:
                __import__(module_name)
                module = sys.modules[module_name]
            except ImportError:
                continue

            try:
                klass = getattr(module, klass_name)
            except AttributeError:
                raise DistutilsModuleError, "invalid command '%s' (no class '%s' in module '%s')" % (
                    command, klass_name, module_name)

            self.cmdclass[command] = klass
            return klass

        raise DistutilsModuleError("invalid command '%s'" % command)
Beispiel #3
0
    def get_command_class(self, command):
        """Return the class that implements the Distutils command named by
        'command'.  First we check the 'cmdclass' dictionary; if the
        command is mentioned there, we fetch the class object from the
        dictionary and return it.  Otherwise we load the command module
        ("distutils.command." + command) and fetch the command class from
        the module.  The loaded class is also stored in 'cmdclass'
        to speed future calls to 'get_command_class()'.

        Raises DistutilsModuleError if the expected module could not be
        found, or if that module does not define the expected class.
        """
        klass = self.cmdclass.get(command)
        if klass:
            return klass

        for pkgname in self.get_command_packages():
            module_name = "%s.%s" % (pkgname, command)
            klass_name = command

            try:
                __import__(module_name)
                module = sys.modules[module_name]
            except ImportError:
                continue

            try:
                klass = getattr(module, klass_name)
            except AttributeError:
                raise DistutilsModuleError, \
                      "invalid command '%s' (no class '%s' in module '%s')" \
                      % (command, klass_name, module_name)

            self.cmdclass[command] = klass
            return klass

        raise DistutilsModuleError("invalid command '%s'" % command)
Beispiel #4
0
 def client(self):
     try:
         from botocore.session import get_session
     except ImportError:
         raise DistutilsModuleError('botocore is required')
     return get_session().create_client('s3')
Beispiel #5
0
    def finalize_options(self):
        self.extensions = self.distribution.ext_modules

        # Let Cython generate its files in the "cythonized"
        # subdirectory of the build_base directory.
        self.set_undefined_options('build', ('build_base', 'build_base'))
        self.build_dir = os.path.join(self.build_base, "cythonized")

        # Inherit some options from the 'build_ext' command if possible
        # (this in turn implies inheritance from the 'build' command)
        inherit_opts = [('build_lib', 'build_lib'), ('debug', 'debug'),
                        ('force', 'force')]

        # Python 3.5 now has a parallel option as well
        if sys.version_info[:2] >= (3, 5):
            inherit_opts.append(('parallel', 'parallel'))

        self.set_undefined_options('build_ext', *inherit_opts)

        # Always produce debugging output unless SAGE_DEBUG=no is given
        # explicitly
        self.debug = os.environ.get('SAGE_DEBUG', None) != 'no'

        if self.debug:
            log.info('Enabling Cython debugging support')

        if self.profile is None:
            self.profile = os.environ.get('SAGE_PROFILE') == 'yes'

        if self.profile:
            log.info('Enabling Cython profiling support')

        if self.parallel is None:
            self.parallel = os.environ.get('SAGE_NUM_THREADS', '0')

        try:
            self.parallel = int(self.parallel)
        except ValueError:
            raise DistutilsOptionError("parallel should be an integer")

        try:
            import Cython
        except ImportError:
            raise DistutilsModuleError(
                "Cython must be installed and importable in order to run "
                "the cythonize command")

        # Cython compiler directives
        self.cython_directives = dict(
            auto_pickle=False,
            autotestdict=False,
            cdivision=True,
            embedsignature=True,
            fast_getattr=True,
            language_level="3str",
            preliminary_late_includes_cy28=True,
            profile=self.profile,
        )
        self.compile_time_env = dict(
            PY_PLATFORM=sys.platform,
            # The following two constants are here only for backwards compatibility of user packages
            PY_VERSION_HEX=sys.hexversion,
            PY_MAJOR_VERSION=sys.version_info[0])

        # We check the Cython version and some relevant configuration
        # options from the earlier build to see if we need to force a
        # recythonization. If the version or options have changed, we
        # must recythonize all files.
        self._version_file = os.path.join(self.build_dir, '.cython_version')
        self._version_stamp = json.dumps(
            {
                'version': Cython.__version__,
                'debug': self.debug,
                'directives': self.cython_directives,
                'compile_time_env': self.compile_time_env,
            },
            sort_keys=True)

        # Read an already written version file if it exists and compare to the
        # current version stamp
        try:
            if open(self._version_file).read() == self._version_stamp:
                force = False
            else:
                # version_file exists but its contents are not what we
                # want => recythonize all Cython code.
                force = True
                # In case this cythonization is interrupted, we end up
                # in an inconsistent state with C code generated by
                # different Cython versions or with different options.
                # To ensure that this inconsistent state will be fixed,
                # we remove the version_file now to force a
                # recythonization the next time we build Sage.
                os.unlink(self._version_file)
        except IOError:
            # Most likely, the version_file does not exist
            # => (re)cythonize all Cython code.
            force = True

        # If the --force flag was given at the command line, always force;
        # otherwise use what we determined from reading the version file
        if self.force is None:
            self.force = force
Beispiel #6
0
    def run(self):
        import django
        import codecs
        from pootle.apps.pootle_checks.constants import (
            CHECK_NAMES, EXCLUDED_FILTERS)
        from translate.filters.checks import (TeeChecker, StandardChecker,
                                              StandardUnitChecker)
        from translate.lang.factory import get_all_languages
        try:
            from docutils.core import publish_parts
        except ImportError:
            from distutils.errors import DistutilsModuleError
            raise DistutilsModuleError("Please install the docutils library.")
        from pootle import syspath_override  # noqa
        django.setup()

        def get_check_description(name, filterfunc):
            """Get a HTML snippet for a specific quality check description.

            The quality check description is extracted from the check function
            docstring (which uses reStructuredText) and rendered using docutils
            to get the HTML snippet.
            """
            # Provide a header with an anchor to refer to.
            description = ('\n<h3 id="%s">%s</h3>\n\n' %
                           (name, unicode(CHECK_NAMES[name])))

            # Clean the leading whitespace on each docstring line so it gets
            # properly rendered.
            docstring = "\n".join(line.strip()
                                  for line in filterfunc.__doc__.split("\n"))

            # Render the reStructuredText in the docstring into HTML.
            description += publish_parts(docstring, writer_name="html")["body"]
            return description

        print("Regenerating Translate Toolkit quality checks descriptions")

        # Get a checker with the Translate Toolkit checks. Note that filters
        # that are not used in Pootle are excluded.
        checkerclasses = [StandardChecker, StandardUnitChecker]
        # Also include language-specific checks
        checkerclasses.extend([type(lang.checker)
                               for lang in get_all_languages()
                               if lang.checker is not None])
        fd = TeeChecker(
            checkerclasses=checkerclasses
        ).getfilters(excludefilters=EXCLUDED_FILTERS)

        docs = sorted(
            get_check_description(name, f) for name, f in fd.items()
        )

        # Output the quality checks descriptions to the HTML file.
        templates_dir = os.path.join(
            os.path.abspath(os.path.dirname(__file__)), "pootle", "templates"
        )
        filename = os.path.join(templates_dir, "help/_ttk_quality_checks.html")

        with codecs.open(filename, "w", "utf-8") as f:
            f.write(u"\n".join(docs))

        print("Checks templates written to %r" % (filename))
Beispiel #7
0
def switchpreference(array_preference):
    """
	Find out if the set preference can be used ...
	"""
    have_numeric = 0
    have_numarray = 0
    have_numpy = 0
    use_numeric = 0
    use_numarray = 0
    use_numpy = 0
    try:
        import numpy
        have_numpy = 1
    except ImportError:
        pass

    try:
        import Numeric
        have_numeric = 1
    except ImportError:
        pass

    try:
        import numarray
        have_numarray = 1
    except ImportError:
        pass

    #array_preference = 'numarray'
    if array_preference != None:
        if array_preference == 'numpy':
            if have_numpy == 1:
                use_numpy = 1
            else:
                sys.stdout.write("Did not find the numpy module you asked for")

        if array_preference == 'Numeric':
            sys.stdout.write(
                "Numeric supported any longer. If you still need it write to [email protected]"
            )
#		if have_numeric == 1:
#		    use_numeric = 1
#		else:
#                         sys.stdout.write("Did not find the Numeric module you asked for")
        elif array_preference == 'numarray':
            sys.stdout.write(
                "numarray supported any longer. If you still need it write to [email protected]"
            )


#		    if have_numarray == 1:
#			use_numarray = 1
#		    else:
#			sys.stdout.write( "Did not find the numarray module you asked for")

    if use_numeric == 0 and use_numarray == 0 and use_numpy == 0:
        if have_numpy == 1:
            use_numpy = 1
        elif have_numarray == 1:
            use_numarray = 1
        elif have_numeric == 1:
            use_numeric = 1
        else:
            raise DistutilsModuleError(
                "I need either numpy, nummarray, or Numeric!")

    if use_numpy == 1:
        use_numeric = 0
        use_numarray = 0
        nummodule = "numpy"

    elif use_numeric == 1:
        #print "Using Numeric as array Package"
        use_numpy = 0
        use_numarray = 0
        nummodule = "Numeric"

    elif use_numarray == 1:
        #print "Using nummarray as array Package"
        use_numeric = 0
        use_numpy = 0
        nummodule = "numarray"
    else:
        raise DistutilsModuleError(
            "I need either numpy, nummarray or Numeric!")
    return nummodule
Beispiel #8
0
        return []

    def run(self):
        if not self.bgen_files:
            return

        try:
            from BisonGen import Main, __version__
        except ImportError, err:
            failure = str(err)
        else:
            if MINIMUM_VERSION > StrictVersion(__version__):
                failure = "found " + __version__
            else:
                failure = None

        if failure:
            msg = "%s requires BisonGen %s (%s)" % (self.command_name,
                                                    MINIMUM_VERSION, failure)
            raise DistutilsModuleError(msg)

        outputs = []
        args = ['BisonGen', '--mode=c']
        if self.force:
            args.append('--force')
        if not self.distribution.verbose:
            args.append('--quiet')
        for filename in self.bgen_files:
            outputs.extend(Main.Run(args + [filename]))
        return
Beispiel #9
0
 def run(self):
     raise DistutilsModuleError('babel is not available')