Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
bf04e205
Unverified
Commit
bf04e205
authored
May 01, 2022
by
Randy Döring
Committed by
GitHub
May 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mypy: fix "unused type ignore" issue on windows (#5524)
parent
6721ebe0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
51 deletions
+44
-51
src/poetry/utils/appdirs.py
+44
-51
No files found.
src/poetry/utils/appdirs.py
View file @
bf04e205
...
@@ -8,9 +8,6 @@ import os
...
@@ -8,9 +8,6 @@ import os
import
sys
import
sys
WINDOWS
=
sys
.
platform
.
startswith
(
"win"
)
or
(
sys
.
platform
==
"cli"
and
os
.
name
==
"nt"
)
def
expanduser
(
path
:
str
)
->
str
:
def
expanduser
(
path
:
str
)
->
str
:
"""
"""
Expand ~ and ~user constructions.
Expand ~ and ~user constructions.
...
@@ -44,7 +41,7 @@ def user_cache_dir(appname: str) -> str:
...
@@ -44,7 +41,7 @@ def user_cache_dir(appname: str) -> str:
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value.
"""
"""
if
WINDOWS
:
if
sys
.
platform
==
"win32"
:
# Get the base path
# Get the base path
path
=
os
.
path
.
normpath
(
_get_win_folder
(
"CSIDL_LOCAL_APPDATA"
))
path
=
os
.
path
.
normpath
(
_get_win_folder
(
"CSIDL_LOCAL_APPDATA"
))
...
@@ -93,7 +90,7 @@ def user_data_dir(appname: str, roaming: bool = False) -> str:
...
@@ -93,7 +90,7 @@ def user_data_dir(appname: str, roaming: bool = False) -> str:
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
For Unix, we follow the XDG spec and support $XDG_DATA_HOME.
That means, by default "~/.local/share/<AppName>".
That means, by default "~/.local/share/<AppName>".
"""
"""
if
WINDOWS
:
if
sys
.
platform
==
"win32"
:
const
=
"CSIDL_APPDATA"
if
roaming
else
"CSIDL_LOCAL_APPDATA"
const
=
"CSIDL_APPDATA"
if
roaming
else
"CSIDL_LOCAL_APPDATA"
return
os
.
path
.
join
(
os
.
path
.
normpath
(
_get_win_folder
(
const
)),
appname
)
return
os
.
path
.
join
(
os
.
path
.
normpath
(
_get_win_folder
(
const
)),
appname
)
elif
sys
.
platform
==
"darwin"
:
elif
sys
.
platform
==
"darwin"
:
...
@@ -124,7 +121,7 @@ def user_config_dir(appname: str, roaming: bool = True) -> str:
...
@@ -124,7 +121,7 @@ def user_config_dir(appname: str, roaming: bool = True) -> str:
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME.
That means, by default "~/.config/<AppName>".
That means, by default "~/.config/<AppName>".
"""
"""
if
WINDOWS
:
if
sys
.
platform
==
"win32"
:
path
=
user_data_dir
(
appname
,
roaming
=
roaming
)
path
=
user_data_dir
(
appname
,
roaming
=
roaming
)
elif
sys
.
platform
==
"darwin"
:
elif
sys
.
platform
==
"darwin"
:
path
=
user_data_dir
(
appname
)
path
=
user_data_dir
(
appname
)
...
@@ -153,7 +150,7 @@ def site_config_dirs(appname: str) -> list[str]:
...
@@ -153,7 +150,7 @@ def site_config_dirs(appname: str) -> list[str]:
Win 7: Hidden, but writeable on Win 7:
Win 7: Hidden, but writeable on Win 7:
C:\ProgramData\<AppName>
\
C:\ProgramData\<AppName>
\
"""
"""
if
WINDOWS
:
if
sys
.
platform
==
"win32"
:
path
=
os
.
path
.
normpath
(
_get_win_folder
(
"CSIDL_COMMON_APPDATA"
))
path
=
os
.
path
.
normpath
(
_get_win_folder
(
"CSIDL_COMMON_APPDATA"
))
pathlist
=
[
os
.
path
.
join
(
path
,
appname
)]
pathlist
=
[
os
.
path
.
join
(
path
,
appname
)]
elif
sys
.
platform
==
"darwin"
:
elif
sys
.
platform
==
"darwin"
:
...
@@ -175,54 +172,50 @@ def site_config_dirs(appname: str) -> list[str]:
...
@@ -175,54 +172,50 @@ def site_config_dirs(appname: str) -> list[str]:
return
pathlist
return
pathlist
# -- Windows support functions --
if
sys
.
platform
==
"win32"
:
def
_get_win_folder_from_registry
(
csidl_name
:
str
)
->
str
:
"""
This is a fallback technique at best. I'm not sure if using the
registry for this guarantees us the correct answer for all CSIDL_*
names.
"""
import
_winreg
shell_folder_name
=
{
"CSIDL_APPDATA"
:
"AppData"
,
"CSIDL_COMMON_APPDATA"
:
"Common AppData"
,
"CSIDL_LOCAL_APPDATA"
:
"Local AppData"
,
}[
csidl_name
]
key
=
_winreg
.
OpenKey
(
_winreg
.
HKEY_CURRENT_USER
,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
,
)
directory
,
_type
=
_winreg
.
QueryValueEx
(
key
,
shell_folder_name
)
return
directory
def
_get_win_folder_with_ctypes
(
csidl_name
:
str
)
->
str
:
def
_get_win_folder_from_registry
(
csidl_name
:
str
)
->
str
:
csidl_const
=
{
"""
"CSIDL_APPDATA"
:
26
,
This is a fallback technique at best. I'm not sure if using the
"CSIDL_COMMON_APPDATA"
:
35
,
registry for this guarantees us the correct answer for all CSIDL_*
"CSIDL_LOCAL_APPDATA"
:
28
,
names.
}[
csidl_name
]
"""
import
_winreg
buf
=
ctypes
.
create_unicode_buffer
(
1024
)
shell_folder_name
=
{
windll
=
ctypes
.
windll
# type: ignore[attr-defined]
"CSIDL_APPDATA"
:
"AppData"
,
windll
.
shell32
.
SHGetFolderPathW
(
None
,
csidl_const
,
None
,
0
,
buf
)
"CSIDL_COMMON_APPDATA"
:
"Common AppData"
,
"CSIDL_LOCAL_APPDATA"
:
"Local AppData"
,
# Downgrade to short path name if have highbit chars. See
}[
csidl_name
]
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
has_high_char
=
any
(
ord
(
c
)
>
255
for
c
in
buf
)
if
has_high_char
:
buf2
=
ctypes
.
create_unicode_buffer
(
1024
)
if
windll
.
kernel32
.
GetShortPathNameW
(
buf
.
value
,
buf2
,
1024
):
buf
=
buf2
return
buf
.
value
key
=
_winreg
.
OpenKey
(
_winreg
.
HKEY_CURRENT_USER
,
r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
,
)
directory
,
_type
=
_winreg
.
QueryValueEx
(
key
,
shell_folder_name
)
return
directory
def
_get_win_folder_with_ctypes
(
csidl_name
:
str
)
->
str
:
csidl_const
=
{
"CSIDL_APPDATA"
:
26
,
"CSIDL_COMMON_APPDATA"
:
35
,
"CSIDL_LOCAL_APPDATA"
:
28
,
}[
csidl_name
]
buf
=
ctypes
.
create_unicode_buffer
(
1024
)
windll
=
ctypes
.
windll
windll
.
shell32
.
SHGetFolderPathW
(
None
,
csidl_const
,
None
,
0
,
buf
)
# Downgrade to short path name if have highbit chars. See
# <http://bugs.activestate.com/show_bug.cgi?id=85099>.
has_high_char
=
any
(
ord
(
c
)
>
255
for
c
in
buf
)
if
has_high_char
:
buf2
=
ctypes
.
create_unicode_buffer
(
1024
)
if
windll
.
kernel32
.
GetShortPathNameW
(
buf
.
value
,
buf2
,
1024
):
buf
=
buf2
return
buf
.
value
if
WINDOWS
:
try
:
try
:
import
ctypes
import
ctypes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment