def _get_spec(source_egg_path, build_number, platform_string=None, python=_UNSPECIFIED, abi_tag=_UNSPECIFIED, metadata_version=None): data, metadata = _get_spec_data( source_egg_path, build_number, platform_string, python, abi_tag, ) if platform_string is None: try: epd_platform = EPDPlatform.from_running_system() except OkonomiyakiError as e: msg = "Could not guess platform from system (original " \ "error was {0!r}). " \ "You may have to specify the platform explicitly." raise EnstallerException(msg.format(e)) else: epd_platform = EPDPlatform.from_epd_string(platform_string) raw_name = data["name"] version = EnpkgVersion.from_upstream_and_build(data["version"], data["build"]) if version.upstream.is_worked_around: raise InvalidVersion(str(version.upstream)) dependencies = Dependencies(runtime=data["packages"]) pkg_info = PackageInfo.from_egg(source_egg_path) return EggMetadata(raw_name, version, epd_platform, metadata.python_tag, metadata.abi_tag, dependencies, pkg_info, metadata.summary, metadata_version=metadata_version)
def test_from_prefix_and_platform(self): # Given prefix = u"/usr/local" platform = EPDPlatform.from_epd_string("rh5-64").platform version = RuntimeVersion.from_string("3.4.3+final.0") # When runtime = PythonRuntime.from_prefix_and_platform( prefix, platform, version ) runtime_info = runtime._runtime_info # Then self.assertEqual(runtime.executable, prefix + "/bin/python3") self.assertEqual(runtime.prefix, prefix) self.assertEqual(runtime.scriptsdir, prefix + "/bin") self.assertEqual( runtime.site_packages, prefix + "/lib/python3.4/site-packages") self.assertEqual(str(runtime_info.version), "3.4.3+final.0") self.assertEqual(str(runtime_info.language_version), "3.4.3") # Given prefix = u"/usr/local" platform = EPDPlatform.from_epd_string("osx-64").platform version = RuntimeVersion.from_string("2.7.9+final.0") # When runtime = PythonRuntime.from_prefix_and_platform( prefix, platform, version ) # Then self.assertEqual(runtime.prefix, prefix) self.assertEqual(runtime.scriptsdir, prefix + "/bin") self.assertEqual( runtime.site_packages, prefix + "/lib/python2.7/site-packages") # Given prefix = u"C:\\Python34" platform = EPDPlatform.from_epd_string("win-64").platform version = RuntimeVersion.from_string("3.4.3+final.0") # When runtime = PythonRuntime.from_prefix_and_platform( prefix, platform, version ) # Then self.assertEqual(runtime.prefix, prefix) self.assertEqual(runtime.scriptsdir, prefix + "\\Scripts") self.assertEqual( runtime.site_packages, prefix + "\\Lib\\site-packages")
def main(argv=None): argv = argv or sys.argv[1:] p = argparse.ArgumentParser() p.add_argument("-f", "--force", action="store_true") p.add_argument("--platform") p.add_argument("egg") ns = p.parse_args(argv) if ns.platform is None: platform = None else: platform = EPDPlatform.from_epd_string(ns.platform) path = dummy_egg_from_egg(ns.egg, force=ns.force, platform=platform)
def test_normalization(self): # Given prefix = u"/usr/local/bin/.." norm_prefix = u"/usr/local" platform = EPDPlatform.from_epd_string("osx-64").platform version = RuntimeVersion.from_string("2.7.9+final.0") # When runtime_info = PythonRuntime.from_prefix_and_platform( prefix, platform, version ) # Then self.assertEqual(runtime_info.prefix, norm_prefix) self.assertEqual(runtime_info.scriptsdir, norm_prefix + "/bin") self.assertEqual( runtime_info.site_packages, norm_prefix + "/lib/python2.7/site-packages")
def test_repack_default_platform(self): # Given source = os.path.join(self.prefix, "nose-1.2.1-py2.7.egg") shutil.copy(STANDARD_EGG, source) target = os.path.join(self.prefix, "nose-1.2.1-1.egg") # When mocked = "enstaller.tools.repack.EPDPlatform.from_running_system" platform = EPDPlatform.from_epd_string("rh5-32") with mock.patch(mocked, return_value=platform): repack(source, 1) # Then self.assertTrue(os.path.exists(target)) with ZipFile(target) as zp: spec = info_from_z(zp) self.assertEqual(spec["arch"], "x86")
def _runtime_info_factory(self, prefix): def _change_scriptsdir(runtime_info): # XXX: hack to force proper path separations, even on Unix. kw = dict( (k.name, getattr(runtime_info, k.name)) for k in runtime_info.__attrs_attrs__ ) # Hack so that scriptsdir is a valid UNIX path (instead of # '/some/prefix\Scripts') kw["scriptsdir"] = os.path.join(prefix, u"Scripts") return type(runtime_info)(**kw) if sys.platform == "win32": epd_string = "win-32" else: epd_string = "rh5-32" platform = EPDPlatform.from_epd_string(epd_string).platform runtime = PythonRuntime.from_prefix_and_platform(prefix, platform) runtime_info = _change_scriptsdir(runtime._runtime_info) return PythonRuntime(runtime_info, u"")
def _get_spec_data(source_egg_path, build_number, platform_string=None, python=_UNSPECIFIED, abi_tag=_UNSPECIFIED): if _looks_like_setuptools_egg(source_egg_path): parsed_platform_string = parse_filename(source_egg_path)[3] if parsed_platform_string is not None and platform_string is None: msg = ("Platform-specific egg detected (platform string is " "{0!r}), you *must* specify the platform.") raise EnstallerException(msg.format(parsed_platform_string)) if platform_string is not None: platform = EPDPlatform.from_epd_string(platform_string) else: platform = None metadata = SetuptoolsEggMetadata.from_egg( source_egg_path, platform, python, abi_tag ) egg_basename = metadata.name version = str(metadata.version) dependencies = [] elif _looks_like_enthought_egg(source_egg_path): metadata = EggMetadata.from_egg(source_egg_path) # The name as used in spec/depend and endist.dat is the so-called # egg basename (i.e. not normalied to lower case) egg_basename = metadata.egg_basename version = metadata.upstream_version dependencies = metadata.runtime_dependencies else: msg = "Unrecognized format: {0!r}".format(source_egg_path) raise EnstallerException(msg) data = {"build": build_number, "packages": dependencies, "name": egg_basename, "version": version} if os.path.exists(ENDIST_DAT): data.update(_parse_endist_for_spec_depend(ENDIST_DAT)) return data, metadata
def _default_runtime_info(prefix=sys.prefix): import enstaller.plat epd_platform = EPDPlatform.from_epd_string(enstaller.plat.custom_plat) platform = epd_platform.platform return PythonRuntime.from_prefix_and_platform(prefix, platform)
def test_brood_cases(self): # set of (python_tag, platform string) pairs that have at least one # index in our current instance of packages.e.com. This was computed # from a dump of our prod database w/ the following SQL: # # SELECT DISTINCT(python_tags.name, platforms.name, platforms.arch) # FROM egg_indices, python_tags, platforms # WHERE # egg_indices.python_tag_id = python_tags.id # and egg_indices.platform_id = platforms.id # # and # # SELECT DISTINCT(python_tags.name, platforms.name, platforms.arch) # FROM eggs, python_tags, platforms # WHERE # eggs.python_tag_id = python_tags.id # and eggs.platform_id = platforms.id # tag_platform = { ('cp27', 'osx_x86'): 'darwin', ('cp27', 'osx_x86_64'): 'darwin', ('cp27', 'rh5_x86'): 'gnu', ('cp27', 'rh5_x86_64'): 'gnu', ('cp27', 'win_x86'): 'msvc2008', ('cp27', 'win_x86_64'): 'msvc2008', ('cp30', 'osx_x86'): 'darwin', ('cp30', 'osx_x86_64'): 'darwin', ('cp30', 'rh5_x86'): 'gnu', ('cp30', 'rh5_x86_64'): 'gnu', ('cp30', 'win_x86'): 'msvc2008', ('cp30', 'win_x86_64'): 'msvc2008', ('cp31', 'osx_x86'): 'darwin', ('cp31', 'osx_x86_64'): 'darwin', ('cp31', 'rh5_x86'): 'gnu', ('cp31', 'rh5_x86_64'): 'gnu', ('cp31', 'win_x86'): 'msvc2008', ('cp31', 'win_x86_64'): 'msvc2008', ('cp32', 'osx_x86'): 'darwin', ('cp32', 'osx_x86_64'): 'darwin', ('cp32', 'rh5_x86'): 'gnu', ('cp32', 'rh5_x86_64'): 'gnu', ('cp32', 'win_x86'): 'msvc2008', ('cp32', 'win_x86_64'): 'msvc2008', ('cp33', 'osx_x86'): 'darwin', ('cp33', 'osx_x86_64'): 'darwin', ('cp33', 'rh5_x86'): 'gnu', ('cp33', 'rh5_x86_64'): 'gnu', ('cp33', 'win_x86'): 'msvc2010', ('cp33', 'win_x86_64'): 'msvc2010', ('cp34', 'osx_x86'): 'darwin', ('cp34', 'osx_x86_64'): 'darwin', ('cp34', 'rh5_x86'): 'gnu', ('cp34', 'rh5_x86_64'): 'gnu', ('cp34', 'win_x86'): 'msvc2010', ('cp34', 'win_x86_64'): 'msvc2010', ('ip27', 'osx_x86'): 'darwin', ('ip27', 'osx_x86_64'): 'darwin', ('ip27', 'rh5_x86'): 'gnu', ('ip27', 'rh5_x86_64'): 'gnu', ('ip27', 'win_x86'): 'msvc2008', ('ip27', 'win_x86_64'): 'msvc2008', ('jy27', 'osx_x86'): 'darwin', ('jy27', 'osx_x86_64'): 'darwin', ('jy27', 'rh5_x86'): 'gnu', ('jy27', 'rh5_x86_64'): 'gnu', ('jy27', 'win_x86'): 'msvc2008', ('jy27', 'win_x86_64'): 'msvc2008', ('pp27', 'osx_x86'): 'darwin', ('pp27', 'osx_x86_64'): 'darwin', ('pp27', 'rh5_x86'): 'gnu', ('pp27', 'rh5_x86_64'): 'gnu', ('pp27', 'win_x86'): 'msvc2008', ('pp27', 'win_x86_64'): 'msvc2008', } for (python_tag, epd_string), platform_abi in tag_platform.items(): epd_platform = EPDPlatform.from_string(epd_string) self.assertEqual( _guess_platform_abi(epd_platform, python_tag), platform_abi )