How to use load_version_data method in tox

Best Python code snippet using tox_python

versions.py

Source:versions.py Github

copy

Full Screen

...16 # New Python installer introduced in CPython 3.5.17 # Usage: https://docs.python.org/3/using/windows.html#installing-without-ui18 cpython = 'cpython'19VERSIONS_DIR_PATH = pathlib.Path(__file__).with_name('versions').resolve()20def load_version_data(name):21 try:22 with VERSIONS_DIR_PATH.joinpath('{}.json'.format(name)).open() as f:23 data = json.load(f)24 except FileNotFoundError:25 raise VersionNotFoundError(name)26 return data27@attr.s28class Version:29 name = attr.ib()30 url = attr.ib()31 md5_sum = attr.ib()32 version_info = attr.ib(convert=tuple)33 product_codes = attr.ib(default=attr.Factory(dict))34 forced_32 = attr.ib(default=False)35 def __str__(self):36 return 'Python {}'.format(self.name)37 @property38 def arch_free_name(self):39 return self.name.split('-', 1)[0]40 @property41 def script_version_names(self):42 # Use set to avoid duplicates.43 if self.forced_32:44 return {self.name, self.arch_free_name}45 return {self.name}46 @property47 def python_commands(self):48 dirpath = configs.get_cmd_dir_path()49 return [50 dirpath.joinpath('python{}.exe'.format(name))51 for name in self.script_version_names52 ]53 @property54 def pip_commands(self):55 dirpath = configs.get_cmd_dir_path()56 return [57 dirpath.joinpath('pip{}.exe'.format(name))58 for name in self.script_version_names59 ]60 @property61 def python_major_command(self):62 dirpath = configs.get_scripts_dir_path()63 return dirpath.joinpath('python{}.exe'.format(self.version_info[0]))64 def get_installation(self):65 path = metadata.get_install_path(self.name).resolve(strict=True)66 return installations.Installation(path=path)67 def is_installed(self):68 try:69 exists = metadata.get_install_path(self.name).exists()70 except FileNotFoundError:71 return False72 return exists73 def check_installer(self, data):74 checksum = hashlib.md5(data).hexdigest()75 assert checksum == self.md5_sum, \76 'expect checksum {}, got {}'.format(self.md5_sum, checksum)77 def get_target_for_install(self):78 return pathlib.Path(79 os.environ['LocalAppData'], 'Programs', 'Python',80 'Python{}'.format(self.name.replace('.', '')),81 )82class CPythonMSIVersion(Version):83 @classmethod84 def load(cls, name, data, *, force_32):85 variant = data['x86' if force_32 else 'amd64']86 return cls(87 name=name,88 version_info=data['version_info'],89 url=variant['url'],90 md5_sum=variant['md5_sum'],91 product_codes=variant.get('product_codes', {}),92 )93 def _run_installer(self, cmd, target_dirpath):94 features = ['DefaultFeature', 'PrivateCRT', 'TclTk', 'pip_feature']95 parts = [ # Argument ordering is very important.96 # Options and required parameters.97 'msiexec', '/i', '"{}"'.format(cmd),98 # Optional parameters and flags.99 '/qb', 'TARGETDIR="{}"'.format(target_dirpath),100 'ADDLOCAL={}'.format(','.join(features)),101 # This does not do what you think. DO NOT SUPPLY IT.102 # The installer is per-user by default.103 # 'ALLUSERS=0',104 ]105 subprocess.check_call(106 ' '.join(parts),107 shell=True, # So we don't need to know where msiexec is.108 )109 def install(self, cmd):110 dirpath = self.get_target_for_install()111 self._run_installer(cmd, dirpath)112 return dirpath113 def upgrade(self, cmd):114 # There is no way to know what was installed from the previous MSI115 # installer; all we can do is installing what we want to the location116 # we want, and leave the old version installation untouched.117 self._run_installer(cmd, self.get_installation().path)118 def get_cached_uninstaller(self):119 info = self.get_installation().get_version_info()120 try:121 return self.product_codes['{0[0]}.{0[1]}.{0[2]}'.format(info)]122 except (IndexError, KeyError, TypeError):123 return metadata.find_uninstaller_id(self.name)124 def uninstall(self, cmd):125 subprocess.check_call('msiexec /x "{}" /qb'.format(cmd), shell=True)126class CPythonVersion(Version):127 @classmethod128 def load(cls, name, data, *, force_32):129 forced_32 = False130 if force_32 and not name.endswith('-32'):131 name = '{}-32'.format(name)132 data = load_version_data(name)133 forced_32 = True134 return cls(135 name=name,136 version_info=data['version_info'],137 url=data['url'],138 md5_sum=data['md5_sum'],139 forced_32=forced_32,140 )141 def install(self, cmd):142 dirpath = self.get_target_for_install()143 subprocess.check_call([144 cmd, '/passive', 'InstallAllUsers=0',145 'DefaultJustForMeTargetDir={}'.format(dirpath),146 'AssociateFiles=0', 'PrependPath=0', 'Shortcuts=0',147 'Include_doc=0', 'Include_launcher=0', 'Include_test=0',148 'Include_tools=0', 'InstallLauncherAllUsers=0',149 ])150 return dirpath151 def upgrade(self, cmd):152 # The installer handles all feature detection for us.153 subprocess.check_call([cmd, '/passive'])154 def get_cached_uninstaller(self):155 return metadata.get_bundle_cache_path(self.name)156 def uninstall(self, cmd):157 subprocess.check_call([cmd, '/uninstall', '/passive'])158def get_version(name, *, force_32):159 data = load_version_data(name)160 installer_type = InstallerType(data['type'])161 klass = {162 InstallerType.cpython_msi: CPythonMSIVersion,163 InstallerType.cpython: CPythonVersion,164 }[installer_type]165 return klass.load(name, data, force_32=force_32)166VERSION_NAME_RE = re.compile(r'^\d+\.\d+(:?\-32)?$')167def get_versions():168 return [169 get_version(p.stem, force_32=False)170 for p in VERSIONS_DIR_PATH.iterdir()171 if p.suffix == '.json' and VERSION_NAME_RE.match(p.stem)...

