Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up try/import checks #62

Merged
merged 1 commit into from
Mar 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/spnego/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,22 @@
TlsSupportedGroup,
)

HAS_ARGCOMPLETE = False
try:
import argcomplete

HAS_ARGCOMPLETE = True
except ImportError: # pragma: nocover
argcomplete = None
pass


yaml: typing.Optional[typing.Any]
HAS_YAML = False
try:
from ruamel import yaml

HAS_YAML = True
except ImportError: # pragma: nocover
yaml = None
pass


def _parse_ntlm_version(
Expand Down Expand Up @@ -700,8 +706,8 @@ def main(args: typing.List[str]) -> None:
else:
token_info = parse_token(b_data, secret=parsed_args.secret, encoding=parsed_args.encoding)

if parsed_args.output_format == "yaml":
y = yaml.YAML() # type: ignore
if parsed_args.output_format == "yaml" and HAS_YAML:
y = yaml.YAML()
y.default_flow_style = False
y.dump(token_info, sys.stdout)
else:
Expand Down Expand Up @@ -755,12 +761,12 @@ def parse_args(args: typing.List[str]) -> argparse.Namespace:
"tokens to generate the session key.",
)

if argcomplete:
if HAS_ARGCOMPLETE:
argcomplete.autocomplete(parser)

parsed_args = parser.parse_args(args)

if parsed_args.output_format == "yaml" and not yaml:
if parsed_args.output_format == "yaml" and not HAS_YAML:
raise ValueError("Cannot output as yaml as ruamel.yaml is not installed.")

return parsed_args
Expand Down