python / cpython

The Python programming language
https://www.python.org
Other
63.37k stars 30.33k forks source link

Registry writes on Windows Store - workaround #85350

Open d94af357-64a2-416d-ae9d-4745c951b6b0 opened 4 years ago

d94af357-64a2-416d-ae9d-4745c951b6b0 commented 4 years ago
BPO 41178
Nosy @pfmoore, @tjguk, @zware, @zooba

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['type-feature', '3.8', 'OS-windows'] title = 'Registry writes on Windows Store - workaround' updated_at = user = 'https://bugs.python.org/DataGhost' ``` bugs.python.org fields: ```python activity = actor = 'DataGhost' assignee = 'none' closed = False closed_date = None closer = None components = ['Windows'] creation = creator = 'DataGhost' dependencies = [] files = [] hgrepos = [] issue_num = 41178 keywords = [] message_count = 1.0 messages = ['372726'] nosy_count = 5.0 nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'steve.dower', 'DataGhost'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'enhancement' url = 'https://bugs.python.org/issue41178' versions = ['Python 3.8'] ```

d94af357-64a2-416d-ae9d-4745c951b6b0 commented 4 years ago

I just installed the Windows Store version of Python (v3.8.3:6f8c832) on Windows 10.0.18362.900 (1903, old VM) and quickly ran into the issue that registry writes aren't visible system-wide. I later found a remark about this in the Known Issues section of the Using Python on Windows page. Real-world scenario: running "python -m pip install --user pipx" and subsequently "python -m pipx ensurepath" says it changed the PATH variable, but it does not take effect even after a reboot. I'd say this is one of the cases where a user might not know about what's going on and why it fails, even after reading the known issues, and the developer might not have thought of the existence or incompatibility of the Windows Store version of Python at all.

I have found a workaround to do this, though, and I figured the best place to do that is in the actual winreg module so that users and developers don't need to worry about this. Calling reg.exe allows registry variables to be written in the "normal" registry, and these changes are system-wide rather than in the private copy Store apps use. Some functions could be changed to use the reg.exe binary instead of the system calls on Windows Store builds. Other functions, such as for querying, don't need any changes.

I realise this is an ugly workaround so I'm just suggesting it in hopes of improving compatibility, so that users and developers don't need to worry about these issues anymore. I did some basic tests on this, by executing reg.exe through the subprocess module, and testing for a Windows Store instance by checking sys.base_exec_prefix. There are probably better ways but at least this shows that it should be possible in just Python.