Full Screen

Full Screen

pep514.py

Source:pep514.py Github

copy

Full Screen

...48 if spec is not None:49 yield spec50def process_tag(hive_name, company, company_key, tag, default_arch):51 with winreg.OpenKeyEx(company_key, tag) as tag_key:52 version = load_version_data(hive_name, company, tag, tag_key)53 if version is not None: # if failed to get version bail54 major, minor, _ = version55 arch = load_arch_data(hive_name, company, tag, tag_key, default_arch)56 if arch is not None:57 exe_data = load_exe(hive_name, company, company_key, tag)58 if exe_data is not None:59 exe, args = exe_data60 return company, major, minor, arch, exe, args61def load_exe(hive_name, company, company_key, tag):62 key_path = "{}/{}/{}".format(hive_name, company, tag)63 try:64 with winreg.OpenKeyEx(company_key, r"{}\InstallPath".format(tag)) as ip_key:65 with ip_key:66 exe = get_value(ip_key, "ExecutablePath")67 if exe is None:68 ip = get_value(ip_key, None)69 if ip is None:70 msg(key_path, "no ExecutablePath or default for it")71 else:72 exe = os.path.join(ip, str("python.exe"))73 if exe is not None and os.path.exists(exe):74 args = get_value(ip_key, "ExecutableArguments")75 return exe, args76 else:77 msg(key_path, "could not load exe with value {}".format(exe))78 except OSError:79 msg("{}/{}".format(key_path, "InstallPath"), "missing")80 return None81def load_arch_data(hive_name, company, tag, tag_key, default_arch):82 arch_str = get_value(tag_key, "SysArchitecture")83 if arch_str is not None:84 key_path = "{}/{}/{}/SysArchitecture".format(hive_name, company, tag)85 try:86 return parse_arch(arch_str)87 except ValueError as sys_arch:88 msg(key_path, sys_arch)89 return default_arch90def parse_arch(arch_str):91 if isinstance(arch_str, six.string_types):92 match = re.match(r"^(\d+)bit$", arch_str)93 if match:94 return int(next(iter(match.groups())))95 error = "invalid format {}".format(arch_str)96 else:97 error = "arch is not string: {}".format(repr(arch_str))98 raise ValueError(error)99def load_version_data(hive_name, company, tag, tag_key):100 for candidate, key_path in [101 (get_value(tag_key, "SysVersion"), "{}/{}/{}/SysVersion".format(hive_name, company, tag)),102 (tag, "{}/{}/{}".format(hive_name, company, tag)),103 ]:104 if candidate is not None:105 try:106 return parse_version(candidate)107 except ValueError as sys_version:108 msg(key_path, sys_version)109 return None110def parse_version(version_str):111 if isinstance(version_str, six.string_types):112 match = re.match(r"^(\d+)(?:\.(\d+))?(?:\.(\d+))?$", version_str)113 if match:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful