Ejemplo n.º 1
0
    def includeReqs(self, reqs, zcml_to_look_for, result, seen, exclude):
        for req in reqs:
            pkg = req.project_name
            if pkg == 'setuptools' or pkg in exclude:
                continue

            if req.extras:
                for extra in req.extras:
                    if (pkg, extra) in seen:
                        continue

                    try:
                        dist = get_provider(req)
                    except:
                        seen.add(pkg)
                        continue

                    DependencyFinder(dist).includableInfo(
                        zcml_to_look_for, result, seen, exclude, (extra,))
            else:
                if pkg in seen:
                    continue

                try:
                    dist = get_provider(req)
                except:
                    seen.add(pkg)
                    continue

                DependencyFinder(dist).includableInfo(
                    zcml_to_look_for, result, seen, exclude)
Ejemplo n.º 2
0
def is_pil_installed():
    pil_req = pkg_resources.Requirement.parse('PIL')
    try:
        pkg_resources.get_provider(pil_req)
    except pkg_resources.DistributionNotFound:
        return False
    return True
Ejemplo n.º 3
0
def package_installed(pkg):
    """Check if package is installed"""
    req = pkg_resources.Requirement.parse(pkg)
    try:
        pkg_resources.get_provider(req)
    except pkg_resources.DistributionNotFound:
        return False
    else:
        return True
Ejemplo n.º 4
0
def package_installed(pkg):
    """Check if package is installed"""
    req = pkg_resources.Requirement.parse(pkg)
    try:
        pkg_resources.get_provider(req)
    except pkg_resources.DistributionNotFound:
        return False
    else:
        return True
Ejemplo n.º 5
0
def pillow_installed():
 """Check if Pillow is installed"""
 pillow_req = pkg_resources.Requirement.parse('Pillow');
 try:
  pkg_resources.get_provider(pillow_req);
 except pkg_resources.DistributionNotFound:
  return False;
 else:
  return True;
Ejemplo n.º 6
0
def pillow_installed():
    """Check if Pillow is installed"""
    pillow_req = pkg_resources.Requirement.parse('Pillow')
    try:
        pkg_resources.get_provider(pillow_req)
    except pkg_resources.DistributionNotFound:
        return False
    else:
        return True
Ejemplo n.º 7
0
def _check_requirement(dependency_string):
    """Parses a dependency string, and checks if the specified requirement is installed

    Raises:
        VersionConflict if the requirement is installed, but with the the wrong version
        DistributionNotFound if nothing is found to provide the requirement
    """
    req = Requirement.parse(dependency_string)

    # first check if the markers specify that this requirement needs installing
    if req.marker is not None and not req.marker.evaluate():
        # not required for this environment
        return

    get_provider(req)
Ejemplo n.º 8
0
def _check_requirement(dependency_string):
    """Parses a dependency string, and checks if the specified requirement is installed

    Raises:
        VersionConflict if the requirement is installed, but with the the wrong version
        DistributionNotFound if nothing is found to provide the requirement
    """
    req = Requirement.parse(dependency_string)

    # first check if the markers specify that this requirement needs installing
    if req.marker is not None and not req.marker.evaluate():
        # not required for this environment
        return

    get_provider(req)
Ejemplo n.º 9
0
 def _prepare_bootstrap(self):
     """
   Write enough of distribute into the .pex .bootstrap directory so that
   we can be fully self-contained.
 """
     setuptools = dist_from_egg(
         self._interpreter.get_location('setuptools'))
     for fn, content_stream in DistributionHelper.walk_data(setuptools):
         if fn == 'pkg_resources.py':
             self._chroot.write(
                 content_stream.read(),
                 os.path.join(self.BOOTSTRAP_DIR, 'pkg_resources.py'),
                 'resource')
     libraries = (
         'twitter.common.python',
         'twitter.common.python.http',
     )
     for name in libraries:
         dirname = name.replace('twitter.common.python',
                                '_twitter_common_python').replace('.', '/')
         provider = get_provider(name)
         if not isinstance(provider, DefaultProvider):
             mod = __import__(name, fromlist=['wutttt'])
             provider = ZipProvider(mod)
         for fn in provider.resource_listdir(''):
             if fn.endswith('.py'):
                 self._chroot.write(
                     provider.get_resource_string(name, fn),
                     os.path.join(self.BOOTSTRAP_DIR, dirname, fn),
                     'resource')
