当前位置: 首页>>代码示例>>Python>>正文


Python pkg_resources.Environment类代码示例

本文整理汇总了Python中pkg_resources.Environment的典型用法代码示例。如果您正苦于以下问题:Python Environment类的具体用法?Python Environment怎么用?Python Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Environment类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(
         self, index_url="https://pypi.python.org/simple", hosts=('*',),
         ca_bundle=None, verify_ssl=True, *args, **kw
         ):
     Environment.__init__(self,*args,**kw)
     self.index_url = index_url + "/"[:not index_url.endswith('/')]
     self.scanned_urls = {}
     self.fetched_urls = {}
     self.package_pages = {}
     self.allows = re.compile('|'.join(map(translate,hosts))).match
     self.to_scan = []
     if verify_ssl and ssl_support.is_available and (ca_bundle or ssl_support.find_ca_bundle()):
         self.opener = ssl_support.opener_for(ca_bundle)
开发者ID:Yankur,项目名称:Web-application,代码行数:13,代码来源:package_index.py

示例2: _init_environment

	def _init_environment(self):
		dist_folders = map(lambda d: os.path.join(os.getcwd(), self.mod_folder, d), os.listdir(self.mod_folder))
		dist_folders = filter(lambda f: os.path.exists(os.path.join(f, "EGG-INFO")), dist_folders)
		dists = map(lambda f: Distribution.from_filename(f) , dist_folders)
		#
		self.pkg_env = Environment()
		for dist in dists: self.pkg_env.add(dist)
开发者ID:tuxpiper,项目名称:raduga,代码行数:7,代码来源:distmgr.py

示例3: init_env

 def init_env(self):
     self.ws = WorkingSet(entries=())
     self.env = Environment(search_path=[self.eggs_dir])
开发者ID:anybox,项目名称:anybox.buildbot.odoo,代码行数:3,代码来源:unibootstrap.py

示例4: Bootstrapper


#.........这里部分代码省略.........
        try:
            if b_version is None:
                # not passed on command line, not read from config file
                # TODO don't hardcode exe path (not so easy)
                cmd = ["bin/buildout", "--version"]
                cmd_str = ' '.join(cmd)
                logger.info("No buildout version has been specified on "
                            "command line nor in bootstrap config file. "
                            "Using the one stage 2 produced (%s)",
                            cmd_str)
                buildout = subprocess.Popen(cmd, stdout=subprocess.PIPE)
                out = buildout.communicate()[0]
                if buildout.returncode == 0:
                    b_version = out.decode().split()[-1]
                else:
                    raise RuntimeError(cmd_str + " has errors")

            with open(out_path, 'w') as ini:
                ini.write('\n'.join((
                    "# Produced by unibootstrap",
                    "# at time (UTC): " + datetime.utcnow().isoformat(),
                    "# with Python " + sys.version.splitlines()[0],
                    "",
                    "[bootstrap]",
                    "buildout-version = " + b_version,
                )))
        except Exception as exc:
            logger.error("Could not write used "
                         "buildout version in %r (%s)", out_path, exc)
        logger.info("Wrote buildout version %s to %s", b_version, out_path)

    def init_env(self):
        self.ws = WorkingSet(entries=())
        self.env = Environment(search_path=[self.eggs_dir])

    def init_reqs(self, buildout_version,
                  force_setuptools_path=None,
                  force_setuptools=None, force_distribute=None):
        """Sets wished requirement attributes.

        These attributes are instances of ``Requirement`` (all needed
        workarounds for that have already been done), plus this method
        also creates the attributes that will be used in
        :meth:`grab_req`

        :param buildout_version: same as in :func:`guess_versions`
        :param force_setuptools_path: if set, this setuptools distribution
                                      will be used both to grab zc.buildout
                                      and in stage2 of bootstrap. This has
                                      precedence over the other 'force'
                                      arguments below.
        :param force_setuptools: force a setuptools (not distribute) req, and
                                 make the necessary preparations for it.
        :param force_distribute: force a distribute (not setuptools) req, and
                                 make the necessary preparations for it.
        """
        self.init_env()
        buildout_rhs, setuptools, setuptools_rhs = guess_versions(
            buildout_version)
        self.buildout_req = Requirement.parse('zc.buildout' + buildout_rhs)
        # this is almost the CLI, but that lets us control which one is
        # executed from PYTHONPATH (finding the equivalent executable would be
        # more hazardeous)
        self._ez_install = (
            sys.executable, '-c',
            "from setuptools.command.easy_install import main; main()",
开发者ID:anybox,项目名称:anybox.buildbot.odoo,代码行数:67,代码来源:unibootstrap.py

示例5: DistributionsManager

class DistributionsManager(object):
	def __init__(self):
		self.mod_folder = os.path.join(os.getcwd(), "raduga_modules")
		if not os.path.exists(self.mod_folder):
			os.mkdir(self.mod_folder)
		self._init_environment()

	def _init_environment(self):
		dist_folders = map(lambda d: os.path.join(os.getcwd(), self.mod_folder, d), os.listdir(self.mod_folder))
		dist_folders = filter(lambda f: os.path.exists(os.path.join(f, "EGG-INFO")), dist_folders)
		dists = map(lambda f: Distribution.from_filename(f) , dist_folders)
		#
		self.pkg_env = Environment()
		for dist in dists: self.pkg_env.add(dist)

	def _add_to_environment(self, egg_folder):
		dist = Distribution.from_filename(egg_folder)
		self.pkg_env.add(dist)

	def _match_req(self, req):
		return self.pkg_env.best_match(req, working_set)

	def _flatten_reqs(self, *req_sets):
		# req_sets further in the list take precedence
		reqs = {}
		for rset in req_sets:
			for sreq in rset:
				req = Requirement.parse(sreq)
				reqs[req.key] = req
		return reqs.values()

	@contextmanager
	def requirement_loader(self, *req_sets):
		# Save sys.path and sys.modules, to be restored later
		import sys, copy
		old_path = copy.copy(sys.path)
		old_sys_modules = sys.modules.keys()
		# Find distributions for all the requirements
		req_dists = []
		reqs = self._flatten_reqs(req_sets)
		for req in reqs:
			match = self._match_req(req)
			if match is None:
				raise RuntimeError("Unable to find distribution matching %s" % str(req))
			req_dists.append(match)
		# Activate the distributions, return control
		for req in req_dists: req.activate()
		yield
		# Restore sys path and modules
		sys.path = old_path
		for modname in sys.modules.keys():
			if not modname in old_sys_modules:
				del sys.modules[modname]

	def install_dist(self, path):
		setup_py = os.path.join(os.getcwd(), path, "setup.py")
		if not os.path.isfile(setup_py):
			raise RuntimeError("Folder %s doesn't have a setup file" % path)
		with self._build_egg_env(path) as tempdir:
			import subprocess, zipfile
			subprocess.check_call(["python", setup_py, "bdist_egg", "--dist-dir=%s" % tempdir])
			egg = os.listdir(tempdir)[0]    # egg will be the single entry in the temp folder
			# TODO: check if exactly that same egg is installed
			eggf = os.path.join(self.mod_folder, egg)   # target egg folder
			os.mkdir(eggf)
			eggz = zipfile.ZipFile(os.path.join(tempdir, egg))
			eggz.extractall(eggf)

	@contextmanager
	def _build_egg_env(self, path):
		import tempfile, shutil
		old_cwd = os.getcwd()
		os.chdir(path)
		tempdir = tempfile.mkdtemp()
		yield tempdir
		shutil.rmtree(tempdir)
		os.chdir(old_cwd)
开发者ID:tuxpiper,项目名称:raduga,代码行数:77,代码来源:distmgr.py

示例6: Environment

    FileMetadata,
    PathMetadata,
    ResourceManager,
    Requirement,
    AvailableDistributions,
    DistInfoDistribution,
    Distribution,
)
from xmlrpc.client import ServerProxy
import requests
import tablib.core
from Other import OrderedSet
from operator import itemgetter
from tablib import Dataset

Distributions = Environment(search_path=sys.path)
Distributions.scan(search_path=sys.path)
# print(len(Distributions._distmap))
import pkg_resources

Cache = OrderedSet()
AD = AvailableDistributions()
print(len(AD._distmap))


refiners = "AND,OR,ANDNOT,ANDMAYBE,NOT".split(",")


def boost(term, value):
    return "{}^{}".format(term, value)
开发者ID:KGerring,项目名称:RevealMe,代码行数:30,代码来源:pypi_all.py


注:本文中的pkg_resources.Environment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。