Skip to content

Commit

Permalink
Update formatting and typing
Browse files Browse the repository at this point in the history
I ran `make` and it fixed/complained about a few things, so I addressed them.
  • Loading branch information
Raymond Butcher committed Dec 7, 2021
1 parent 3d2fe76 commit 64edbaf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
18 changes: 13 additions & 5 deletions pretf.aws/pretf/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def _profile_creds_definitely_supported_by_terraform(creds: Any) -> bool:

@locked
def export_environment_variables(
session: Optional[Session] = None, region_name: Optional[str] = None, **kwargs: dict
session: Optional[Session] = None,
region_name: Optional[str] = None,
**kwargs: Any,
) -> None:
"""
Exports AWS credentials as environment variables.
Expand Down Expand Up @@ -214,7 +216,10 @@ def export_environment_variables(

@lru_cache()
@locked
def get_account_id(session: Optional[Session] = None, **kwargs: dict) -> str:
def get_account_id(
session: Optional[Session] = None,
**kwargs: Any,
) -> str:
if session is None:
session = get_session(**kwargs)
sts_client = session.client("sts")
Expand All @@ -223,19 +228,22 @@ def get_account_id(session: Optional[Session] = None, **kwargs: dict) -> str:


@locked
def get_frozen_credentials(session: Optional[Session] = None, **kwargs: dict) -> Any:
def get_frozen_credentials(
session: Optional[Session] = None,
**kwargs: Any,
) -> Any:
if session is None:
session = get_session(**kwargs)
return session.get_credentials().get_frozen_credentials()


@lru_cache()
def get_session(**kwargs: dict) -> Session:
def get_session(**kwargs: Any) -> Session:
return Session(**kwargs)


@locked
def provider_aws(**body: dict) -> Block:
def provider_aws(**body: Any) -> Block:
"""
Returns an AWS provider block. If provided, the `profile` option
may be replaced with temporary credentials for that profile.
Expand Down
5 changes: 4 additions & 1 deletion pretf/pretf/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from contextlib import contextmanager
from fnmatch import fnmatch
from importlib.abc import Loader
from importlib.machinery import ModuleSpec
from importlib.util import module_from_spec, spec_from_file_location
from io import StringIO
from pathlib import Path, PurePath
Expand Down Expand Up @@ -76,7 +77,8 @@ def _execute(

if returncode != 0:
raise CalledProcessError(
returncode=returncode, cmd=" ".join(shlex.quote(arg) for arg in args),
returncode=returncode,
cmd=" ".join(shlex.quote(arg) for arg in args),
)

return CompletedProcess(args=args, returncode=returncode)
Expand Down Expand Up @@ -204,6 +206,7 @@ def import_file(path: Union[PurePath, str]) -> Generator[ModuleType, None, None]
try:
name = os.path.basename(path).split(".")[0]
spec = spec_from_file_location(name, str(path))
assert isinstance(spec, ModuleSpec)
module = module_from_spec(spec)
assert isinstance(spec.loader, Loader)
loader: Loader = spec.loader
Expand Down
32 changes: 25 additions & 7 deletions pretf/pretf/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
from .util import import_file, is_verbose


def clean_files(paths: Sequence[Path], verbose: Optional[bool] = None) -> None:
def clean_files(
paths: Sequence[Path],
verbose: Optional[bool] = None,
) -> None:
"""
Deletes the specified files. Intended for use after `create_files()`.
Use `delete_files()` if wildcards are required.
Expand Down Expand Up @@ -98,7 +101,8 @@ def create_files(


def custom(
path: Union[PurePath, str], context: Optional[dict] = None
path: Union[PurePath, str],
context: Optional[dict] = None,
) -> CompletedProcess:
"""
Calls the pretf_workflow() function from the specified Python file.
Expand All @@ -123,7 +127,9 @@ def custom(


def default(
clean: bool = True, created: list = [], verbose: Optional[bool] = None
clean: bool = True,
created: list = [],
verbose: Optional[bool] = None,
) -> CompletedProcess:
"""
This is the default Pretf workflow. This is automatically used when there
Expand Down Expand Up @@ -196,7 +202,8 @@ def delete_files(


def delete_links(
cwd: Optional[Union[Path, str]] = None, verbose: Optional[bool] = None
cwd: Optional[Union[Path, str]] = None,
verbose: Optional[bool] = None,
) -> List[Path]:
"""
Deletes symlinks from the current directory.
Expand Down Expand Up @@ -269,12 +276,18 @@ def execute_terraform(

# This is a valid executable, run it.
return util.execute(
file=terraform_path, args=args, cwd=cwd, capture=capture, verbose=verbose
file=terraform_path,
args=args,
cwd=cwd,
env=env,
capture=capture,
verbose=verbose,
)

log.bad("terraform: command not found")
raise CalledProcessError(
returncode=1, cmd=" ".join(shlex.quote(arg) for arg in args),
returncode=1,
cmd=" ".join(shlex.quote(arg) for arg in args),
)


Expand Down Expand Up @@ -457,7 +470,12 @@ def link_module(
if source.startswith(".") or source.startswith("/"):

# Modules already on the filesystem can be used directly.
paths.extend(util.find_paths(path_patterns=["*"], cwd=source,))
paths.extend(
util.find_paths(
path_patterns=["*"],
cwd=source,
)
)

else:

Expand Down

0 comments on commit 64edbaf

Please sign in to comment.