Ejemplo n.º 10
0
  def _prepare_bootstrap(self):
    # Writes enough of setuptools into the .pex .bootstrap directory so that we can be fully
    # self-contained.

    wrote_setuptools = False
    setuptools = DistributionHelper.distribution_from_path(
        self._interpreter.get_location('setuptools'),
        name='setuptools')

    if setuptools is None:
      raise RuntimeError('Failed to find setuptools while building pex!')

    for fn, content_stream in DistributionHelper.walk_data(setuptools):
      if fn.startswith('pkg_resources') or fn.startswith('_markerlib'):
        self._chroot.write(content_stream.read(), os.path.join(self.BOOTSTRAP_DIR, fn), 'resource')
        wrote_setuptools = True

    if not wrote_setuptools:
      raise RuntimeError(
          'Failed to extract pkg_resources from setuptools.  Perhaps pants was linked with an '
          'incompatible setuptools.')

    libraries = {
      'pex': '_pex',
    }

    for source_name, target_location in libraries.items():
      provider = get_provider(source_name)
      if not isinstance(provider, DefaultProvider):
        mod = __import__(source_name, fromlist=['ignore'])
        provider = ZipProvider(mod)
      for fn in provider.resource_listdir(''):
        if fn.endswith('.py'):
          self._chroot.write(provider.get_resource_string(source_name, fn),
            os.path.join(self.BOOTSTRAP_DIR, target_location, fn), 'resource')
Ejemplo n.º 11
0
  def _prepare_bootstrap(self):
    """
      Write enough of distribute into the .pex .bootstrap directory so that
      we can be fully self-contained.
    """
    wrote_setuptools = False
    setuptools = DistributionHelper.distribution_from_path(
        self._interpreter.get_location('setuptools'))

    for fn, content_stream in DistributionHelper.walk_data(setuptools):
      if fn == 'pkg_resources.py' or fn.startswith('_markerlib'):
        self._chroot.write(content_stream.read(), os.path.join(self.BOOTSTRAP_DIR, fn), 'resource')
        wrote_setuptools = True

    if not wrote_setuptools:
      raise RuntimeError(
          'Failed to extract pkg_resources from setuptools.  Perhaps pants was linked with an '
          'incompatible setuptools.')

    libraries = (
      'twitter.common.python',
      'twitter.common.python.http',
    )

    for name in libraries:
      dirname = name.replace('twitter.common.python', '_twitter_common_python').replace('.', '/')
      provider = get_provider(name)
      if not isinstance(provider, DefaultProvider):
        mod = __import__(name, fromlist=['wutttt'])
        provider = ZipProvider(mod)
      for fn in provider.resource_listdir(''):
        if fn.endswith('.py'):
          self._chroot.write(provider.get_resource_string(name, fn),
            os.path.join(self.BOOTSTRAP_DIR, dirname, fn), 'resource')
Ejemplo n.º 12
0
 def _check_module_path(self):
     # If ferenda is imported, and the working directory of the
     # process is then changed (with os.cwd()), this can cause
     # problems with the pkg_resources API, since that module might
     # use relative paths for the location of resources, and
     # changing the working directory causes these relative paths
     # to be invalid wrt the new working directory. This seem to be
     # a problem with py2 only, since on py3 the absolute path for
     # each loaded module is stored in sys.modules which
     # pkg_resources uses.
     # 
     # This method tries to detect the problem and correct it if
     # possible.
     if self.use_pkg_resources:
         module_path = pkg_resources.get_provider("ferenda").module_path
         if not os.path.exists(module_path) and not os.path.isabs(module_path):
             # There appears to be no simple way of determining the
             # "true" path of where ferenda is installed. But if
             # os.environ["FERENDA_HOME"] is defined we can rely on
             # that. Then we directly muck with sys.modules to
             # record the absolute path to the module. This might
             # not be legal... NB: This should only happen in
             # development mode, not with an installed ferenda
             # package, and only on py2.
             if "FERENDA_HOME" in os.environ:
                 truepath = (os.environ["FERENDA_HOME"] + os.sep +
                             module_path + os.sep + "__init__.py")
                 sys.modules["ferenda"].__file__ = truepath
             else:
                 raise ResourceNotFound("pkg_resources internal variable module_path is a relative path (%s). No such path exists relative to %s" % (module_path, os.getcwd()))
 def __init__(self, allowed_template):
     self.allowed_template = allowed_template
     self.provider = get_provider(self.package_name)
     self.manager = ResourceManager()
     self.src_mock = mock.MagicMock(
         spec='jinja2.loaders.PackageLoader.get_source', autospec=True)
     self.src_mock.side_effect = self.template_source
Ejemplo n.º 14
0
def load_config(config_path):
    if config_path.startswith('/'):
        return open(config_path)

    if '=' in config_path:
        key, value = config_path.split('=', 1)
        key = key.strip()
        value = value.strip()
        try:
            json.loads(value)
        except ValueError:
            value = json.dumps(value)
        # convert key=value to key: value
        # key:value syntax is already taken by package loader
        return ['{key}: {value}'.format(key=key, value=value)]

    if ':' in config_path:
        package, relative_path = config_path.split(':', 1)

        resource_manager = pkg_resources.ResourceManager()
        provider = pkg_resources.get_provider(package)

        return provider.get_resource_stream(resource_manager, relative_path)

    return open(config_path)
Ejemplo n.º 15
0
Archivo: wsgi.py Proyecto: jso/werkzeug
 def get_package_loader(self, package, package_path):
     from pkg_resources import DefaultProvider, ZipProvider, \
          ResourceManager, get_provider
     loadtime = datetime.utcnow()
     provider = get_provider(package)
     manager = ResourceManager()
     filesystem_bound = isinstance(provider, DefaultProvider)
     zip_bound = isinstance(provider, ZipProvider)
     def loader(path):
         if path is None:
             return None, None
         path = posixpath.join(package_path, path)
         if not provider.has_resource(path):
             return None, None
         basename = posixpath.basename(path)
         if filesystem_bound:
             return basename, self._opener(
                 provider.get_resource_filename(manager, path))
         file_size = 0
         if zip_bound:
             zip_path = "/".join([
                 package.replace(".", "/"),
                 path
             ])
             file_zip_info = provider.zipinfo.get(zip_path)
             if file_zip_info:
                 file_size = file_zip_info.file_size
         return basename, lambda: (
             provider.get_resource_stream(manager, path),
             loadtime,
             file_size
         )
     return loader
Ejemplo n.º 16
0
    def do_instinfo(self, subcmd, opts):
        """
        ${cmd_name}: Get some information about the yt installation

        ${cmd_usage}
        ${cmd_option_list}
        """
        import pkg_resources
        yt_provider = pkg_resources.get_provider("yt")
        path = os.path.dirname(yt_provider.module_path)
        print
        print "yt module located at:"
        print "    %s" % (path)
        if "site-packages" not in path:
            vc_type = _get_vcs_type(path)
            vstring = _vcs_identifier[vc_type](path)
            print
            print "The current version of the code is:"
            print
            print "---"
            print vstring
            print "---"
            print
            print "This installation CAN be automatically updated."
            if opts.update_source:
                _vcs_updater[vc_type](path)
            print "Updated successfully."
Ejemplo n.º 17
0
    def installFonts(file_name):
        """
        Install the specified font file to this system.
        """
        if isinstance(pkg_resources.get_provider('pyfiglet'), pkg_resources.ZipProvider):
            # Figlet is installed using a zipped resource - don't try to upload to it.
            location = SHARED_DIRECTORY
        else:
            # Figlet looks like a standard directory - so lets use that to install new fonts.
            location = pkg_resources.resource_filename('pyfiglet', 'fonts')

        print("Installing {} to {}".format(file_name, location))

        # Make sure the required destination directory exists
        if not os.path.exists(location):
            os.makedirs(location)

        # Copy the font definitions - unpacking any zip files as needed.
        if os.path.splitext(file_name)[1].lower() == ".zip":
            # Ignore any structure inside the ZIP file.
            with zipfile.ZipFile(file_name) as zip_file:
                for font in zip_file.namelist():
                    font_file = os.path.basename(font)
                    if not font_file:
                        continue
                    with zip_file.open(font) as src:
                        with open(os.path.join(location, font_file), "wb") as dest:
                            shutil.copyfileobj(src, dest)
        else:
            shutil.copy(file_name, location)
Ejemplo n.º 18
0
    def installFonts(file_name):
        """
        Install the specified font file to this system.
        """
        if isinstance(pkg_resources.get_provider('pyfiglet'), pkg_resources.ZipProvider):
            # Figlet is installed using a zipped resource - don't try to upload to it.
            location = SHARED_DIRECTORY
        else:
            # Figlet looks like a standard directory - so lets use that to install new fonts.
            location = pkg_resources.resource_filename('pyfiglet', 'fonts')

        print("Installing {} to {}".format(file_name, location))

        # Make sure the required destination directory exists
        if not os.path.exists(location):
            os.makedirs(location)

        # Copy the font definitions - unpacking any zip files as needed.
        if os.path.splitext(file_name)[1].lower() == ".zip":
            # Ignore any structure inside the ZIP file.
            with zipfile.ZipFile(file_name) as zip_file:
                for font in zip_file.namelist():
                    font_file = os.path.basename(font)
                    if not font_file:
                        continue
                    with zip_file.open(font) as src:
                        with open(os.path.join(location, font_file), "wb") as dest:
                            shutil.copyfileobj(src, dest)
        else:
            shutil.copy(file_name, location)
Ejemplo n.º 19
0
def load_kernel(package, kernel_name):
    kernel_path = Path(
        pkg_resources.get_provider(package).get_resource_filename(
            __name__, '{}.cl'.format(kernel_name)))
    with kernel_path.open() as f:
        kernel_source = ''.join(f.readlines())
    return kernel_source
