add terraform-local version when using version flag#84
Conversation
|
|
||
| ## Change Log | ||
|
|
||
| * v0.24.0: Add support to return `terraform-local` version when calling `tflocal -version` and fix AWS provider detection |
There was a problem hiding this comment.
this doesn't sound clear... lmk if you find something better, I'd happily take any suggestion 😅
cloutierMat
left a comment
There was a problem hiding this comment.
Awesome! Thanks for taking this initiative to solve this pain point and your diligence to not break users possible flows in the process. more information is always better!
I only left a question regarding the test. It seems that there might be an extra copy paste comment, unless I am missing something 😄
|
|
||
| ## Change Log | ||
|
|
||
| * v0.24.0: Add support to return `terraform-local` version when calling `tflocal -version` and fix AWS provider detection |
There was a problem hiding this comment.
Thanks for adding the previous pr changelog as well! 🙏
| def get_tf_local_version(): | ||
| from importlib.metadata import version | ||
| return version("terraform-local") |
There was a problem hiding this comment.
I agree that this seems safe. It will find the version that is currently available in the venv, so we won't have issues with multiple install of tflocal.
I have tested install with pipx, with pip in a venv and my hybrid dev env, and all seem to give proper result. 👍
There was a problem hiding this comment.
awesome, thanks a lot for taking the time to test extra scenarios 🙏
| except Exception: | ||
| pass |
There was a problem hiding this comment.
🎉 Hurray for extra safety here! 🚀
There was a problem hiding this comment.
thanks! made me think I'll update those to use contextlib.suppress, but this will be for a follow up 👌
| return subprocess.check_output(cmd, **kwargs) | ||
|
|
||
| with tempfile.TemporaryDirectory(delete=True) as temp_dir: | ||
| # we need the `terraform init` command to create a lock file, so it cannot be a `DRY_RUN` |
There was a problem hiding this comment.
Is that a forgotten copy paste? I fail to see where the init or the dry run would impact the version command 🤔
There was a problem hiding this comment.
it is indeed, my bad 😅 will update
This PR now returns the version of
terraform-localwhen runningtflocal -v(or--version,-version, all accepted by Terraform).This was sometimes an issue when users had a global installation of
tflocaland one in a virtual environment, and only updated one of them. It was hard to know which version you'd be calling/using.We are printing to
stderrto avoid breaking existing user setup maybe relying ontflocal --versionreturning the underlying Terraform version unmodified.It is not trivial to get the version without directly parsing the
setup.cfgfile, or changing the setup itself to create a__version__variable somewhere in the code to be imported.Relying on
from importlib.metadata import versionseems safe, but I'm not sure if it could import a different version than the one that is being called right now... 🤔 I doubt itThis seems to be the preferred way: https://packaging.python.org/en/latest/discussions/versioning/#runtime-version-access