-
Notifications
You must be signed in to change notification settings - Fork 122
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
Adds new function for empty env files #3204
base: main
Are you sure you want to change the base?
Conversation
tmt/base.py
Outdated
|
||
env_file = self.plan_environment_file | ||
|
||
if (self.my_run and env_file.exists() and env_file.stat().st_size == 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this would work: by design, lint_*
callbacks are called not in runtime, tmt run ...
, but e.g. before committing changes, via tmt * lint
. Therefore self.my_run
should always be unset when linters run.
I think there is also a misunderstanding in your way: plan_environment_file
is a per-plan file, provided by tmt to plans and tests, with path exposed via TMT_PLAN_ENVIRONMENT_FILE
envvar, and as such does exist only in the context of tmt run
. Which makes it non-lintable entity.
If you wanted to check whether files referenced by plan's environment-file
, https://tmt.readthedocs.io/en/stable/spec/plans.html#environment-file, you'd need to check self.node
, self.node.get("environment-file") or []
should give you the list of files referenced by the plan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@happz thanks for the feedback I am still a newbie here, just a couple of comments. The idea of this patch is to cover the issue #2872 which mentions to report the fail in the tmt lint
so that should be the idea right?, or maybe you want to rethink the intention of the issue. Regarding the plan environment file I changed the code according to your review, I hope now it's appropiate
cc @psss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the idea matches the issue, you just focused on the wrong "environment file", that's all :)
6819c26
to
e1db5ce
Compare
tmt/base.py
Outdated
""" P001: env files are not empty """ | ||
|
||
env_files = self.node.get("environment-file") or [] | ||
if len(env_files) > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if env_files:
is the Python way of checking list emptiness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks !
tmt/base.py
Outdated
if len(env_files) > 0: | ||
for env_file in env_files: | ||
path = os.path.normpath(env_file) | ||
size = os.path.getsize(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use pathlib
instead of os.path
, please. It will eventually make the condition simpler as well:
for _env_file in env_files:
env_file = Path(env_file).resolve()
if not env_file.exists() or not env_file.stat().st_size:
..
Catches both cases when the file does not exists - deserves its own message - and the file being empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks !
e1db5ce
to
ef711a8
Compare
New function that raises a failure if the size of the environment file, if this one exists, is zero. Signed-off-by: mcasquer <[email protected]>
ef711a8
to
c2b295a
Compare
New function that raises a failure if the size of
the environment file, if this one exists, is zero.
Pull Request Checklist