Ejemplo n.º 20
0
	def __init__(self):
		builder = gtk.Builder()

		if hasattr(sys ,'frozen'):
			from blogger_update_metatags import resources
			data = resources.GUI_XML
		else:
			try:
				import pkgutil
				data = pkgutil.get_data(__name__, 'gui.xml')
			except ImportError:
				from pkg_resources import get_provider, ResourceManager
				data = get_provider(__name__).get_resource_string(ResourceManager(), 'gui.xml')

		builder.add_from_string(data)
		builder.connect_signals(self)

		for obj in builder.get_objects():
			setattr(self, gtk.Buildable.get_name(obj), obj)

		if os.access(DEFAULT_CONFIG_FILE, os.R_OK):
			self.filechooserbutton.set_filename(DEFAULT_CONFIG_FILE)

		self.treeview_log.append_column(gtk.TreeViewColumn(None, gtk.CellRendererPixbuf(), stock_id=0))
		self.treeview_log.append_column(gtk.TreeViewColumn(None, gtk.CellRendererText(), text=1))

		self.dialog.show_all()

		logger.addHandler(GtkListStoreHandler(self.liststore_log))
Ejemplo n.º 21
0
 def _package_name(self):
     pkg_provider = pkg_resources.get_provider(self.modname)
     module_path = self.modname.replace('.', os.sep)
     is_package = pkg_provider.module_path.endswith(module_path)
     if is_package:
         return self.modname
     return self.modname.rsplit('.', 1)[0]
Ejemplo n.º 22
0
    def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, \
            get_provider
        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None
            path = posixpath.join(package_path, path)
            if not provider.has_resource(path):
                return None, None
            basename = posixpath.basename(path)
            if filesystem_bound:
                return basename, self._opener(
                    provider.get_resource_filename(manager, path))
            s = provider.get_resource_string(manager, path)
            return basename, lambda: (
                BytesIO(s),
                loadtime,
                len(s)
            )
        return loader
Ejemplo n.º 23
0
 def getModuleFormat(self,importModulePath):
     provider = pkg_resources.get_provider(importModulePath)
     format = 'Null'
     if isinstance(provider, pkg_resources.EggProvider): format = 'Egg'
     if isinstance(provider, pkg_resources.DefaultProvider): format = 'File'
     if isinstance(provider, pkg_resources.ZipProvider): format = 'Zip'
     return format
Ejemplo n.º 24
0
 def _package_name(self):
     pkg_provider = pkg_resources.get_provider(self.modname)
     module_path = self.modname.replace('.', os.sep)
     is_package = pkg_provider.module_path.endswith(module_path)
     if is_package:
         return self.modname
     return self.modname.rsplit('.', 1)[0]
    def add_source(self, name, package_name, directory, cache_max_age=None):
        """
        Add a static files source directory, optionally associated with a
        python package.

        :param name: The (unique) name used to identify this source.
        :param package_name: The name of the python package containing the
                             files
        :param directory: Path to the directory containing the
                          static files. Should be relative if package_name is
                          specified, otherwise absolute.
        :param cache_max_age: Optional duration in seconds for the
                              Cache-Control max-age header. If omitted the
                              default value is used
        """
        if name in self.sources:
            raise ValueError("StaticFiles source %r is already used" %
                             (name, ))

        if package_name:
            map_path = get_provider(package_name).get_resource_filename
        else:

            def map_path(resource_manager, path):
                return path

        static_root = map_path(self.resource_manager, directory)
        if not isdir(static_root):
            raise ValueError("%r is not a directory" % (static_root, ))

        cache_max_age = (self.cache_max_age
                         if cache_max_age is None else cache_max_age)

        self.sources[name] = (map_path, directory, cache_max_age)
Ejemplo n.º 26
0
    def includableInfo(self, zcml_to_look_for):
        """Return the packages in the dependencies which are includable.

        zcml_to_look_for - a list of zcml filenames we are looking for

        Returns a dictionary with the include candidates as keys, and lists
        of dotted names of packages that contain the include candidates as
        values.
        """
        result = ZCMLInfo(zcml_to_look_for)
        for req in self.context.requires():
            dist_manager = DistributionManager(get_provider(req))
            for dotted_name in dist_manager.dottedNames():
                try:
                    module = resolve(dotted_name)
                except ImportError as exc:
                    logging.getLogger("z3c.autoinclude").warn(
                        "resolve(%r) raised import error: %s" % (dotted_name, exc))
                    continue
                for candidate in zcml_to_look_for:
                    candidate_path = os.path.join(
                        os.path.dirname(module.__file__), candidate)
                    if os.path.isfile(candidate_path):
                        result[candidate].append(dotted_name)
        return result
Ejemplo n.º 27
0
    def includableInfo(self, zcml_to_look_for):
        """Return the packages in the dependencies which are includable.

        zcml_to_look_for - a list of zcml filenames we are looking for

        Returns a dictionary with the include candidates as keys, and lists
        of dotted names of packages that contain the include candidates as
        values.
        """
        result = ZCMLInfo(zcml_to_look_for)
        for req in self.context.requires():
            dist_manager = DistributionManager(get_provider(req))
            for dotted_name in dist_manager.dottedNames():
                try:
                    module = resolve(dotted_name)
                except ImportError as exc:
                    logger.warning(
                        "resolve(%r) raised import error: %s" % (dotted_name, exc))
                    continue
                module_file = getattr(module, '__file__', None)
                if module_file is None:
                    logger.warning(
                        "%r has no __file__ attribute" % dotted_name)
                    continue
                for candidate in zcml_to_look_for:
                    candidate_path = os.path.join(
                        os.path.dirname(module_file), candidate)
                    if os.path.isfile(candidate_path):
                        result[candidate].append(dotted_name)
        return result
Ejemplo n.º 28
0
 def _check_module_path(self):
     # If ferenda is imported, and the working directory of the
     # process is then changed (with os.cwd()), this can cause
     # problems with the pkg_resources API, since that module might
     # use relative paths for the location of resources, and
     # changing the working directory causes these relative paths
     # to be invalid wrt the new working directory. This seem to be
     # a problem with py2 only, since on py3 the absolute path for
     # each loaded module is stored in sys.modules which
     # pkg_resources uses.
     #
     # This method tries to detect the problem and correct it if
     # possible.
     if self.use_pkg_resources:
         module_path = pkg_resources.get_provider("ferenda").module_path
         if not os.path.exists(module_path) and not os.path.isabs(
                 module_path):
             # There appears to be no simple way of determining the
             # "true" path of where ferenda is installed. But if
             # os.environ["FERENDA_HOME"] is defined we can rely on
             # that. Then we directly muck with sys.modules to
             # record the absolute path to the module. This might
             # not be legal... NB: This should only happen in
             # development mode, not with an installed ferenda
             # package, and only on py2.
             if "FERENDA_HOME" in os.environ:
                 truepath = (os.environ["FERENDA_HOME"] + os.sep +
                             module_path + os.sep + "__init__.py")
                 sys.modules["ferenda"].__file__ = truepath
             else:
                 raise ResourceNotFound(
                     "pkg_resources internal variable module_path is a relative path (%s). No such path exists relative to %s"
                     % (module_path, os.getcwd()))
Ejemplo n.º 29
0
def set_project_info():
    """Set project information from setup tools installation."""
    # CUSTOMIZE THIS VALUE FOR YOUR OWN INSTALLATION
    base_url = 'https://slack-tableflip.herokuapp.com'

    # Get app info from the dist
    app_name = 'slack_tableflip'
    provider = get_provider(app_name)

    return {
        'name': app_name,
        'name_full': 'EM Slack Tableflip',
        'author_url': 'http://www.erinmorelli.com',
        'github_url': 'https://github.com/ErinMorelli/em-slack-tableflip',
        'version': '1.5',
        'version_int': 1.5,
        'package_path': provider.module_path,
        'copyright': '2015-{0}'.format(str(date.today().year)),
        'client_secret': os.environ['SLACK_CLIENT_SECRET'],
        'client_id': os.environ['SLACK_CLIENT_ID'],
        'base_url': base_url,
        'oauth_url': 'https://slack.com/oauth/authorize',
        'auth_url': '{0}/authenticate'.format(base_url),
        'user_url': '{0}/validate'.format(base_url),
        'team_url': '{0}/authorize'.format(base_url),
        'team_scope': [
            'commands'
        ],
        'user_scope': [
            'chat:write:bot',
            'chat:write:user',
            'identify'
        ]
    }
Ejemplo n.º 30
0
    def get_package_loader(self, package, package_path):
        from pkg_resources import DefaultProvider, ResourceManager, get_provider

        loadtime = datetime.utcnow()
        provider = get_provider(package)
        manager = ResourceManager()
        filesystem_bound = isinstance(provider, DefaultProvider)

        def loader(path):
            if path is None:
                return None, None

            path = posixpath.join(package_path, path)

            if not provider.has_resource(path):
                return None, None

            basename = posixpath.basename(path)

            if filesystem_bound:
                return (
                    basename,
                    self._opener(provider.get_resource_filename(manager, path)),
                )

            s = provider.get_resource_string(manager, path)
            return basename, lambda: (BytesIO(s), loadtime, len(s))

        return loader
Ejemplo n.º 31
0
def update_periods_file():
    mapping = generate_mapping()
    
    path = get_provider(__name__).module_path
    with open(pjoin(path, "periods.yaml"), "wb") as fd:
        fd.write(dump(mapping))
    print "Periods file updated with %i entries" % len(mapping)
