A tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported. The goal is to provide a stable and consistent interface abstraction to Ansible.
The mypy linter currently complains about the dump_artifact() method once typing is added to it. This is because there exists a code branch where hexdigest() could be called on a variable with a None type. The code logic was also overly complex. This is simplified by reorganizing it slightly, and not allowing for the filename parameter to be None (we never pass it that value except in a unit test). Some unit tests are added to make sure it functions as expected.
I think we could simplify this code even further:
not convinced the comparison of file contents to the new contents is even necessary... we could just always overwrite.
returning the final filename seems silly since that data is known to the caller (we could instead return a bool to indicate if the file was written)
I didn't make those other changes, though, since I wanted to leave the current functionality intact until a later date, and I only want to fix the linting issue in this PR.
The
mypy
linter currently complains about thedump_artifact()
method once typing is added to it. This is because there exists a code branch wherehexdigest()
could be called on a variable with aNone
type. The code logic was also overly complex. This is simplified by reorganizing it slightly, and not allowing for thefilename
parameter to beNone
(we never pass it that value except in a unit test). Some unit tests are added to make sure it functions as expected.I think we could simplify this code even further:
I didn't make those other changes, though, since I wanted to leave the current functionality intact until a later date, and I only want to fix the linting issue in this PR.