Skip to content

Commit 4b468a9

Browse files
committed
Merge branch 'refactor-logging' into dev
2 parents 26240cb + 69eef72 commit 4b468a9

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

msal_extensions/cache_lock.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import time
66
import logging
77
from distutils.version import LooseVersion
8-
import warnings
98

109
import portalocker
1110

@@ -33,16 +32,12 @@ def __init__(self, lockfile_path):
3332
flags=portalocker.LOCK_EX | portalocker.LOCK_NB,
3433
**open_kwargs)
3534

36-
def try_to_create_lock_file(self):
37-
"""Do not call this. It will be removed in next release"""
38-
warnings.warn("try_to_create_lock_file() will be removed", DeprecationWarning)
39-
return self._try_to_create_lock_file()
40-
4135
def _try_to_create_lock_file(self):
4236
timeout = 5
4337
check_interval = 0.25
4438
current_time = getattr(time, "monotonic", time.time)
4539
timeout_end = current_time() + timeout
40+
pid = os.getpid()
4641
while timeout_end > current_time():
4742
try:
4843
with open(self._lockpath, 'x'): # pylint: disable=unspecified-encoding
@@ -51,15 +46,18 @@ def _try_to_create_lock_file(self):
5146
logger.warning("Python 2 does not support atomic creation of file")
5247
return False
5348
except FileExistsError: # Only Python 3 will reach this clause
54-
logger.warning("Lock file exists, trying again after some time")
49+
logger.debug(
50+
"Process %d found existing lock file, will retry after %f second",
51+
pid, check_interval)
5552
time.sleep(check_interval)
5653
return False
5754

5855
def __enter__(self):
56+
pid = os.getpid()
5957
if not self._try_to_create_lock_file():
60-
logger.warning("Failed to create lock file")
58+
logger.warning("Process %d failed to create lock file", pid)
6159
file_handle = self._lock.__enter__()
62-
file_handle.write('{} {}'.format(os.getpid(), sys.argv[0]).encode('utf-8'))
60+
file_handle.write('{} {}'.format(pid, sys.argv[0]).encode('utf-8')) # pylint: disable=consider-using-f-string
6361
return file_handle
6462

6563
def __exit__(self, *args):
@@ -70,5 +68,5 @@ def __exit__(self, *args):
7068
# file for itself.
7169
os.remove(self._lockpath)
7270
except OSError as ex: # pylint: disable=invalid-name
73-
if ex.errno != errno.ENOENT and ex.errno != errno.EACCES:
71+
if ex.errno not in (errno.ENOENT, errno.EACCES):
7472
raise

msal_extensions/osx.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ def __init__(self, exit_status):
2121
self.exit_status = exit_status
2222
# TODO: pylint: disable=fixme
2323
# use SecCopyErrorMessageString to fetch the appropriate message here.
24-
self.message = \
25-
'{} ' \
26-
'see https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/MacErrors.h'\
27-
.format(self.exit_status)
24+
self.message = (
25+
'{} see https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/MacErrors.h' # pylint: disable=consider-using-f-string,line-too-long
26+
.format(self.exit_status))
2827

2928
def _get_native_location(name):
3029
# type: (str) -> str
@@ -33,7 +32,7 @@ def _get_native_location(name):
3332
:param name: The name of the library to be loaded.
3433
:return: The location of the library on a MacOS filesystem.
3534
"""
36-
return '/System/Library/Frameworks/{0}.framework/{0}'.format(name)
35+
return '/System/Library/Frameworks/{0}.framework/{0}'.format(name) # pylint: disable=consider-using-f-string
3736

3837

3938
# Load native MacOS libraries

msal_extensions/persistence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def load(self):
227227
# This happens when a load() is called before a save().
228228
# We map it into cross-platform error for unified catching.
229229
raise PersistenceNotFound(
230-
location="Service:{} Account:{}".format(
230+
location="Service:{} Account:{}".format( # pylint: disable=consider-using-f-string
231231
self._service_name, self._account_name),
232232
message=(
233233
"Keychain persistence not initialized. "

0 commit comments

Comments
 (0)