Ejemplo n.º 32
0
    def __init__(self):
        """ Initialize CLI.
        """
        self.startup = time.time()
        self.LOG = pymagic.get_class_logger(self)

        # Get version number
        self.version = self.VERSION
        if not self.version:
            # Take version from package
            provider = pkg_resources.get_provider(__name__)
            pkg_info = provider.get_metadata("PKG-INFO")

            if not pkg_info:
                pkg_info = "Version: 0.0.0\n"
                try:
                    # Development setup
                    pkg_path = os.path.join(
                        __file__.split(__name__.replace(
                            '.', os.sep))[0],  # containing path
                        __name__.split(".")[0]  # package name
                    )
                    if os.path.exists(pkg_path + ".egg-info"):
                        pkg_path += ".egg-info"
                    else:
                        pkg_path = glob.glob(pkg_path + "-*-py%d.%d.egg-info" %
                                             sys.version_info[:2])
                        if len(pkg_path) == 1:
                            pkg_path = pkg_path[0]
                        else:
                            self.LOG.warn("Found %d candidate versions" %
                                          len(pkg_path))
                            pkg_path = None
                    if pkg_path:
                        with closing(open(os.path.join(pkg_path,
                                                       "PKG-INFO"))) as handle:
                            pkg_info = handle.read()
                    else:
                        self.LOG.warn("Software version cannot be determined!")
                except IOError:
                    self.LOG.warn("Software version cannot be determined!")

            pkg_info = dict(
                line.split(": ", 1) for line in pkg_info.splitlines()
                if ": " in line)
            self.version = pkg_info.get("Version", "DEV")

        self.args = None
        self.options = None
        self.return_code = 0
        self.parser = OptionParser(
            "%prog [options] " + self.ARGS_HELP + "\n\n"
            "%prog " + self.version +
            (", " + self.COPYRIGHT if self.COPYRIGHT else "") + "\n\n" +
            textwrap.dedent(self.__doc__.rstrip()).lstrip('\n') +
            '\n'.join(self.ADDITIONAL_HELP) +
            "\n\nFor more details, see the full documentation at" +
            "\n\n    https://pyrocore.readthedocs.io/",
            version="%prog " + self.version)
Ejemplo n.º 33
0
 def get_version_from_pkg_resources(package):
     try:
         requirement = pkg_resources.Requirement.parse(package)
         provider = pkg_resources.get_provider(requirement)
         return provider.version
     except Exception as err:
         print(f"get_version_from_pkg_resources: {err}")
         return None
Ejemplo n.º 34
0
 def _get_provider(self):
     if self._provider is None:
         try:
             requirement = pkg_resources.Requirement.parse(self.package)
             self._provider = pkg_resources.get_provider(requirement)
         except pkg_resources.DistributionNotFound:
             pass
     return self._provider
Ejemplo n.º 35
0
 def __init__(self, package_name, package_path = 'templates', encoding = 'utf-8'):
     from pkg_resources import DefaultProvider, ResourceManager, get_provider
     provider = get_provider(package_name)
     self.encoding = encoding
     self.manager = ResourceManager()
     self.filesystem_bound = isinstance(provider, DefaultProvider)
     self.provider = provider
     self.package_path = package_path
Ejemplo n.º 36
0
def enclose_package_path_exists(package_name):
    """
    Returns a `path_exists` method that searches within the specified package
    """
    # NOTE: I don't really like the `enclose_...` name, if anyone wants to
    #       refactor this name, please feel free
    provider = pkg_resources.get_provider(package_name)
    return provider.has_resource
Ejemplo n.º 37
0
 def _get_provider(self):
     if self._provider is None:
         try:
             requirement = pkg_resources.Requirement.parse(self.package)
             self._provider = pkg_resources.get_provider(requirement)
         except pkg_resources.DistributionNotFound:
             pass
     return self._provider
Ejemplo n.º 38
0
 def __init__(self, package_name, package_path='templates',
              encoding='utf-8'):
     provider = get_provider(package_name)
     self.encoding = encoding
     self.manager = ResourceManager()
     self.filesystem_bound = isinstance(provider, DefaultProvider)
     self.provider = provider
     self.package_path = package_path
Ejemplo n.º 39
0
 def list_children(self):
     provider = pkg_resources.get_provider(self.mod_name)
     children = []
     for f in provider.resource_listdir('.'):
         if f.endswith('.py'):
             children.append(f[:-3])
         elif '.' not in f and provider.has_resource(os.path.join(f, '__init__.py')):
             children.append(f)
     return sorted(set(children))
Ejemplo n.º 40
0
 def load_resource(self, rp=None, package='stackdio'):
     """
     Takes a relative path `rp`, and attempts to pull the full resource
     path using pkg_resources.
     """
     provider = get_provider(package)
     if rp is None:
         return os.path.dirname(provider.module_path)
     return provider.get_resource_filename(ResourceManager(), rp)
Ejemplo n.º 41
0
 def load_resource(self, rp=None, package='stackdio'):
     """
     Takes a relative path `rp`, and attempts to pull the full resource
     path using pkg_resources.
     """
     provider = get_provider(package)
     if rp is None:
         return os.path.dirname(provider.module_path)
     return provider.get_resource_filename(ResourceManager(), rp)
Ejemplo n.º 42
0
 def load_templates(self):
     for package_name in self.modules:
         try:
             pkg = self.packages[package_name] = {}
             pkg['provider'] = get_provider(package_name)
             pkg['fs_bound'] = isinstance(pkg['provider'], DefaultProvider)
         except Exception as e:
             trace = str(traceback.format_exc())
             log.error("Can't import module %s\n%s" % (str(e), trace))
