@@ -81,15 +81,15 @@ def _do_i_own(path: str) -> bool:
81
81
try :
82
82
return p .owner () == os .getlogin ()
83
83
except Exception :
84
- pass
84
+ pass # noqa
85
85
86
86
if hasattr (os , 'geteuid' ):
87
87
try :
88
88
st = p .stat ()
89
89
return st .st_uid == os .geteuid ()
90
90
except (NotImplementedError , OSError ):
91
91
# geteuid not always implemented
92
- pass
92
+ pass # noqa
93
93
94
94
# no ownership checks worked, check write access
95
95
return os .access (p , os .W_OK )
@@ -207,10 +207,10 @@ def jupyter_runtime_dir() -> str:
207
207
else :
208
208
deprecation (
209
209
"Jupyter is migrating its paths to use standard platformdirs\n "
210
- + "given by the platformdirs library. To remove this warning and\n "
211
- + "see the appropriate new directories, set the environment variable\n "
212
- + "`JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.\n "
213
- + "The use of platformdirs will be the default in `jupyter_core` v6"
210
+ "given by the platformdirs library. To remove this warning and\n "
211
+ "see the appropriate new directories, set the environment variable\n "
212
+ "`JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.\n "
213
+ "The use of platformdirs will be the default in `jupyter_core` v6"
214
214
)
215
215
if os .name == "nt" :
216
216
programdata = os .environ .get ("PROGRAMDATA" , None )
@@ -261,10 +261,7 @@ def jupyter_path(*subdirs: str) -> List[str]:
261
261
# Check if site.getuserbase() exists to be compatible with virtualenv,
262
262
# which often does not have this method.
263
263
userbase : Optional [str ]
264
- if hasattr (site , "getuserbase" ):
265
- userbase = site .getuserbase ()
266
- else :
267
- userbase = site .USER_BASE
264
+ userbase = site .getuserbase () if hasattr (site , "getuserbase" ) else site .USER_BASE
268
265
269
266
if userbase :
270
267
userdir = os .path .join (userbase , "share" , "jupyter" )
@@ -334,10 +331,7 @@ def jupyter_config_path() -> List[str]:
334
331
userbase : Optional [str ]
335
332
# Check if site.getuserbase() exists to be compatible with virtualenv,
336
333
# which often does not have this method.
337
- if hasattr (site , "getuserbase" ):
338
- userbase = site .getuserbase ()
339
- else :
340
- userbase = site .USER_BASE
334
+ userbase = site .getuserbase () if hasattr (site , "getuserbase" ) else site .USER_BASE
341
335
342
336
if userbase :
343
337
userdir = os .path .join (userbase , "etc" , "jupyter" )
@@ -439,7 +433,7 @@ def is_file_hidden_posix(abs_path: str, stat_res: Optional[Any] = None) -> bool:
439
433
raise
440
434
441
435
# check that dirs can be listed
442
- if stat .S_ISDIR (stat_res .st_mode ): # type:ignore[misc]
436
+ if stat .S_ISDIR (stat_res .st_mode ): # type:ignore[misc] # noqa
443
437
# use x-access, not actual listing, in case of slow/large listings
444
438
if not os .access (abs_path , os .X_OK | os .R_OK ):
445
439
return True
@@ -457,7 +451,7 @@ def is_file_hidden_posix(abs_path: str, stat_res: Optional[Any] = None) -> bool:
457
451
is_file_hidden = is_file_hidden_posix
458
452
459
453
460
- def is_hidden (abs_path : str , abs_root : str = "" ) -> bool :
454
+ def is_hidden (abs_path : str , abs_root : str = "" ) -> bool : # noqa
461
455
"""Is a file hidden or contained in a hidden directory?
462
456
463
457
This will start with the rightmost path element and work backwards to the
@@ -554,7 +548,7 @@ def win32_restrict_file_to_user(fname: str) -> None:
554
548
win32security .SetFileSecurity (fname , win32security .DACL_SECURITY_INFORMATION , sd )
555
549
556
550
557
- def _win32_restrict_file_to_user_ctypes (fname : str ) -> None :
551
+ def _win32_restrict_file_to_user_ctypes (fname : str ) -> None : # noqa
558
552
"""Secure a windows file to read-only access for the user.
559
553
560
554
Follows guidance from win32 library creator:
@@ -992,16 +986,17 @@ def secure_write(fname: str, binary: bool = False) -> Iterator[Any]:
992
986
if os .name != "nt" :
993
987
# Enforce that the file got the requested permissions before writing
994
988
file_mode = get_file_mode (fname )
995
- if 0o0600 != file_mode :
989
+ if file_mode != 0o0600 : # noqa
996
990
if allow_insecure_writes :
997
991
issue_insecure_write_warning ()
998
992
else :
999
- raise RuntimeError (
993
+ msg = (
1000
994
"Permissions assignment failed for secure file: '{file}'."
1001
995
" Got '{permissions}' instead of '0o0600'." .format (
1002
996
file = fname , permissions = oct (file_mode )
1003
997
)
1004
998
)
999
+ raise RuntimeError (msg )
1005
1000
yield f
1006
1001
1007
1002
0 commit comments