8000 Move prerun functions into Runtime class by ssbarnea · Pull Request #16 · ansible/ansible-compat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move prerun functions into Runtime class #16

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 8000

Merged
merged 2 commits into from
Jul 1, 2021
Merged

Move prerun functions into Runtime class #16

merged 2 commits into from
Jul 1, 2021

Conversation

ssbarnea
Copy link
Member
@ssbarnea ssbarnea commented Jul 1, 2021

No description provided.

@ssbarnea ssbarnea requested a review from webknjaz as a code owner July 1, 2021 10:11
@ssbarnea ssbarnea added the enhancement New feature or request label Jul 1, 2021
@ssbarnea ssbarnea force-pushed the fix/api branch 2 times, most recently from 5b7ce97 to fc913b5 Compare July 1, 2021 10:44
Fixed bug found while testing molecule adoption of ansible-compat,
mostly related to testing.
@ssbarnea ssbarnea merged commit ca3b985 into main Jul 1, 2021
@ssbarnea ssbarnea deleted the fix/api branch July 1, 2021 14:18
def __init__(
self,
config_dump: Optional[str] = None,
data: Optional[Dict[str, object]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why object and not Any?

def __init__(self, config_dump: Optional[str] = None) -> None:
def __init__(
self,
config_dump: Optional[str] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple ways of initializing the struct in the same initializer looks weird and mixes up multiple unrelated abstractions. It's best to do such things in custom classmethod initializers.

Also, I'd avoid any I/O in the default initializer for a similar reason. The main one should just accept the data and assign it internally.

stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if run.returncode != 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd not use this C-style obligatory rc check idiom. It's unpythonic and error-prone because it adds extra cognitive load on the users who have to always remember to do this check.
It's better to have check=True because this way (1) it forces you to do try/except and you can't just forget to handle an error + (2) you could explicitly chain the exception cause with raise X from Y which greatly improves the DX, specifically the respectability of tracebacks.

Comment on lines +146 to +147
"--roles-path",
f"{self.cache_dir}/roles",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually best to couple options and their values on the same line because otherwise, they look standalone which adds more cognitive complexity for the reader to figure out which ones are related and separate those that aren't.


if not offline:
self.install_requirements("requirements.yml")
for req in pathlib.Path(".").glob("molecule/*/requirements.yml"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's an abstraction leak here: compat shouldn't "know" about molecule or lint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0