Ejemplo n.º 43
0
    def __init__(self, module, env=None):
        """Initialize the Environment object
		:param module: The Module that serves as the basis for this botoweb application
		:param env: Optional environment file that overrides any settings in our config
		"""
        self.module = module
        self._client_connection = None
        if not env:
            env = os.environ.get("BOTO_WEB_ENV")
        self.env = env

        # Config setup
        self.config = Config()
        self.config.env = self

        self.dist = get_provider(self.module)
        self.mgr = ResourceManager()

        if self.dist.has_resource("conf"):
            self.config.update(self.get_config("conf"))

        if env and os.path.exists(self.env):
            log.info("Loading environment: %s" % self.env)
            self.config.update(yaml.load(open(self.env, "r")))

        # Set up the DB shortcuts
        if not self.config.has_key("DB"):
            self.config['DB'] = {
                "db_type":
                self.config.get("DB", "db_type", "SimpleDB"),
                "db_user":
                self.config.get("Credentials", "aws_access_key_id"),
                "db_passwd":
                self.config.get("Credentials", "aws_secret_access_key")
            }
        if self.config.has_key("auth_db"):
            self.config['DB']['User'] = {"db_name": self.config['auth_db']}
        if self.config.has_key("default_db"):
            self.config['DB']['db_name'] = self.config["default_db"]
        if self.config.has_key("session_db"):
            self.config['DB']['Session'] = {
                'db_name': self.config["session_db"]
            }

        # Bootstrap importing all db_classes for XMLize
        if self.config['botoweb'].has_key("handlers"):
            for handler in self.config['botoweb']['handlers']:
                if handler.has_key("db_class"):
                    try:
                        db_class = find_class(handler['db_class'])
                    except:
                        log.exception("Could not load class: %s" %
                                      handler['db_class'])
                        db_class = None
                    if db_class:
                        xmlize.register(db_class)
Ejemplo n.º 44
0
def test_redocjs_lib_is_copied(run_sphinx, tmpdir):
    outdir = tmpdir.join('out')
    extdir = py.path.local(
        pkg_resources.get_provider('sphinxcontrib.redoc').module_path)

    run_sphinx()

    assert outdir.join('_static', 'redoc.js').check()
    assert outdir.join('_static', 'redoc.js').computehash() \
        == extdir.join('redoc.js').computehash()
Ejemplo n.º 45
0
 def setUp(self):
     self.port = random.randrange(10000, 20000)
     provider = pkg_resources.get_provider(__name__)
     demo_config_path = provider.get_resource_filename(None, 'demo_config.py')
     self.process = subprocess.Popen([
         os.path.join(os.path.dirname(sys.executable),
                      'fake_jenkins'),
         '0.0.0.0',
         str(self.port)
     ], env={'FAKE_JENKINS_CONFIG_FILE': demo_config_path})
Ejemplo n.º 46
0
    def __init__(self, package_name, package_path="templates", encoding="utf-8", get_language=None):
        from pkg_resources import DefaultProvider, ResourceManager, get_provider

        provider = get_provider(package_name)
        self.encoding = encoding
        self.manager = ResourceManager()
        self.filesystem_bound = isinstance(provider, DefaultProvider)
        self.provider = provider
        self.package_path = package_path
        self.get_language = get_language or (lambda: [])
Ejemplo n.º 47
0
  def _prepare_bootstrap(self):
    """
      Write enough of distribute and pip into the .pex .bootstrap directory so that
      we can be fully self-contained.
    """
    bare_env = pkg_resources.Environment()

    pip_req = pkg_resources.Requirement.parse('pip>=1.1')
    distribute_req = pkg_resources.Requirement.parse('distribute>=0.6.24')
    pip_dist = distribute_dist = None

    for dist in DistributionHelper.all_distributions(sys.path):
      if dist in pip_req and bare_env.can_add(dist):
        pip_dist = dist
      if dist in distribute_req and bare_env.can_add(dist):
        distribute_dist = dist
      if pip_dist and distribute_dist:
        break
    if not pip_dist:
      raise DistributionNotFound('Could not find pip!')
    if not distribute_dist:
      raise DistributionNotFound('Could not find distribute!')

    PEX.debug('Writing .bootstrap library.')
    for fn, content in DistributionHelper.walk_data(pip_dist):
      if fn.startswith('pip/'):
        # PEX.debug('BOOTSTRAP: Writing %s' % fn)
        self._chroot.write(content, os.path.join(self.BOOTSTRAP_DIR, fn), 'resource')
    for fn, content in DistributionHelper.walk_data(distribute_dist):
      if fn.startswith('pkg_resources.py') or fn.startswith('setuptools'):
        # PEX.debug('BOOTSTRAP: Writing %s' % fn)
        self._chroot.write(content, os.path.join(self.BOOTSTRAP_DIR, fn), 'resource')
    libraries = (
      'twitter.common.dirutil',
      'twitter.common.collections',
      'twitter.common.contextutil',
      'twitter.common.lang',
      'twitter.common.python'
    )
    for name in libraries:
      dirname = name.replace('.', '/')
      provider = pkg_resources.get_provider(name)
      if not isinstance(provider, pkg_resources.DefaultProvider):
        mod = __import__(name, fromlist=['wutttt'])
        provider = pkg_resources.ZipProvider(mod)
      for fn in provider.resource_listdir(''):
        if fn.endswith('.py'):
          # PEX.debug('BOOTSTRAP: Writing %s' % os.path.join(dirname, fn))
          self._chroot.write(provider.get_resource_string(name, fn),
            os.path.join(self.BOOTSTRAP_DIR, dirname, fn), 'resource')
    for initdir in ('twitter', 'twitter/common'):
      self._chroot.write(
        b"__import__('pkg_resources').declare_namespace(__name__)",
        os.path.join(self.BOOTSTRAP_DIR, initdir, '__init__.py'),
        'resource')
Ejemplo n.º 48
0
    def __init__(self, package_name, package_path="templates", encoding="utf-8"):
        from pkg_resources import DefaultProvider
        from pkg_resources import get_provider
        from pkg_resources import ResourceManager

        provider = get_provider(package_name)
        self.encoding = encoding
        self.manager = ResourceManager()
        self.filesystem_bound = isinstance(provider, DefaultProvider)
        self.provider = provider
        self.package_path = package_path
Ejemplo n.º 49
0
    def getTemplate(cls, fname):
        current_module = sys.modules[__name__]
        provider = get_provider(current_module.__package__)
        manager = ResourceManager()

        p = "/".join(['templates', fname])

        if not provider.has_resource(p):
            raise Exception("Template not found: %s", fname)

        return provider.get_resource_string(manager, p)
Ejemplo n.º 50
0
def get_yt_version():
    try:
        from yt.__hg_version__ import hg_version
        return hg_version
    except ImportError:
        pass
    import pkg_resources
    yt_provider = pkg_resources.get_provider("yt")
    path = os.path.dirname(yt_provider.module_path)
    version = get_hg_version(path)[:12]
    return version
Ejemplo n.º 51
0
    def __init__(self, package, path=''):
        """
        Initialize package resource provider.

        :param string package: python package/module name or object
        :param string path: name of a resource relative to the package
        """
        self.package = package
        self.path = path
        self._manager = _manager
        self._provider = pkg_resources.get_provider(package)
Ejemplo n.º 52
0
def get_yt_version():
    try:
        from yt.__hg_version__ import hg_version
        return hg_version
    except ImportError:
        pass
    import pkg_resources
    yt_provider = pkg_resources.get_provider("yt")
    path = os.path.dirname(yt_provider.module_path)
    version = get_hg_version(path)[:12]
    return version
Ejemplo n.º 53
0
def get_example_data(dataset_name):
    """
    This is a smart package loader that locates text files inside our package
    :param dataset_name:
    :return:
    """
    provider = get_provider('ebu_tt_live')
    manager = ResourceManager()

    source = provider.get_resource_string(manager, 'example_data/'+dataset_name)

    return source
Ejemplo n.º 54
0
    def __init__(self, package, path=''):
        """
        Initialize package resource provider.

        :param string package: python package/module name or object
        :param string path: name of a resource relative to the package

        """
        self.package = package
        self.path = path
        self._manager = _manager
        self._provider = pkg_resources.get_provider(package)
Ejemplo n.º 55
0
 def __init__(self,
              package_name,
              package_path='templates',
              encoding='utf-8'):
     from pkg_resources import DefaultProvider, ResourceManager, \
                               get_provider
     provider = get_provider(package_name)
     self._encoding = encoding
     self._manager = ResourceManager()
     self._filesystem_bound = isinstance(provider, DefaultProvider)
     self._provider = provider
     self._package_path = package_path
Ejemplo n.º 56
0
    def __call__(self, component):
        """
        Load a Jinja2 Environment for a component.
        """
        package_path = join(self.templates_path, component)

        provider = get_provider(self.package_name)
        if not provider.resource_isdir(package_path):
            return Environment(loader=EmptyLoader())

        return Environment(loader=PackageLoader(self.package_name, package_path),
                           undefined=StrictUndefined)
Ejemplo n.º 57
0
 def _get_version_from_pkg_resources(self):
     """Get the version of the package from the pkg_resources record
     associated with the package."""
     try:
         requirement = pkg_resources.Requirement.parse(self.package)
         provider = pkg_resources.get_provider(requirement)
         return provider.version
     except pkg_resources.DistributionNotFound:
         # The most likely cause for this is running tests in a tree
         # produced from a tarball where the package itself has not been
         # installed into anything. Revert to setup-time logic.
         return "8.0.0.20"