本文整理汇总了Python中enstaller.repository.Repository._from_prefixes方法的典型用法代码示例。如果您正苦于以下问题:Python Repository._from_prefixes方法的具体用法?Python Repository._from_prefixes怎么用?Python Repository._from_prefixes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enstaller.repository.Repository
的用法示例。
在下文中一共展示了Repository._from_prefixes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def __init__(self, remote_repository, session,
prefixes=[sys.prefix], progress_context=None,
force=False, max_retries=_DEFAULT_MAX_RETRIES,
runtime_info=None):
self.prefixes = prefixes
self.top_prefix = prefixes[0]
self._runtime_info = (
runtime_info or _default_runtime_info(self.top_prefix)
)
self._remote_repository = remote_repository
self._installed_repository = Repository._from_prefixes(self.prefixes)
self._top_installed_repository = \
Repository._from_prefixes([self.top_prefix])
self._session = session
self._downloader = _DownloadManager(session, remote_repository)
self._progress_context = progress_context or \
ProgressBarContext(dummy_progress_bar_factory)
self._force = force
self.max_retries = max_retries
示例2: test_from_empty_prefix
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_from_empty_prefix(self):
# Given
with mkdtemp() as tempdir:
# When
repository = Repository._from_prefixes([tempdir])
# Then
self.assertEqual(len(list(repository.iter_packages())), 0)
示例3: get_freeze_list
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def get_freeze_list(prefixes):
"""
Compute the list of eggs installed in the given prefixes.
Returns
-------
names: seq
List of installed eggs, as full names (e.g. 'numpy-1.8.0-1')
"""
full_names = [
"{0} {1}".format(package.name, package.full_version)
for package in Repository._from_prefixes(prefixes).iter_packages()
]
return sorted(full_names)
示例4: test_print_installed
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_print_installed(self):
with mkdtemp() as d:
r_out = textwrap.dedent("""\
Name Version Store
============================================================
dummy 1.0.1-1 {0}
""".format(disp_store_info(d)))
ec = EggInst(DUMMY_EGG, d)
ec.install()
repository = Repository._from_prefixes([d])
with mock_print() as m:
print_installed(repository)
self.assertMultiLineEqual(m.value, r_out)
r_out = textwrap.dedent("""\
Name Version Store
============================================================
""")
repository = Repository._from_prefixes([d])
with mock_print() as m:
print_installed(repository, pat=re.compile("no_dummy"))
self.assertEqual(m.value, r_out)
示例5: test_from_prefix
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_from_prefix(self):
# Given
path = DUMMY_EGG
with mkdtemp() as tempdir:
create_venv(tempdir)
installer = EggInst(path, prefix=tempdir)
installer.install()
# When
repository = Repository._from_prefixes([tempdir])
# Then
packages = repository.find_packages("dummy")
self.assertEqual(len(packages), 1)
self.assertEqual(packages[0].name, "dummy")
示例6: test_remove_non_existing
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_remove_non_existing(self):
# Given
entries = [
dummy_repository_package_factory("numpy", "1.6.1", 1),
dummy_repository_package_factory("numpy", "1.8.0", 2),
]
repository = repository_factory(entries)
solver = Solver(repository, Repository._from_prefixes([self.prefix]))
request = Request()
request.remove(Requirement("numpy"))
# When/Then
with self.assertRaises(EnpkgError):
solver.resolve(request)
示例7: test_install_missing_dependency
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_install_missing_dependency(self):
# Given
entries = [
dummy_repository_package_factory("numpy", "1.8.0", 2,
dependencies=["MKL 10.3"]),
]
repository = repository_factory(entries)
installed_repository = Repository._from_prefixes([self.prefix])
solver = Solver(repository, installed_repository)
request = Request()
request.install(Requirement("numpy"))
# When/Then
with self.assertRaises(MissingDependency):
solver.resolve(request)
示例8: test_install_no_egg_entry
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_install_no_egg_entry(self):
# Given
entries = [
dummy_repository_package_factory("numpy", "1.6.1", 1),
dummy_repository_package_factory("numpy", "1.8.0", 2),
]
repository = repository_factory(entries)
installed_repository = Repository._from_prefixes([self.prefix])
solver = Solver(repository, installed_repository)
request = Request()
request.install(Requirement("scipy"))
# When/Then
with self.assertRaises(NoPackageFound):
solver.resolve(request)
示例9: test_remove_actions
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_remove_actions(self):
# Given
repository = Repository()
for egg in [DUMMY_EGG]:
egginst = EggInst(egg, self.prefix)
egginst.install()
solver = Solver(repository, Repository._from_prefixes([self.prefix]))
request = Request()
request.remove(Requirement("dummy"))
# When
actions = solver.resolve(request)
# Then
self.assertEqual(actions, [("remove", os.path.basename(DUMMY_EGG))])
示例10: test_install_simple
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_install_simple(self):
numpy_1_8_0 = dummy_repository_package_factory("numpy", "1.8.0", 2)
entries = [
dummy_repository_package_factory("numpy", "1.6.1", 1),
numpy_1_8_0,
dummy_repository_package_factory("numpy", "1.7.1", 2),
]
r_actions = [('install', numpy_1_8_0)]
repository = repository_factory(entries)
installed_repository = Repository._from_prefixes([self.prefix])
solver = Solver(repository, installed_repository)
request = Request()
request.install(Requirement("numpy"))
actions = solver.resolve(request)
self.assertEqual(actions, r_actions)
示例11: test_chained_override_update
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_chained_override_update(self):
""" Test update to package with latest version in lower prefix
but an older version in primary prefix.
"""
# Given
l0_egg = NOSE_1_3_0
l1_egg = NOSE_1_2_1
nose = dummy_repository_package_factory(
*split_eggname(os.path.basename(l0_egg))
)
repository = repository_factory([nose])
l0 = os.path.join(self.prefix, 'l0')
l1 = os.path.join(self.prefix, 'l1')
makedirs(l0)
makedirs(l1)
l1_egg_meta_dir = os.path.join(l1, EGG_INFO, "nose")
# Install latest version in l0
EggInst(l0_egg, l0).install()
# Install older version in l1
EggInst(l1_egg, l1).install()
installed_nose = InstalledPackageMetadata.from_meta_dir(
l1_egg_meta_dir, prefix=l1
)
expected_actions = [('remove', installed_nose), ('install', nose)]
installed_repository = Repository._from_prefixes([l1])
solver = Solver(repository, installed_repository)
request = Request()
request.install(Requirement("nose"))
# When
actions = solver.resolve(request)
# Then
self.assertListEqual(actions, expected_actions)
示例12: test_simple
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_simple(self):
# Given
filename = "nose-1.3.0-1.egg"
path = os.path.join(_EGGINST_COMMON_DATA, filename)
metadata = PackageMetadata.from_egg(path)
self._install_eggs([path])
# When
action = RemoveAction(path, self.top_prefix,
self.top_installed_repository,
self.installed_repository)
action.execute()
# Then
repository = Repository._from_prefixes([self.top_prefix])
self.assertFalse(repository.has_package(metadata))
self.assertFalse(self.top_installed_repository.has_package(metadata))
self.assertFalse(self.installed_repository.has_package(metadata))
self.assertFalse(action.is_canceled)
示例13: test_remove_actions
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_remove_actions(self):
# Given
repository = Repository()
for egg in [DUMMY_EGG]:
egginst = EggInst(egg, self.prefix)
egginst.install()
installed_repository = Repository._from_prefixes([self.prefix])
solver = Solver(repository, installed_repository)
request = Request()
request.remove(Requirement("dummy"))
# When
actions = solver.resolve(request)
# Then
self.assertEqual(
actions,
[("remove", installed_repository.find_packages("dummy")[0])]
)
示例14: dispatch_commands_with_enpkg
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def dispatch_commands_with_enpkg(args, enpkg, config, prefix, session, parser,
pat):
if args.dry_run:
def print_actions(actions):
for item in actions:
print('%-8s %s' % item)
enpkg.execute = print_actions
if args.imports: # --imports
repository = Repository._from_prefixes(enpkg.prefixes)
imports_option(repository)
return
if args.revert: # --revert
revert(enpkg, args.revert)
return
# Try to auto-update enstaller
if config.autoupdate:
if update_enstaller(session, enpkg._remote_repository, args):
print("Enstaller has been updated.\n"
"Please re-run your previous command.")
return
if args.search: # --search
search(enpkg._remote_repository, enpkg._installed_repository,
config, session, pat)
return
if args.info: # --info
if len(args.cnames) != 1:
parser.error("Option requires one argument (name of package)")
info_option(enpkg._remote_repository, enpkg._installed_repository,
args.cnames[0])
return
if args.whats_new: # --whats-new
whats_new(enpkg._remote_repository, enpkg._installed_repository)
return
if args.update_all: # --update-all
update_all(enpkg, config, args)
return
if args.requirements:
install_from_requirements(enpkg, config, args)
return
if len(args.cnames) == 0 and not args.remove_enstaller:
parser.error("Requirement(s) missing")
elif len(args.cnames) == 2:
pat = re.compile(r'\d+\.\d+')
if pat.match(args.cnames[1]):
args.cnames = ['-'.join(args.cnames)]
reqs = _compute_reqs(args.cnames)
# This code assumes we have already upgraded enstaller if needed
if needs_to_downgrade_enstaller(reqs):
msg = "Enstaller in requirement list: enstaller will be downgraded !"
warnings.warn(msg)
else:
logger.debug("Enstaller is up to date, not updating")
reqs = [req for req in reqs if req.name != "enstaller"]
logger.info("Requirements:")
for req in reqs:
logger.info(' %r', req)
logger.info("prefix: %r", prefix)
REMOVE_ENSTALLER_WARNING = ("Removing enstaller package will break enpkg "
"and is not recommended.")
if args.remove:
if any(req.name == 'enstaller' for req in reqs):
print(REMOVE_ENSTALLER_WARNING)
print("If you are sure you wish to remove enstaller, use:")
print(" enpkg --remove-enstaller")
return
if args.remove_enstaller:
print(REMOVE_ENSTALLER_WARNING)
if prompt_yes_no("Really remove enstaller? (y/[n]) ", args.yes):
args.remove = True
reqs = [Requirement('enstaller')]
if any(req.name == 'epd' for req in reqs):
if args.remove:
parser.error("Can't remove 'epd'")
elif len(reqs) > 1:
parser.error("Can't combine 'enpkg epd' with other packages.")
elif not epd_install_confirm(args.yes):
return
if args.remove:
for req in reqs:
solver = enpkg._solver_factory()
try:
request = Request()
request.remove(req)
#.........这里部分代码省略.........
示例15: test_from_prefix_normalization
# 需要导入模块: from enstaller.repository import Repository [as 别名]
# 或者: from enstaller.repository.Repository import _from_prefixes [as 别名]
def test_from_prefix_normalization(self):
# Given
r_installed_metadata = {
"PyYAML-3.11-1.egg": {
"arch": "amd64",
"build": 1,
"key": "PyYAML-3.11-1.egg",
"md5": "4d1df29c87bb101747b5a774b720f543",
"name": "pyyaml",
"osdist": "RedHat_5",
"packages": [
"libYAML 0.1.4"
],
"platform": "linux2",
"product": "free",
"python": "2.7",
"size": 183069,
"type": "egg",
"version": "3.11"
},
"libYAML-0.1.4-1.egg": {
"arch": "amd64",
"build": 1,
"key": "libYAML-0.1.4-1.egg",
"md5": "3679f8a4f6c852ed65a3b9809bbecd13",
"name": "libyaml",
"osdist": "RedHat_5",
"packages": [],
"platform": "linux2",
"python": None,
"version": "0.1.4"
}
}
def info_from_metadir(meta_dir):
if meta_dir == os.path.join("dummy_prefix", "EGG-INFO", "libyaml"):
return r_installed_metadata["libYAML-0.1.4-1.egg"]
elif meta_dir == os.path.join("dummy_prefix", "EGG-INFO", "pyyaml"):
return r_installed_metadata["PyYAML-3.11-1.egg"]
else:
return None
def _valid_meta_dir_iterator(prefixes):
for prefix in prefixes:
egg_info_root = os.path.join(prefix, "EGG-INFO")
for info in six.itervalues(r_installed_metadata):
yield (
prefix, egg_info_root,
os.path.join(egg_info_root, info["name"])
)
# When
with mock.patch(
"enstaller.repository._valid_meta_dir_iterator",
_valid_meta_dir_iterator
):
with mock.patch(
"enstaller.repository.info_from_metadir",
info_from_metadir
):
repository = Repository._from_prefixes(["dummy_prefix"])
# Then
packages = repository.find_packages("pyyaml")
self.assertEqual(len(packages), 1)
self.assertEqual(packages[0].name, "pyyaml")
self.assertEqual(packages[0].dependencies, frozenset(["libyaml 0.1.4",]))