584 lines
58 KiB
HTML
584 lines
58 KiB
HTML
|
|
|||
|
<!DOCTYPE html>
|
|||
|
<html lang="en">
|
|||
|
<head>
|
|||
|
<meta charset="utf-8">
|
|||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|||
|
<meta name="color-scheme" content="light dark">
|
|||
|
<title>PEP 514 – Python registration in the Windows registry | peps.python.org</title>
|
|||
|
<link rel="shortcut icon" href="../_static/py.png">
|
|||
|
<link rel="canonical" href="https://peps.python.org/pep-0514/">
|
|||
|
<link rel="stylesheet" href="../_static/style.css" type="text/css">
|
|||
|
<link rel="stylesheet" href="../_static/mq.css" type="text/css">
|
|||
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" media="(prefers-color-scheme: light)" id="pyg-light">
|
|||
|
<link rel="stylesheet" href="../_static/pygments_dark.css" type="text/css" media="(prefers-color-scheme: dark)" id="pyg-dark">
|
|||
|
<link rel="alternate" type="application/rss+xml" title="Latest PEPs" href="https://peps.python.org/peps.rss">
|
|||
|
<meta property="og:title" content='PEP 514 – Python registration in the Windows registry | peps.python.org'>
|
|||
|
<meta property="og:description" content="This PEP defines a schema for the Python registry key to allow third-party installers to register their installation, and to allow tools and applications to detect and correctly display all Python environments on a user’s machine. No implementation chan...">
|
|||
|
<meta property="og:type" content="website">
|
|||
|
<meta property="og:url" content="https://peps.python.org/pep-0514/">
|
|||
|
<meta property="og:site_name" content="Python Enhancement Proposals (PEPs)">
|
|||
|
<meta property="og:image" content="https://peps.python.org/_static/og-image.png">
|
|||
|
<meta property="og:image:alt" content="Python PEPs">
|
|||
|
<meta property="og:image:width" content="200">
|
|||
|
<meta property="og:image:height" content="200">
|
|||
|
<meta name="description" content="This PEP defines a schema for the Python registry key to allow third-party installers to register their installation, and to allow tools and applications to detect and correctly display all Python environments on a user’s machine. No implementation chan...">
|
|||
|
<meta name="theme-color" content="#3776ab">
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
|
|||
|
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
|
|||
|
<symbol id="svg-sun-half" viewBox="0 0 24 24" pointer-events="all">
|
|||
|
<title>Following system colour scheme</title>
|
|||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
|
|||
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|||
|
<circle cx="12" cy="12" r="9"></circle>
|
|||
|
<path d="M12 3v18m0-12l4.65-4.65M12 14.3l7.37-7.37M12 19.6l8.85-8.85"></path>
|
|||
|
</svg>
|
|||
|
</symbol>
|
|||
|
<symbol id="svg-moon" viewBox="0 0 24 24" pointer-events="all">
|
|||
|
<title>Selected dark colour scheme</title>
|
|||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
|
|||
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
|||
|
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z"></path>
|
|||
|
</svg>
|
|||
|
</symbol>
|
|||
|
<symbol id="svg-sun" viewBox="0 0 24 24" pointer-events="all">
|
|||
|
<title>Selected light colour scheme</title>
|
|||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
|
|||
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|||
|
<circle cx="12" cy="12" r="5"></circle>
|
|||
|
<line x1="12" y1="1" x2="12" y2="3"></line>
|
|||
|
<line x1="12" y1="21" x2="12" y2="23"></line>
|
|||
|
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
|
|||
|
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
|
|||
|
<line x1="1" y1="12" x2="3" y2="12"></line>
|
|||
|
<line x1="21" y1="12" x2="23" y2="12"></line>
|
|||
|
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
|
|||
|
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
|
|||
|
</svg>
|
|||
|
</symbol>
|
|||
|
</svg>
|
|||
|
<script>
|
|||
|
|
|||
|
document.documentElement.dataset.colour_scheme = localStorage.getItem("colour_scheme") || "auto"
|
|||
|
</script>
|
|||
|
<section id="pep-page-section">
|
|||
|
<header>
|
|||
|
<h1>Python Enhancement Proposals</h1>
|
|||
|
<ul class="breadcrumbs">
|
|||
|
<li><a href="https://www.python.org/" title="The Python Programming Language">Python</a> » </li>
|
|||
|
<li><a href="../pep-0000/">PEP Index</a> » </li>
|
|||
|
<li>PEP 514</li>
|
|||
|
</ul>
|
|||
|
<button id="colour-scheme-cycler" onClick="setColourScheme(nextColourScheme())">
|
|||
|
<svg aria-hidden="true" class="colour-scheme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
|
|||
|
<svg aria-hidden="true" class="colour-scheme-icon-when-dark"><use href="#svg-moon"></use></svg>
|
|||
|
<svg aria-hidden="true" class="colour-scheme-icon-when-light"><use href="#svg-sun"></use></svg>
|
|||
|
<span class="visually-hidden">Toggle light / dark / auto colour theme</span>
|
|||
|
</button>
|
|||
|
</header>
|
|||
|
<article>
|
|||
|
<section id="pep-content">
|
|||
|
<h1 class="page-title">PEP 514 – Python registration in the Windows registry</h1>
|
|||
|
<dl class="rfc2822 field-list simple">
|
|||
|
<dt class="field-odd">Author<span class="colon">:</span></dt>
|
|||
|
<dd class="field-odd">Steve Dower <steve.dower at python.org></dd>
|
|||
|
<dt class="field-even">BDFL-Delegate<span class="colon">:</span></dt>
|
|||
|
<dd class="field-even">Paul Moore <p.f.moore at gmail.com></dd>
|
|||
|
<dt class="field-odd">Status<span class="colon">:</span></dt>
|
|||
|
<dd class="field-odd"><abbr title="Currently valid informational guidance, or an in-use process">Active</abbr></dd>
|
|||
|
<dt class="field-even">Type<span class="colon">:</span></dt>
|
|||
|
<dd class="field-even"><abbr title="Non-normative PEP containing background, guidelines or other information relevant to the Python ecosystem">Informational</abbr></dd>
|
|||
|
<dt class="field-odd">Created<span class="colon">:</span></dt>
|
|||
|
<dd class="field-odd">02-Feb-2016</dd>
|
|||
|
<dt class="field-even">Post-History<span class="colon">:</span></dt>
|
|||
|
<dd class="field-even">02-Feb-2016, 01-Mar-2016, 18-Jul-2016</dd>
|
|||
|
<dt class="field-odd">Resolution<span class="colon">:</span></dt>
|
|||
|
<dd class="field-odd"><a class="reference external" href="https://mail.python.org/pipermail/python-dev/2016-July/145697.html">Python-Dev message</a></dd>
|
|||
|
</dl>
|
|||
|
<hr class="docutils" />
|
|||
|
<section id="contents">
|
|||
|
<details><summary>Table of Contents</summary><ul class="simple">
|
|||
|
<li><a class="reference internal" href="#abstract">Abstract</a></li>
|
|||
|
<li><a class="reference internal" href="#motivation">Motivation</a></li>
|
|||
|
<li><a class="reference internal" href="#definitions">Definitions</a></li>
|
|||
|
<li><a class="reference internal" href="#structure">Structure</a><ul>
|
|||
|
<li><a class="reference internal" href="#backwards-compatibility">Backwards Compatibility</a></li>
|
|||
|
<li><a class="reference internal" href="#company">Company</a></li>
|
|||
|
<li><a class="reference internal" href="#tag">Tag</a></li>
|
|||
|
<li><a class="reference internal" href="#installpath">InstallPath</a></li>
|
|||
|
<li><a class="reference internal" href="#help">Help</a></li>
|
|||
|
<li><a class="reference internal" href="#other-keys">Other Keys</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#sample-code">Sample Code</a></li>
|
|||
|
<li><a class="reference internal" href="#references">References</a></li>
|
|||
|
<li><a class="reference internal" href="#copyright">Copyright</a></li>
|
|||
|
</ul>
|
|||
|
</details></section>
|
|||
|
<section id="abstract">
|
|||
|
<h2><a class="toc-backref" href="#abstract" role="doc-backlink">Abstract</a></h2>
|
|||
|
<p>This PEP defines a schema for the Python registry key to allow third-party
|
|||
|
installers to register their installation, and to allow tools and applications
|
|||
|
to detect and correctly display all Python environments on a user’s machine. No
|
|||
|
implementation changes to Python are proposed with this PEP.</p>
|
|||
|
<p>Python environments are not required to be registered unless they want to be
|
|||
|
automatically discoverable by external tools. As this relates to Windows only,
|
|||
|
these tools are expected to be predominantly GUI applications. However, console
|
|||
|
applications may also make use of the registered information. This PEP covers
|
|||
|
the information that may be made available, but the actual presentation and use
|
|||
|
of this information is left to the tool designers.</p>
|
|||
|
<p>The schema matches the registry values that have been used by the official
|
|||
|
installer since at least Python 2.5, and the resolution behaviour matches the
|
|||
|
behaviour of the official Python releases. Some backwards compatibility rules
|
|||
|
are provided to ensure tools can correctly detect versions of CPython that do
|
|||
|
not register full information.</p>
|
|||
|
</section>
|
|||
|
<section id="motivation">
|
|||
|
<h2><a class="toc-backref" href="#motivation" role="doc-backlink">Motivation</a></h2>
|
|||
|
<p>When installed on Windows, the official Python installer creates a registry key
|
|||
|
for discovery and detection by other applications. This allows tools such as
|
|||
|
installers or IDEs to automatically detect and display a user’s Python
|
|||
|
installations. For example, the <a class="pep reference internal" href="../pep-0397/" title="PEP 397 – Python launcher for Windows">PEP 397</a> <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher and editors such as
|
|||
|
PyCharm and Visual Studio already make use of this information.</p>
|
|||
|
<p>Third-party installers, such as those used by distributions, typically create
|
|||
|
identical keys for the same purpose. Most tools that use the registry to detect
|
|||
|
Python installations only inspect the keys used by the official installer. As a
|
|||
|
result, third-party installations that wish to be discoverable will overwrite
|
|||
|
these values, often causing users to “lose” their original Python installation.</p>
|
|||
|
<p>By describing a layout for registry keys that allows third-party installations
|
|||
|
to register themselves uniquely, as well as providing tool developers guidance
|
|||
|
for discovering all available Python installations, these collisions should be
|
|||
|
prevented. We also take the opportunity to add some well-known metadata so that
|
|||
|
more information can be presented to users.</p>
|
|||
|
</section>
|
|||
|
<section id="definitions">
|
|||
|
<h2><a class="toc-backref" href="#definitions" role="doc-backlink">Definitions</a></h2>
|
|||
|
<p>A “registry key” is the equivalent of a file-system path into the registry. Each
|
|||
|
key may contain “subkeys” (keys nested within keys) and “values” (named and
|
|||
|
typed attributes attached to a key). These are used on Windows to store settings
|
|||
|
in much the same way that directories containing configuration files would work.</p>
|
|||
|
<p><code class="docutils literal notranslate"><span class="pre">HKEY_CURRENT_USER</span></code> is the root of settings for the currently logged-in user,
|
|||
|
and this user can generally read and write all settings under this root.</p>
|
|||
|
<p><code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE</span></code> is the root of settings for all users. Generally, any
|
|||
|
user can read these settings but only administrators can modify them. It is
|
|||
|
typical for values under <code class="docutils literal notranslate"><span class="pre">HKEY_CURRENT_USER</span></code> to take precedence over those in
|
|||
|
<code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE</span></code>.</p>
|
|||
|
<p>On 64-bit Windows, <code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE\Software\Wow6432Node</span></code> is a special key
|
|||
|
that 32-bit processes transparently read and write to rather than accessing the
|
|||
|
<code class="docutils literal notranslate"><span class="pre">Software</span></code> key directly.</p>
|
|||
|
<p>Further documentation regarding registry redirection on Windows is available
|
|||
|
from the MSDN Library <a class="footnote-reference brackets" href="#id2" id="id1">[1]</a>.</p>
|
|||
|
</section>
|
|||
|
<section id="structure">
|
|||
|
<h2><a class="toc-backref" href="#structure" role="doc-backlink">Structure</a></h2>
|
|||
|
<p>We consider there to be a single collection of Python environments on a machine,
|
|||
|
where the collection may be different for each user of the machine. There are
|
|||
|
three potential registry locations where the collection may be stored based on
|
|||
|
the installation options of each environment:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="o"><</span><span class="n">Company</span><span class="o">></span>\<span class="o"><</span><span class="n">Tag</span><span class="o">></span>
|
|||
|
<span class="n">HKEY_LOCAL_MACHINE</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="o"><</span><span class="n">Company</span><span class="o">></span>\<span class="o"><</span><span class="n">Tag</span><span class="o">></span>
|
|||
|
<span class="n">HKEY_LOCAL_MACHINE</span>\<span class="n">Software</span>\<span class="n">Wow6432Node</span>\<span class="n">Python</span>\<span class="o"><</span><span class="n">Company</span><span class="o">></span>\<span class="o"><</span><span class="n">Tag</span><span class="o">></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Official Python releases use <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> for Company, and the value of
|
|||
|
<code class="docutils literal notranslate"><span class="pre">sys.winver</span></code> for Tag. The Company <code class="docutils literal notranslate"><span class="pre">PyLauncher</span></code> is reserved. Other registered
|
|||
|
environments may use any values for Company and Tag. Recommendations are made
|
|||
|
later in this document.</p>
|
|||
|
<p>Company-Tag pairs are case-insensitive, and uniquely identify each environment.
|
|||
|
Depending on the purpose and intended use of a tool, there are two suggested
|
|||
|
approaches for resolving conflicts between Company-Tag pairs.</p>
|
|||
|
<p>Tools that list every installed environment may choose to include those
|
|||
|
even where the Company-Tag pairs match. They should ensure users can easily
|
|||
|
identify whether the registration was per-user or per-machine, and which
|
|||
|
registration has the higher priority.</p>
|
|||
|
<p>Tools that aim to select a single installed environment from all registered
|
|||
|
environments based on the Company-Tag pair, such as the <code class="docutils literal notranslate"><span class="pre">py.exe</span></code> launcher,
|
|||
|
should always select the environment registered in <code class="docutils literal notranslate"><span class="pre">HKEY_CURRENT_USER</span></code> when
|
|||
|
than the matching one in <code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE</span></code>.</p>
|
|||
|
<p>Conflicts between <code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE\Software\Python</span></code> and
|
|||
|
<code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python</span></code> should only occur when both
|
|||
|
64-bit and 32-bit versions of an interpreter have the same Tag. In this case,
|
|||
|
the tool should select whichever is more appropriate for its use.</p>
|
|||
|
<p>If a tool is able to determine from the provided information (or lack thereof)
|
|||
|
that it cannot use a registered environment, there is no obligation to present
|
|||
|
it to users.</p>
|
|||
|
<p>Except as discussed in the section on backwards compatibility, Company and Tag
|
|||
|
values are considered opaque to tools, and no information about the interpreter
|
|||
|
should be inferred from the text. However, some tools may display the Company
|
|||
|
and Tag values to users, so ideally the Tag will be able to help users identify
|
|||
|
the associated environment.</p>
|
|||
|
<p>Python environments are not required to register themselves unless they want to
|
|||
|
be automatically discoverable by external tools.</p>
|
|||
|
<section id="backwards-compatibility">
|
|||
|
<h3><a class="toc-backref" href="#backwards-compatibility" role="doc-backlink">Backwards Compatibility</a></h3>
|
|||
|
<p>Python 3.4 and earlier did not distinguish between 32-bit and 64-bit builds in
|
|||
|
<code class="docutils literal notranslate"><span class="pre">sys.winver</span></code>. As a result, it is not possible to have valid side-by-side
|
|||
|
installations of both 32-bit and 64-bit interpreters under this scheme since it
|
|||
|
would result in duplicate Tags.</p>
|
|||
|
<p>To ensure backwards compatibility, applications should treat environments listed
|
|||
|
under the following two registry keys as distinct, even when the Tag matches:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_LOCAL_MACHINE</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">PythonCore</span>\<span class="o"><</span><span class="n">Tag</span><span class="o">></span>
|
|||
|
<span class="n">HKEY_LOCAL_MACHINE</span>\<span class="n">Software</span>\<span class="n">Wow6432Node</span>\<span class="n">Python</span>\<span class="n">PythonCore</span>\<span class="o"><</span><span class="n">Tag</span><span class="o">></span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Environments listed under <code class="docutils literal notranslate"><span class="pre">HKEY_CURRENT_USER</span></code> may be treated as distinct from
|
|||
|
both of the above keys, potentially resulting in three environments discovered
|
|||
|
using the same Tag. Alternatively, a tool may determine whether the per-user
|
|||
|
environment is 64-bit or 32-bit and give it priority over the per-machine
|
|||
|
environment, resulting in a maximum of two discovered environments.</p>
|
|||
|
<p>It is not possible to detect side-by-side installations of both 64-bit and
|
|||
|
32-bit versions of Python prior to 3.5 when they have been installed for the
|
|||
|
current user. Python 3.5 and later always uses different Tags for 64-bit and
|
|||
|
32-bit versions.</p>
|
|||
|
<p>The following section describe user-visible information that may be registered.
|
|||
|
For Python 3.5 and earlier, none of this information is available, but
|
|||
|
alternative defaults are specified for the <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> key.</p>
|
|||
|
<p>Environments registered under other Company names have no backward compatibility
|
|||
|
requirements and must use distinct Tags to support side-by-side installations.
|
|||
|
Tools consuming these registrations are not required to disambiguate tags other
|
|||
|
than by preferring the user’s setting.</p>
|
|||
|
</section>
|
|||
|
<section id="company">
|
|||
|
<h3><a class="toc-backref" href="#company" role="doc-backlink">Company</a></h3>
|
|||
|
<p>The Company part of the key is intended to group related environments and to
|
|||
|
ensure that Tags are namespaced appropriately. The key name should be
|
|||
|
alphanumeric without spaces and likely to be unique. For example, a trademarked
|
|||
|
name (preferred), a hostname, or as a last resort, a UUID would be appropriate:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">www</span><span class="o">.</span><span class="n">example</span><span class="o">.</span><span class="n">com</span>
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="mi">6</span><span class="n">C465E66</span><span class="o">-</span><span class="mi">5</span><span class="n">A8C</span><span class="o">-</span><span class="mi">4942</span><span class="o">-</span><span class="mf">9E6</span><span class="n">A</span><span class="o">-</span><span class="n">D29159480C60</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>The company name <code class="docutils literal notranslate"><span class="pre">PyLauncher</span></code> is reserved for the <a class="pep reference internal" href="../pep-0397/" title="PEP 397 – Python launcher for Windows">PEP 397</a> launcher
|
|||
|
(<code class="docutils literal notranslate"><span class="pre">py.exe</span></code>). It does not follow this convention and should be ignored by tools.</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">DisplayName</span></code> exists, it should be used to identify
|
|||
|
the environment manufacturer/developer/distributor to users. Otherwise, the name
|
|||
|
of the key should be used. (For <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default display name is
|
|||
|
“Python Software Foundation”.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">SupportUrl</span></code> exists, it may be displayed or otherwise
|
|||
|
used to direct users to a web site related to the environment. (For
|
|||
|
<code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default support URL is “<a class="reference external" href="http://www.python.org/">http://www.python.org/</a>”.)</p>
|
|||
|
<p>A complete example may look like:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">value</span> <span class="ow">not</span> <span class="nb">set</span><span class="p">)</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Example Corp"</span>
|
|||
|
<span class="n">SupportUrl</span> <span class="o">=</span> <span class="s2">"http://www.example.com"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="tag">
|
|||
|
<h3><a class="toc-backref" href="#tag" role="doc-backlink">Tag</a></h3>
|
|||
|
<p>The Tag part of the key is intended to uniquely identify an environment within
|
|||
|
those provided by a single company. The key name should be alphanumeric without
|
|||
|
spaces and stable across installations. For example, the Python language
|
|||
|
version, a UUID or a partial/complete hash would be appropriate, while a Tag
|
|||
|
based on the install directory or some aspect of the current machine may not.
|
|||
|
For example:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="n">examplepy</span>
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="mf">3.6</span>
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="mi">6</span><span class="n">C465E66</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>It is expected that some tools will require users to type the Tag into a command
|
|||
|
line, and that the Company may be optional provided the Tag is unique across all
|
|||
|
Python installations. Short, human-readable and easy to type Tags are
|
|||
|
recommended, and if possible, select a value likely to be unique across all
|
|||
|
other Companies.</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">DisplayName</span></code> exists, it should be used to identify
|
|||
|
the environment to users. Otherwise, the name of the key should be used. (For
|
|||
|
<code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default is “Python “ followed by the Tag.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">SupportUrl</span></code> exists, it may be displayed or otherwise
|
|||
|
used to direct users to a web site related to the environment. (For
|
|||
|
<code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default is “<a class="reference external" href="http://www.python.org/">http://www.python.org/</a>”.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">Version</span></code> exists, it should be used to identify the
|
|||
|
version of the environment. This is independent from the version of Python
|
|||
|
implemented by the environment. (For <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default is the first
|
|||
|
three characters of the Tag.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">SysVersion</span></code> exists, it must be in <code class="docutils literal notranslate"><span class="pre">x.y</span></code> or
|
|||
|
<code class="docutils literal notranslate"><span class="pre">x.y.z</span></code> format matching the version returned by <code class="docutils literal notranslate"><span class="pre">sys.version_info</span></code> in the
|
|||
|
interpreter. If omitted, the Python version is unknown. (For <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>,
|
|||
|
the default is the first three characters of the Tag.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">SysArchitecture</span></code> exists, it must match the first
|
|||
|
element of the tuple returned by <code class="docutils literal notranslate"><span class="pre">platform.architecture()</span></code>. Typically, this
|
|||
|
will be “32bit” or “64bit”. If omitted, the architecture is unknown. (For
|
|||
|
<code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the architecture is “32bit” when registered under
|
|||
|
<code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE\Software\Wow6432Node\Python</span></code> <em>or</em> anywhere on a 32-bit
|
|||
|
operating system, “64bit” when registered under
|
|||
|
<code class="docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE\Software\Python</span></code> on a 64-bit machine, and unknown when
|
|||
|
registered under <code class="docutils literal notranslate"><span class="pre">HKEY_CURRENT_USER</span></code>.)</p>
|
|||
|
<p>Note that each of these values is recommended, but optional. Omitting
|
|||
|
<code class="docutils literal notranslate"><span class="pre">SysVersion</span></code> or <code class="docutils literal notranslate"><span class="pre">SysArchitecture</span></code> may prevent some tools from correctly
|
|||
|
supporting the environment. A complete example may look like this:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="n">examplepy</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">value</span> <span class="ow">not</span> <span class="nb">set</span><span class="p">)</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Example Py Distro 3"</span>
|
|||
|
<span class="n">SupportUrl</span> <span class="o">=</span> <span class="s2">"http://www.example.com/distro-3"</span>
|
|||
|
<span class="n">Version</span> <span class="o">=</span> <span class="s2">"3.0.12345.0"</span>
|
|||
|
<span class="n">SysVersion</span> <span class="o">=</span> <span class="s2">"3.6.0"</span>
|
|||
|
<span class="n">SysArchitecture</span> <span class="o">=</span> <span class="s2">"64bit"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="installpath">
|
|||
|
<h3><a class="toc-backref" href="#installpath" role="doc-backlink">InstallPath</a></h3>
|
|||
|
<p>Beneath the environment key, an <code class="docutils literal notranslate"><span class="pre">InstallPath</span></code> key must be created. This key is
|
|||
|
always named <code class="docutils literal notranslate"><span class="pre">InstallPath</span></code>, and the default value must match <code class="docutils literal notranslate"><span class="pre">sys.prefix</span></code>:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="mf">3.6</span>\<span class="n">InstallPath</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="s2">"C:\ExampleCorpPy36"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">ExecutablePath</span></code> exists, it must be the full path to
|
|||
|
the <code class="docutils literal notranslate"><span class="pre">python.exe</span></code> (or equivalent) executable. If omitted, the environment is
|
|||
|
not executable. (For <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default is the <code class="docutils literal notranslate"><span class="pre">python.exe</span></code> file in
|
|||
|
the directory referenced by the <code class="docutils literal notranslate"><span class="pre">(Default)</span></code> value.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">ExecutableArguments</span></code> exists, tools should use the
|
|||
|
value as the first arguments when executing <code class="docutils literal notranslate"><span class="pre">ExecutablePath</span></code>. Tools may add
|
|||
|
other arguments following these, and will reasonably expect standard Python
|
|||
|
command line options to be available.</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">WindowedExecutablePath</span></code> exists, it must be a path to
|
|||
|
the <code class="docutils literal notranslate"><span class="pre">pythonw.exe</span></code> (or equivalent) executable. If omitted, the default is the
|
|||
|
value of <code class="docutils literal notranslate"><span class="pre">ExecutablePath</span></code>, and if that is omitted the environment is not
|
|||
|
executable. (For <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>, the default is the <code class="docutils literal notranslate"><span class="pre">pythonw.exe</span></code> file in the
|
|||
|
directory referenced by the <code class="docutils literal notranslate"><span class="pre">(Default)</span></code> value.)</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">WindowedExecutableArguments</span></code> exists, tools should use
|
|||
|
the value as the first arguments when executing <code class="docutils literal notranslate"><span class="pre">WindowedExecutablePath</span></code>.
|
|||
|
Tools may add other arguments following these, and will reasonably expect
|
|||
|
standard Python command line options to be available.</p>
|
|||
|
<p>A complete example may look like:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="n">examplepy</span>\<span class="n">InstallPath</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="s2">"C:\ExampleDistro30"</span>
|
|||
|
<span class="n">ExecutablePath</span> <span class="o">=</span> <span class="s2">"C:\ExampleDistro30\ex_python.exe"</span>
|
|||
|
<span class="n">ExecutableArguments</span> <span class="o">=</span> <span class="s2">"--arg1"</span>
|
|||
|
<span class="n">WindowedExecutablePath</span> <span class="o">=</span> <span class="s2">"C:\ExampleDistro30\ex_pythonw.exe"</span>
|
|||
|
<span class="n">WindowedExecutableArguments</span> <span class="o">=</span> <span class="s2">"--arg1"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="help">
|
|||
|
<h3><a class="toc-backref" href="#help" role="doc-backlink">Help</a></h3>
|
|||
|
<p>Beneath the environment key, a <code class="docutils literal notranslate"><span class="pre">Help</span></code> key may be created. This key is always
|
|||
|
named <code class="docutils literal notranslate"><span class="pre">Help</span></code> if present and has no default value.</p>
|
|||
|
<p>Each subkey of <code class="docutils literal notranslate"><span class="pre">Help</span></code> specifies a documentation file, tool, or URL associated
|
|||
|
with the environment. The subkey may have any name, and the default value is a
|
|||
|
string appropriate for passing to <code class="docutils literal notranslate"><span class="pre">os.startfile</span></code> or equivalent.</p>
|
|||
|
<p>If a string value named <code class="docutils literal notranslate"><span class="pre">DisplayName</span></code> exists, it should be used to identify
|
|||
|
the help file to users. Otherwise, the key name should be used.</p>
|
|||
|
<p>A complete example may look like:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">ExampleCorp</span>\<span class="mi">6</span><span class="n">C465E66</span>\<span class="n">Help</span>
|
|||
|
<span class="n">Python</span>\
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="s2">"C:\ExampleDistro30\python36.chm"</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Python Documentation"</span>
|
|||
|
<span class="n">Extras</span>\
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="s2">"http://www.example.com/tutorial"</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Example Distro Online Tutorial"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="other-keys">
|
|||
|
<h3><a class="toc-backref" href="#other-keys" role="doc-backlink">Other Keys</a></h3>
|
|||
|
<p>All other subkeys under a Company-Tag pair are available for private use.</p>
|
|||
|
<p>Official CPython releases have traditionally used certain keys in this space to
|
|||
|
determine the location of the Python standard library and other installed
|
|||
|
modules. This behaviour is retained primarily for backward compatibility.
|
|||
|
However, as the code that reads these values is embedded into the interpreter,
|
|||
|
third-party distributions may be affected by values written into <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>
|
|||
|
if using an unmodified interpreter.</p>
|
|||
|
</section>
|
|||
|
</section>
|
|||
|
<section id="sample-code">
|
|||
|
<h2><a class="toc-backref" href="#sample-code" role="doc-backlink">Sample Code</a></h2>
|
|||
|
<p>This sample code enumerates the registry and displays the available Company-Tag
|
|||
|
pairs that could be used to launch an environment and the target executable. It
|
|||
|
only shows the most-preferred target for the tag. Backwards-compatible handling
|
|||
|
of <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> is omitted but shown in a later example:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Display most-preferred environments.</span>
|
|||
|
<span class="c1"># Assumes a 64-bit operating system</span>
|
|||
|
<span class="c1"># Does not correctly handle PythonCore compatibility</span>
|
|||
|
|
|||
|
<span class="kn">import</span> <span class="nn">winreg</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">enum_keys</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
|
|||
|
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
|
|||
|
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="k">yield</span> <span class="n">winreg</span><span class="o">.</span><span class="n">EnumKey</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
|
|||
|
<span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
|
|||
|
<span class="k">break</span>
|
|||
|
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">get_value</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value_name</span><span class="p">):</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="k">return</span> <span class="n">winreg</span><span class="o">.</span><span class="n">QueryValue</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value_name</span><span class="p">)</span>
|
|||
|
<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>
|
|||
|
<span class="k">return</span> <span class="kc">None</span>
|
|||
|
|
|||
|
<span class="n">seen</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
|
|||
|
<span class="k">for</span> <span class="n">hive</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">flags</span> <span class="ow">in</span> <span class="p">[</span>
|
|||
|
<span class="p">(</span><span class="n">winreg</span><span class="o">.</span><span class="n">HKEY_CURRENT_USER</span><span class="p">,</span> <span class="sa">r</span><span class="s1">'Software\Python'</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
|
|||
|
<span class="p">(</span><span class="n">winreg</span><span class="o">.</span><span class="n">HKEY_LOCAL_MACHINE</span><span class="p">,</span> <span class="sa">r</span><span class="s1">'Software\Python'</span><span class="p">,</span> <span class="n">winreg</span><span class="o">.</span><span class="n">KEY_WOW64_64KEY</span><span class="p">),</span>
|
|||
|
<span class="p">(</span><span class="n">winreg</span><span class="o">.</span><span class="n">HKEY_LOCAL_MACHINE</span><span class="p">,</span> <span class="sa">r</span><span class="s1">'Software\Python'</span><span class="p">,</span> <span class="n">winreg</span><span class="o">.</span><span class="n">KEY_WOW64_32KEY</span><span class="p">),</span>
|
|||
|
<span class="p">]:</span>
|
|||
|
<span class="k">with</span> <span class="n">winreg</span><span class="o">.</span><span class="n">OpenKeyEx</span><span class="p">(</span><span class="n">hive</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">access</span><span class="o">=</span><span class="n">winreg</span><span class="o">.</span><span class="n">KEY_READ</span> <span class="o">|</span> <span class="n">flags</span><span class="p">)</span> <span class="k">as</span> <span class="n">root_key</span><span class="p">:</span>
|
|||
|
<span class="k">for</span> <span class="n">company</span> <span class="ow">in</span> <span class="n">enum_keys</span><span class="p">(</span><span class="n">root_key</span><span class="p">):</span>
|
|||
|
<span class="k">if</span> <span class="n">company</span> <span class="o">==</span> <span class="s1">'PyLauncher'</span><span class="p">:</span>
|
|||
|
<span class="k">continue</span>
|
|||
|
|
|||
|
<span class="k">with</span> <span class="n">winreg</span><span class="o">.</span><span class="n">OpenKey</span><span class="p">(</span><span class="n">root_key</span><span class="p">,</span> <span class="n">company</span><span class="p">)</span> <span class="k">as</span> <span class="n">company_key</span><span class="p">:</span>
|
|||
|
<span class="k">for</span> <span class="n">tag</span> <span class="ow">in</span> <span class="n">enum_keys</span><span class="p">(</span><span class="n">company_key</span><span class="p">):</span>
|
|||
|
<span class="k">if</span> <span class="p">(</span><span class="n">company</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span> <span class="ow">in</span> <span class="n">seen</span><span class="p">:</span>
|
|||
|
<span class="k">if</span> <span class="n">company</span> <span class="o">==</span> <span class="s1">'PythonCore'</span><span class="p">:</span>
|
|||
|
<span class="c1"># TODO: Backwards compatibility handling</span>
|
|||
|
<span class="k">pass</span>
|
|||
|
<span class="k">continue</span>
|
|||
|
<span class="n">seen</span><span class="o">.</span><span class="n">add</span><span class="p">((</span><span class="n">company</span><span class="p">,</span> <span class="n">tag</span><span class="p">))</span>
|
|||
|
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="k">with</span> <span class="n">winreg</span><span class="o">.</span><span class="n">OpenKey</span><span class="p">(</span><span class="n">company_key</span><span class="p">,</span> <span class="n">tag</span> <span class="o">+</span> <span class="sa">r</span><span class="s1">'\InstallPath'</span><span class="p">)</span> <span class="k">as</span> <span class="n">ip_key</span><span class="p">:</span>
|
|||
|
<span class="n">exec_path</span> <span class="o">=</span> <span class="n">get_value</span><span class="p">(</span><span class="n">ip_key</span><span class="p">,</span> <span class="s1">'ExecutablePath'</span><span class="p">)</span>
|
|||
|
<span class="n">exec_args</span> <span class="o">=</span> <span class="n">get_value</span><span class="p">(</span><span class="n">ip_key</span><span class="p">,</span> <span class="s1">'ExecutableArguments'</span><span class="p">)</span>
|
|||
|
<span class="k">if</span> <span class="n">company</span> <span class="o">==</span> <span class="s1">'PythonCore'</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">exec_path</span><span class="p">:</span>
|
|||
|
<span class="c1"># TODO: Backwards compatibility handling</span>
|
|||
|
<span class="k">pass</span>
|
|||
|
<span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
|
|||
|
<span class="n">exec_path</span><span class="p">,</span> <span class="n">exec_args</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>
|
|||
|
|
|||
|
<span class="k">if</span> <span class="n">exec_path</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="se">\\</span><span class="si">{}</span><span class="s1"> - </span><span class="si">{}</span><span class="s1"> </span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">company</span><span class="p">,</span> <span class="n">tag</span><span class="p">,</span> <span class="n">exec_path</span><span class="p">,</span> <span class="n">exec_args</span> <span class="ow">or</span> <span class="s1">''</span><span class="p">))</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="se">\\</span><span class="si">{}</span><span class="s1"> - (not executable)'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">company</span><span class="p">,</span> <span class="n">tag</span><span class="p">))</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>This example only scans <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code> entries for the current user. Where data
|
|||
|
is missing, the defaults as described earlier in the PEP are substituted. Note
|
|||
|
that these defaults are only for use under <code class="docutils literal notranslate"><span class="pre">PythonCore</span></code>; other registrations
|
|||
|
do not have any default values:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Only lists per-user PythonCore registrations</span>
|
|||
|
<span class="c1"># Uses fallback values as described in PEP 514</span>
|
|||
|
|
|||
|
<span class="kn">import</span> <span class="nn">os</span>
|
|||
|
<span class="kn">import</span> <span class="nn">winreg</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">enum_keys</span><span class="p">(</span><span class="n">key</span><span class="p">):</span>
|
|||
|
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
|
|||
|
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="k">yield</span> <span class="n">winreg</span><span class="o">.</span><span class="n">EnumKey</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">i</span><span class="p">)</span>
|
|||
|
<span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
|
|||
|
<span class="k">break</span>
|
|||
|
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">get_value</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value_name</span><span class="p">):</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="k">return</span> <span class="n">winreg</span><span class="o">.</span><span class="n">QueryValue</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value_name</span><span class="p">)</span>
|
|||
|
<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>
|
|||
|
<span class="k">return</span> <span class="kc">None</span>
|
|||
|
|
|||
|
<span class="k">with</span> <span class="n">winreg</span><span class="o">.</span><span class="n">OpenKey</span><span class="p">(</span><span class="n">winreg</span><span class="o">.</span><span class="n">HKEY_CURRENT_USER</span><span class="p">,</span> <span class="sa">r</span><span class="s2">"Software\Python\PythonCore"</span><span class="p">)</span> <span class="k">as</span> <span class="n">company_key</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'Company:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">company_key</span><span class="p">,</span> <span class="s1">'DisplayName'</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">'Python Software Foundation'</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'Support:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">company_key</span><span class="p">,</span> <span class="s1">'SupportUrl'</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">'http://www.python.org/'</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">()</span>
|
|||
|
|
|||
|
<span class="k">for</span> <span class="n">tag</span> <span class="ow">in</span> <span class="n">enum_keys</span><span class="p">(</span><span class="n">company_key</span><span class="p">):</span>
|
|||
|
<span class="k">with</span> <span class="n">winreg</span><span class="o">.</span><span class="n">OpenKey</span><span class="p">(</span><span class="n">company_key</span><span class="p">,</span> <span class="n">tag</span><span class="p">)</span> <span class="k">as</span> <span class="n">tag_key</span><span class="p">:</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'PythonCore</span><span class="se">\\</span><span class="s1">'</span> <span class="o">+</span> <span class="n">tag</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'Name:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">tag_key</span><span class="p">,</span> <span class="s1">'DisplayName'</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="s1">'Python '</span> <span class="o">+</span> <span class="n">tag</span><span class="p">))</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'Support:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">tag_key</span><span class="p">,</span> <span class="s1">'SupportUrl'</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">'http://www.python.org/'</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'Version:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">tag_key</span><span class="p">,</span> <span class="s1">'Version'</span><span class="p">)</span> <span class="ow">or</span> <span class="n">tag</span><span class="p">[:</span><span class="mi">3</span><span class="p">])</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'SysVersion:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">tag_key</span><span class="p">,</span> <span class="s1">'SysVersion'</span><span class="p">)</span> <span class="ow">or</span> <span class="n">tag</span><span class="p">[:</span><span class="mi">3</span><span class="p">])</span>
|
|||
|
<span class="c1"># Architecture is unknown because we are in HKCU</span>
|
|||
|
<span class="c1"># Tools may use alternate approaches to determine architecture when</span>
|
|||
|
<span class="c1"># the registration does not specify it.</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'SysArchitecture:'</span><span class="p">,</span> <span class="n">get_value</span><span class="p">(</span><span class="n">tag_key</span><span class="p">,</span> <span class="s1">'SysArchitecture'</span><span class="p">)</span> <span class="ow">or</span> <span class="s1">'(unknown)'</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="n">ip_key</span> <span class="o">=</span> <span class="n">winreg</span><span class="o">.</span><span class="n">OpenKey</span><span class="p">(</span><span class="n">company_key</span><span class="p">,</span> <span class="n">tag</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">InstallPath'</span><span class="p">)</span>
|
|||
|
<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span>
|
|||
|
<span class="k">pass</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="k">with</span> <span class="n">ip_key</span><span class="p">:</span>
|
|||
|
<span class="n">ip</span> <span class="o">=</span> <span class="n">get_value</span><span class="p">(</span><span class="n">ip_key</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
|
|||
|
<span class="n">exe</span> <span class="o">=</span> <span class="n">get_value</span><span class="p">(</span><span class="n">ip_key</span><span class="p">,</span> <span class="s1">'ExecutablePath'</span><span class="p">)</span> <span class="ow">or</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ip</span><span class="p">,</span> <span class="s1">'python.exe'</span><span class="p">)</span>
|
|||
|
<span class="n">exew</span> <span class="o">=</span> <span class="n">get_value</span><span class="p">(</span><span class="n">ip_key</span><span class="p">,</span> <span class="s1">'WindowedExecutablePath'</span><span class="p">)</span> <span class="ow">or</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ip</span><span class="p">,</span> <span class="s1">'python.exe'</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'InstallPath:'</span><span class="p">,</span> <span class="n">ip</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'ExecutablePath:'</span><span class="p">,</span> <span class="n">exe</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'WindowedExecutablePath:'</span><span class="p">,</span> <span class="n">exew</span><span class="p">)</span>
|
|||
|
<span class="nb">print</span><span class="p">()</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>This example shows a subset of the registration that will be created by a
|
|||
|
just-for-me install of 64-bit Python 3.6.0. Other keys may also be created:</p>
|
|||
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">PythonCore</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">value</span> <span class="ow">not</span> <span class="nb">set</span><span class="p">)</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Python Software Foundation"</span>
|
|||
|
<span class="n">SupportUrl</span> <span class="o">=</span> <span class="s2">"http://www.python.org/"</span>
|
|||
|
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">PythonCore</span>\<span class="mf">3.6</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">value</span> <span class="ow">not</span> <span class="nb">set</span><span class="p">)</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Python 3.6 (64-bit)"</span>
|
|||
|
<span class="n">SupportUrl</span> <span class="o">=</span> <span class="s2">"http://www.python.org/"</span>
|
|||
|
<span class="n">Version</span> <span class="o">=</span> <span class="s2">"3.6.0"</span>
|
|||
|
<span class="n">SysVersion</span> <span class="o">=</span> <span class="s2">"3.6"</span>
|
|||
|
<span class="n">SysArchitecture</span> <span class="o">=</span> <span class="s2">"64bit"</span>
|
|||
|
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">PythonCore</span>\<span class="mf">3.6</span>\<span class="n">Help</span>\<span class="n">Main</span> <span class="n">Python</span> <span class="n">Documentation</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="s2">"C:\Users\Me\AppData\Local\Programs\Python\Python36\Doc\python360.chm"</span>
|
|||
|
<span class="n">DisplayName</span> <span class="o">=</span> <span class="s2">"Python 3.6.0 Documentation"</span>
|
|||
|
|
|||
|
<span class="n">HKEY_CURRENT_USER</span>\<span class="n">Software</span>\<span class="n">Python</span>\<span class="n">PythonCore</span>\<span class="mf">3.6</span>\<span class="n">InstallPath</span>
|
|||
|
<span class="p">(</span><span class="n">Default</span><span class="p">)</span> <span class="o">=</span> <span class="s2">"C:\Users\Me\AppData\Local\Programs\Python\Python36</span><span class="se">\"</span>
|
|||
|
<span class="n">ExecutablePath</span> <span class="o">=</span> <span class="s2">"C:\Users\Me\AppData\Local\Programs\Python\Python36\python.exe"</span>
|
|||
|
<span class="n">WindowedExecutablePath</span> <span class="o">=</span> <span class="s2">"C:\Users\Me\AppData\Local\Programs\Python\Python36\pythonw.exe"</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
</section>
|
|||
|
<section id="references">
|
|||
|
<h2><a class="toc-backref" href="#references" role="doc-backlink">References</a></h2>
|
|||
|
<aside class="footnote-list brackets">
|
|||
|
<aside class="footnote brackets" id="id2" role="doc-footnote">
|
|||
|
<dt class="label" id="id2">[<a href="#id1">1</a>]</dt>
|
|||
|
<dd>Registry Redirector (Windows)
|
|||
|
(<a class="reference external" href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384232.aspx">https://msdn.microsoft.com/en-us/library/windows/desktop/aa384232.aspx</a>)</aside>
|
|||
|
</aside>
|
|||
|
</section>
|
|||
|
<section id="copyright">
|
|||
|
<h2><a class="toc-backref" href="#copyright" role="doc-backlink">Copyright</a></h2>
|
|||
|
<p>This document has been placed in the public domain.</p>
|
|||
|
</section>
|
|||
|
</section>
|
|||
|
<hr class="docutils" />
|
|||
|
<p>Source: <a class="reference external" href="https://github.com/python/peps/blob/main/peps/pep-0514.rst">https://github.com/python/peps/blob/main/peps/pep-0514.rst</a></p>
|
|||
|
<p>Last modified: <a class="reference external" href="https://github.com/python/peps/commits/main/peps/pep-0514.rst">2023-09-09 17:39:29 GMT</a></p>
|
|||
|
|
|||
|
</article>
|
|||
|
<nav id="pep-sidebar">
|
|||
|
<h2>Contents</h2>
|
|||
|
<ul>
|
|||
|
<li><a class="reference internal" href="#abstract">Abstract</a></li>
|
|||
|
<li><a class="reference internal" href="#motivation">Motivation</a></li>
|
|||
|
<li><a class="reference internal" href="#definitions">Definitions</a></li>
|
|||
|
<li><a class="reference internal" href="#structure">Structure</a><ul>
|
|||
|
<li><a class="reference internal" href="#backwards-compatibility">Backwards Compatibility</a></li>
|
|||
|
<li><a class="reference internal" href="#company">Company</a></li>
|
|||
|
<li><a class="reference internal" href="#tag">Tag</a></li>
|
|||
|
<li><a class="reference internal" href="#installpath">InstallPath</a></li>
|
|||
|
<li><a class="reference internal" href="#help">Help</a></li>
|
|||
|
<li><a class="reference internal" href="#other-keys">Other Keys</a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
<li><a class="reference internal" href="#sample-code">Sample Code</a></li>
|
|||
|
<li><a class="reference internal" href="#references">References</a></li>
|
|||
|
<li><a class="reference internal" href="#copyright">Copyright</a></li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<br>
|
|||
|
<a id="source" href="https://github.com/python/peps/blob/main/peps/pep-0514.rst">Page Source (GitHub)</a>
|
|||
|
</nav>
|
|||
|
</section>
|
|||
|
<script src="../_static/colour_scheme.js"></script>
|
|||
|
<script src="../_static/wrap_tables.js"></script>
|
|||
|
<script src="../_static/sticky_banner.js"></script>
|
|||
|
</body>
|
|||
|
</html>
|