Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPDATA directory is different in store installed python #85368

Closed
aku911 mannequin opened this issue Jul 2, 2020 · 8 comments
Closed

APPDATA directory is different in store installed python #85368

aku911 mannequin opened this issue Jul 2, 2020 · 8 comments
Labels
3.8 only security fixes OS-windows type-bug An unexpected behavior, bug, or error

Comments

@aku911
Copy link
Mannequin

aku911 mannequin commented Jul 2, 2020

BPO 41196
Nosy @pfmoore, @tjguk, @zware, @eryksun, @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:

assignee = None
closed_at = <Date 2020-07-02.20:25:57.819>
created_at = <Date 2020-07-02.18:06:42.380>
labels = ['invalid', 'type-bug', '3.8', 'OS-windows']
title = 'APPDATA directory is different in store installed python'
updated_at = <Date 2020-07-03.14:52:12.564>
user = 'https://bugs.python.org/aku911'

bugs.python.org fields:

activity = <Date 2020-07-03.14:52:12.564>
actor = 'steve.dower'
assignee = 'none'
closed = True
closed_date = <Date 2020-07-02.20:25:57.819>
closer = 'steve.dower'
components = ['Windows']
creation = <Date 2020-07-02.18:06:42.380>
creator = 'aku911'
dependencies = []
files = []
hgrepos = []
issue_num = 41196
keywords = []
message_count = 6.0
messages = ['372868', '372869', '372880', '372881', '372902', '372936']
nosy_count = 6.0
nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'aku911']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41196'
versions = ['Python 3.8']

@aku911 aku911 mannequin added 3.8 only security fixes OS-windows type-bug An unexpected behavior, bug, or error labels Jul 2, 2020
@aku911
Copy link
Mannequin Author

aku911 mannequin commented Jul 2, 2020

Install the windows store python then run this code:

import os
os.listdir(os.environ['APPDATA'])

Install another version of python and run the same code.

You'll get different results.

This can cause issues when trying to share data in a user's APPDATA folder.

@aku911
Copy link
Mannequin Author

aku911 mannequin commented Jul 2, 2020

This is causing this issue here:
https://github.com/microsoft/vscode-python/issues/11412

@zooba
Copy link
Member

zooba commented Jul 2, 2020

This is by (Windows's) design - separate apps are treated as separate by the Windows app model. In the latest and N-1 updates to Windows, the AppData redirection only applies to newly created files, not those that already exist. [1] Before then, it used copy-on-write.

The design is based on having seen many apps break because of inadvertently sharing data, and also apps failing to clean up after themselves well (of which Python is *very* guilty). The built-in "Reset App" and "Uninstall App" functions would not be viable without this separation.

What it really means for apps that are trying to share state across different Python runtimes is that they're not going to have such a great time. The best option I can offer is to use the user's Documents folder instead, which is explicitly shared (though may also be synced between machines, so not always appropriate).

The next best option is to recommend that the Store package only be used on its own, and not in conjunction with other Python installs. Those who need multiple versions or mostly-but-not-quite-separate installs will need to use the traditional installer.

But what it means for all the other tools that write to AppData is that they don't have to worry about old settings laying around or causing additional clutter. The standard "Reset app" action is a viable way to fix issues in configuration or cached files (and uninstall all packages). From a user point of view, I really like these features.

1: https://docs.microsoft.com/windows/msix/desktop/desktop-to-uwp-behind-the-scenes

@zooba zooba closed this as completed Jul 2, 2020
@zooba zooba added the invalid label Jul 2, 2020
@zooba zooba closed this as completed Jul 2, 2020
@zooba zooba added the invalid label Jul 2, 2020
@zooba
Copy link
Member

zooba commented Jul 2, 2020

As an aside, virtual environments will have the same redirection as the base interpreter, so this is really only an issue between a 3.7 install and a 3.8 install, or a Store install and a traditional install.

@eryksun
Copy link
Contributor

eryksun commented Jul 3, 2020

What it really means for apps that are trying to share state across
different Python runtimes is that they're not going to have such a
great time.

I tried impersonating the token of Explorer in the current thread (i.e. GetShellWindow, GetWindowThreadProcessId, OpenProcess, OpenProcessToken, ImpersonateLoggedOnUser), but writing to AppData was still redirected. Apparently redirection for apps only looks at the process token. A crude workaround is to script PowerShell or CMD in a child process.

@zooba
Copy link
Member

zooba commented Jul 3, 2020

A crude workaround is to script PowerShell or CMD in a child process.

I mean, that's not a *terrible* workaround:

>>> import os
>>> p1 = os.path.expandvars("%APPDATA%\\test.txt")
>>> p1
'C:\\Users\\steve\\AppData\\Roaming\\test.txt'
>>> open(p1, "w").close()
>>> os.system(f'copy "{os.path.realpath(p1)}" "{p1}"')
        1 file(s) copied.
0
>>>

But yeah, definitely crude :)

@ericoporto
Copy link

@zooba , does that work for Directories too or only files? And does this works for which python versions?

@zooba
Copy link
Member

zooba commented Apr 11, 2023

All of this is Windows, not us. Check the document I linked earlier.

It applies to everything and every version of Python depending on which version of Windows is currently running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes OS-windows type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants