Local appdata location on MS Store python is not what orca thinks it is #32

Closed
opened 2023-08-09 02:58:43 +00:00 by ilidemi · 8 comments
Collaborator

Writes to C:/Users/ilia/AppData/Local/orca get redirected to C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/orca on my install. This is intended MS Store behavior: https://learn.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes#file-system

Asking the shell to do the dirty work is one solution:

>>> from pathlib import Path
>>> p = Path("C:/Users/ilia/AppData/Local/orca")
>>> p.resolve()
WindowsPath('C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/orca')
>>> with open('C:/Users/ilia/AppData/Local/copy.bat', 'w') as f:
...     f.write(f'xcopy {p.resolve()} {p}\\ /s /e')
... 
154
>>> subprocess.run([Path('C:/Users/ilia/AppData/Local/copy.bat').resolve()]) 
[...]
48 File(s) copied
Writes to `C:/Users/ilia/AppData/Local/orca` get redirected to `C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/orca` on my install. This is intended MS Store behavior: https://learn.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-behind-the-scenes#file-system Asking the shell to do the dirty work is one solution: ``` >>> from pathlib import Path >>> p = Path("C:/Users/ilia/AppData/Local/orca") >>> p.resolve() WindowsPath('C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/orca') >>> with open('C:/Users/ilia/AppData/Local/copy.bat', 'w') as f: ... f.write(f'xcopy {p.resolve()} {p}\\ /s /e') ... 154 >>> subprocess.run([Path('C:/Users/ilia/AppData/Local/copy.bat').resolve()]) [...] 48 File(s) copied ```
Author
Collaborator

Simpler solution:

>>> subprocess.run(['xcopy', p.resolve(), p, '/E', '/I'], stdout=subprocess.DEVNULL)
CompletedProcess(args=['xcopy', WindowsPath('C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/orca'), WindowsPath('C:/Users/ilia/AppData/Local/orca'), '/E', '/I'], returncode=0)
Simpler solution: ``` >>> subprocess.run(['xcopy', p.resolve(), p, '/E', '/I'], stdout=subprocess.DEVNULL) CompletedProcess(args=['xcopy', WindowsPath('C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/orca'), WindowsPath('C:/Users/ilia/AppData/Local/orca'), '/E', '/I'], returncode=0) ```
bvisness added this to the Jam MVP milestone 2023-08-09 17:20:44 +00:00
bvisness self-assigned this 2023-08-09 17:20:50 +00:00
Owner

Confoundingly, when I install Python from the MS Store, I don't get the same behavior:

Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import Path
>>> p = Path("C:/Users/bvisn/AppData/Local/orca") 
>>> p.resolve()
WindowsPath('C:/Users/bvisn/AppData/Local/orca')

It would really be convenient if I could actually reproduce this...

Confoundingly, when I install Python from the MS Store, I don't get the same behavior: ``` Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from pathlib import Path >>> p = Path("C:/Users/bvisn/AppData/Local/orca") >>> p.resolve() WindowsPath('C:/Users/bvisn/AppData/Local/orca') ``` It would really be convenient if I could actually reproduce this...
Owner

Ok, bizarre. Because AppData\Local\orca already existed on my system, it didn't do the redirect shenanigans. If I delete that folder, I reproduce it just fine.

Ok, bizarre. Because `AppData\Local\orca` already existed on my system, it didn't do the redirect shenanigans. If I delete that folder, I reproduce it just fine.
Author
Collaborator

The doc link mentions:

Modifications to existing files under the user's AppData folder is allowed in order to provide a higher degree of compatibility and interactivity between apps and the OS.

Same happens if I try to resolve a non-existing path:

>>> p = Path("C:/Users/ilia/Appdata/Local/abacabadabacaba")
>>> p.resolve()
WindowsPath('C:/Users/ilia/AppData/Local/abacabadabacaba')
>>> with open(p, 'w') as f:
...     f.write('hi')
...
2
>>> p.resolve()
WindowsPath('C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/abacabadabacaba')
The doc link mentions: > Modifications to existing files under the user's AppData folder is allowed in order to provide a higher degree of compatibility and interactivity between apps and the OS. Same happens if I try to resolve a non-existing path: ``` >>> p = Path("C:/Users/ilia/Appdata/Local/abacabadabacaba") >>> p.resolve() WindowsPath('C:/Users/ilia/AppData/Local/abacabadabacaba') >>> with open(p, 'w') as f: ... f.write('hi') ... 2 >>> p.resolve() WindowsPath('C:/Users/ilia/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/Local/abacabadabacaba') ```
Author
Collaborator

This may also mean that after shelling to xcopy the original folder won't be possible to delete from python code. So it'd either need a different name or another shell command to remove itself.

This may also mean that after shelling to xcopy the original folder won't be possible to delete from python code. So it'd either need a different name or another shell command to remove itself.
Owner

It seems that all I have to do is create the folders using the shell, and then the rest all works fine, no xcopy.

It seems that all I have to do is create the folders using the shell, and then the rest all works fine, no xcopy.
Owner

@MartinFouilleul Did you say on Monday that this was still giving you trouble? I don't remember now.

@MartinFouilleul Did you say on Monday that this was still giving you trouble? I don't remember now.
Collaborator

No, it doesn't cause trouble for me, I think we can close this since #44 was merged.

No, it doesn't cause trouble for me, I think we can close this since #44 was merged.
Sign in to join this conversation.
No Label
macOS
windows
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hmn/orca#32
No description provided.