Beispiel #1
0
 def run(self):
     if not callable(self.artifact_builder):
         raise DistutilsModuleError(
             "artifact_builder is not callable for %s" % self)
     if self.dry_run:
         return
     package_name = self.distribution.get_name()
     if not self.artifact_builder([package_name]):
         raise DistutilsModuleError(
             "some entries in registry '%s' defined for package '%s' "
             "failed to generate an artifact" % (
                 self.artifact_builder.registry_name,
                 package_name,
             ))
Beispiel #2
0
def get_saved_password(name):
    r"""Retrieve previously saved password. The password is returned 
        unencrypted.  *name* is used to lookup a password on this machine,
        which must be the same *name* used in :py:func:`.save_password`."""

    try:
        # Only import pywin32 dependency if user creates a project
        # that requires encrypted password.
        import win32crypt
    except ImportError:
        raise DistutilsModuleError("system missing required win32api "
                "module. You can download from "
                "http://sourceforge.net/projects.pywin32")

    try:
        # retrieve value from user's private registry

        with _winreg.OpenKeyEx(_winreg.HKEY_CURRENT_USER,
                "SOFTWARE\\signet") as key:

            enc = _winreg.QueryValue(key, name)
            enc =  base64.b64decode(enc)

            # decrypt password using DPAPI (CRYPTPROECT_LOCAL_MACHINE)

            return win32crypt.CryptUnprotectData(enc, 
                            None, None, None, 4)[1]

    except (WindowsError, IndexError):
        return None
Beispiel #3
0
 def initialize_options(self):
     if not HAVE_CYTHON:
         raise DistutilsModuleError(
             'Cython is required to compile the package.\n'
             'Cython can be obtained at www.cython.org or installed with '
             'conda or pip.')
     super(build_ext, self).initialize_options()
Beispiel #4
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 #5
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'.
    """

    hooks = getattr(cmd_obj, hook_kind, None)

    if not hooks:
        return

    for modname, hook in hooks:
        if isinstance(hook, str):
            try:
                hook_obj = resolve_name(hook)
            except ImportError as exc:
                raise DistutilsModuleError('cannot find hook {0}: {1}'.format(
                    hook, err))
        else:
            hook_obj = hook

        if not callable(hook_obj):
            raise DistutilsOptionError('hook {0!r} is not callable' % hook)

        log.info('running {0} from {1} for {2} command'.format(
            hook_kind.rstrip('s'), modname, cmd_obj.get_command_name()))

        try:
            hook_obj(cmd_obj)
        except Exception as exc:
            log.error('{0} command hook {1} raised an exception: %s\n'.format(
                hook_obj.__name__, cmd_obj.get_command_name()))
            log.error(traceback.format_exc())
            sys.exit(1)
Beispiel #6
0
    def run(self):
        import django
        import codecs
        from pootle.apps.pootle_misc.checks import check_names, excluded_filters
        from translate.filters.checks import (
            TeeChecker,
            StandardChecker,
            StandardUnitChecker,
        )

        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, str(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.
        fd = TeeChecker(
            checkerclasses=[StandardChecker, StandardUnitChecker]).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 get_file_list(self):
        try:
            from distutils.errors import DistutilsModuleError
            import subprocess
            p = subprocess.Popen(['hg', 'manifest'], stdout=subprocess.PIPE)
            exitcode = p.wait()
            if exitcode != 0:
                raise DistutilsModuleError("Mercurial exited with non-zero "
                                           "exit code: %d" % exitcode)
            files = p.stdout.read().strip().split('\n')

            # Add the files *before* the normal manifest magic is
            # done. That allows the manifest template to exclude some
            # files tracked by hg and to include others.
            self.filelist.extend(files)
            sdist.get_file_list(self)
        except OSError, e:
            raise DistutilsModuleError("could not execute Mercurial: %s" % e)
Beispiel #8
0
def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
    """Generate an instance of some CCompiler subclass for the supplied
    platform/compiler combination.  'plat' defaults to 'os.name'
    (eg. 'posix', 'nt'), and 'compiler' defaults to the default compiler
    for that platform.  Currently only 'posix' and 'nt' are supported, and
    the default compilers are "traditional Unix interface" (UnixCCompiler
    class) and Visual C++ (MSVCCompiler class).  Note that it's perfectly
    possible to ask for a Unix compiler object under Windows, and a
    Microsoft compiler object under Unix -- if you supply a value for
    'compiler', 'plat' is ignored.
    """
    if plat is None:
        plat = os.name

    try:
        if compiler is None:
            compiler = get_default_compiler(plat)

        (module_name, class_name, long_description) = compiler_class[compiler]
    except KeyError:
        msg = "don't know how to compile C/C++ code on platform '%s'" % plat
        if compiler is not None:
            msg = msg + " with '%s' compiler" % compiler
        raise DistutilsPlatformError(msg)

    try:
        module_name = "distutils." + module_name
        __import__(module_name)
        module = sys.modules[module_name]
        klass = vars(module)[class_name]
    except ImportError:
        raise DistutilsModuleError(
            "can't compile C/C++ code: unable to load module '%s'" %
            module_name)
    except KeyError:
        raise DistutilsModuleError(
            "can't compile C/C++ code: unable to find class '%s' "
            "in module '%s'" % (class_name, module_name))

    # XXX The None is necessary to preserve backwards compatibility
    # with classes that expect verbose to be the first positional
    # argument.
    return klass(None, dry_run, force)
def new_compiler (plat=None,
                  compiler=None,
                  verbose=None,
                  dry_run=0,
                  force=0):
    # Try first C compilers from numpy.distutils.
    if verbose is None:
        verbose = log.get_threshold() <= log.INFO
    if plat is None:
        plat = os.name
    try:
        if compiler is None:
            compiler = get_default_compiler(plat)
        (module_name, class_name, long_description) = compiler_class[compiler]
    except KeyError:
        msg = "don't know how to compile C/C++ code on platform '%s'" % plat
        if compiler is not None:
            msg = msg + " with '%s' compiler" % compiler
        raise DistutilsPlatformError(msg)
    module_name = "numpy.distutils." + module_name
    try:
        __import__ (module_name)
    except ImportError:
        msg = str(get_exception())
        log.info('%s in numpy.distutils; trying from distutils',
                 str(msg))
        module_name = module_name[6:]
        try:
            __import__(module_name)
        except ImportError:
            msg = str(get_exception())
            raise DistutilsModuleError("can't compile C/C++ code: unable to load module '%s'" % \
                  module_name)
    try:
        module = sys.modules[module_name]
        klass = vars(module)[class_name]
    except KeyError:
        raise DistutilsModuleError(("can't compile C/C++ code: unable to find class '%s' " +
               "in module '%s'") % (class_name, module_name))
    compiler = klass(None, dry_run, force)
    compiler.verbose = verbose
    log.debug('new_compiler returns %s' % (klass))
    return compiler
Beispiel #10
0
 def run(self):
     if self.reuse_acts and is_acts_importable():
         self.announce('Reusing existing ACTS installation', log.WARN)
     else:
         self.announce('Installing ACTS library', log.WARN)
         setup_acts_for_cmd_or_die("install")
         self.announce('ACTS installed.', log.WARN)
     if not is_acts_importable():
         raise DistutilsModuleError("Cannot import acts after installation")
     install.run(self)
     set_permissions_for_host_executables(self.get_outputs())
Beispiel #11
0
def save_password(name, password):
    r"""Save password to user's private registry (encrypted). *name* is used
        to save a password on this machine and can be any string that complies
        with Windows's registry naming rules. *password* is the plain text
        password associated with *name*. Set *password* to None, to delete
        value from the registry.
    
        **TIP** I recommend you use the certificate expiration date as the name.
        Remebering when a cert will expire is a maintenance headache, and using
        this as the name will help with this chore.

        Example use::

            >>> from signet.command.sign_code import *
            >>> save_password('Cert-1-Expires-2014-11', 'abc123')
            >>> get_saved_password('Cert-1-Expires-2014-11')
            'abc123'
        """

    if password is None:
        _winreg.DeleteKey(_winreg.HKEY_CURRENT_USER,
                "SOFTWARE\\signet\\%s" % name)
        return

    try:
        # Only import pywin32 dependency if user creates a project
        # that requires encrypted password.

        import win32crypt
    except ImportError:
        raise DistutilsModuleError("system missing required win32api "
                "module. You can download from "
                "http://sourceforge.net/projects/pywin32")

    # encrypt password using DPAPI (CRYPTPROECT_LOCAL_MACHINE)

    enc = win32crypt.CryptProtectData(password, name,
                None, None, None, 4)
    enc = base64.b64encode(enc)

    # create any missing subkeys

    key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, 
                "SOFTWARE\\signet")

    # save password

    _winreg.SetValue(key, name, _winreg.REG_SZ, enc)
Beispiel #12
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 #13
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 #14
0
 def run(self):
     raise DistutilsModuleError('babel is not available')
Beispiel #15
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 #16
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 #17
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 #18
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