Skip to content

Commit a1bc1ca

Browse files
Copilotxiangyan99
andcommitted
Fix black formatting issues
Co-authored-by: xiangyan99 <[email protected]>
1 parent 464c41d commit a1bc1ca

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

sdk/identity/azure-identity/azure/identity/_credentials/azure_powershell.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313

1414
from .azure_cli import get_safe_working_dir
1515
from .. import CredentialUnavailableError
16-
from .._internal import _scopes_to_resource, resolve_tenant, within_dac, validate_tenant_id, validate_scope
16+
from .._internal import (
17+
_scopes_to_resource,
18+
resolve_tenant,
19+
within_dac,
20+
validate_tenant_id,
21+
validate_scope,
22+
)
1723
from .._internal.decorators import log_get_token
1824

1925

@@ -150,7 +156,9 @@ def get_token(
150156
return AccessToken(token_info.token, token_info.expires_on)
151157

152158
@log_get_token
153-
def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] = None) -> AccessTokenInfo:
159+
def get_token_info(
160+
self, *scopes: str, options: Optional[TokenRequestOptions] = None
161+
) -> AccessTokenInfo:
154162
"""Request an access token for `scopes`.
155163
156164
This is an alternative to `get_token` to enable certain scenarios that require additional properties
@@ -209,7 +217,9 @@ def run_command_line(command_line: List[str], timeout: int) -> str:
209217
try:
210218
proc = start_process(command_line)
211219
stdout, stderr = proc.communicate(**kwargs)
212-
if sys.platform.startswith("win") and ("' is not recognized" in stderr or proc.returncode == 9009):
220+
if sys.platform.startswith("win") and (
221+
"' is not recognized" in stderr or proc.returncode == 9009
222+
):
213223
# pwsh.exe isn't on the path; try powershell.exe
214224
command_line[-1] = command_line[-1].replace("pwsh", "powershell", 1)
215225
proc = start_process(command_line)
@@ -251,8 +261,12 @@ def parse_token(output: str) -> AccessTokenInfo:
251261
return AccessTokenInfo(token, int(expires_on))
252262

253263
if within_dac.get():
254-
raise CredentialUnavailableError(message='Unexpected output from Get-AzAccessToken: "{}"'.format(output))
255-
raise ClientAuthenticationError(message='Unexpected output from Get-AzAccessToken: "{}"'.format(output))
264+
raise CredentialUnavailableError(
265+
message='Unexpected output from Get-AzAccessToken: "{}"'.format(output)
266+
)
267+
raise ClientAuthenticationError(
268+
message='Unexpected output from Get-AzAccessToken: "{}"'.format(output)
269+
)
256270

257271

258272
def get_command_line(scopes: Tuple[str, ...], tenant_id: str) -> List[str]:
@@ -282,7 +296,11 @@ def raise_for_error(return_code: int, stdout: str, stderr: str) -> None:
282296

283297
if stderr:
284298
# stderr is too noisy to include with an exception but may be useful for debugging
285-
_LOGGER.debug('%s received an error from Azure PowerShell: "%s"', AzurePowerShellCredential.__name__, stderr)
299+
_LOGGER.debug(
300+
'%s received an error from Azure PowerShell: "%s"',
301+
AzurePowerShellCredential.__name__,
302+
stderr,
303+
)
286304
raise CredentialUnavailableError(
287305
message="Failed to invoke PowerShell. Enable debug logging for additional information."
288306
)

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ async def get_token(
8888
)
8989

9090
# only ProactorEventLoop supports subprocesses on Windows (and it isn't the default loop on Python < 3.8)
91-
if sys.platform.startswith("win") and not isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop):
91+
if sys.platform.startswith("win") and not isinstance(
92+
asyncio.get_event_loop(), asyncio.ProactorEventLoop
93+
):
9294
return _SyncCredential().get_token(*scopes, tenant_id=tenant_id, **kwargs)
9395

9496
options: TokenRequestOptions = {}
@@ -99,7 +101,9 @@ async def get_token(
99101
return AccessToken(token_info.token, token_info.expires_on)
100102

101103
@log_get_token_async
102-
async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptions] = None) -> AccessTokenInfo:
104+
async def get_token_info(
105+
self, *scopes: str, options: Optional[TokenRequestOptions] = None
106+
) -> AccessTokenInfo:
103107
"""Request an access token for `scopes`.
104108
105109
This is an alternative to `get_token` to enable certain scenarios that require additional properties
@@ -127,7 +131,9 @@ async def get_token_info(self, *scopes: str, options: Optional[TokenRequestOptio
127131
message=f"Fail to get token, please run Connect-AzAccount --ClaimsChallenge {claims_value}"
128132
)
129133

130-
if sys.platform.startswith("win") and not isinstance(asyncio.get_event_loop(), asyncio.ProactorEventLoop):
134+
if sys.platform.startswith("win") and not isinstance(
135+
asyncio.get_event_loop(), asyncio.ProactorEventLoop
136+
):
131137
return _SyncCredential().get_token_info(*scopes, options=options)
132138
return await self._get_token_base(*scopes, options=options)
133139

@@ -167,7 +173,9 @@ async def run_command_line(command_line: List[str], timeout: int) -> str:
167173
try:
168174
proc = await start_process(command_line)
169175
stdout, stderr = await asyncio.wait_for(proc.communicate(), 10)
170-
if sys.platform.startswith("win") and (b"' is not recognized" in stderr or proc.returncode == 9009):
176+
if sys.platform.startswith("win") and (
177+
b"' is not recognized" in stderr or proc.returncode == 9009
178+
):
171179
# pwsh.exe isn't on the path; try powershell.exe
172180
command_line[-1] = command_line[-1].replace("pwsh", "powershell", 1)
173181
proc = await start_process(command_line)
@@ -185,7 +193,9 @@ async def run_command_line(command_line: List[str], timeout: int) -> str:
185193
error = CredentialUnavailableError(
186194
message='Failed to execute "{}".\n'
187195
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
188-
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.".format(command_line[0])
196+
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.".format(
197+
command_line[0]
198+
)
189199
)
190200
raise error from ex
191201

0 commit comments

Comments
 (0)