teemtee / tmt

Test Management Tool
MIT License
80 stars 122 forks source link

pre-commit fmf subpath #2004

Closed LecrisUT closed 2 months ago

LecrisUT commented 1 year ago

Allow to run pre-commit with fmf root in a subpath

lukaszachy commented 1 year ago

This means we need a way to propagate --root for tmt commands and for path= argument used in git ls-files

lukaszachy commented 1 year ago

Might be easy enough. Docs to read about hooks: https://pre-commit.com/#new-hooks

LecrisUT commented 1 year ago

Indeed, if it was such a simple fix, I would have made a PR with the feature. If we can create a simple wrapper I think it's trivial, but otherwise I don't see how to extract a specific args in the .pre-commit-hooks.yaml format. Do you think it worth making a small wrapper file for that?

lukaszachy commented 1 year ago

I'm afraid we will have to. If tmt could accept args everywhere it would be easy but it doesn't (we need to add it as the first option).... The 'entry point' with current 'bash -c' is too hackish to my liking anyway, dedicated scripts might be easier to fix/extend .

LecrisUT commented 1 year ago

I did a bit of quick testing, and there is a more crucial issue that tmt --root path/to/fmf_root lint fails:

fail No tree found in repo 'None', missing an '.fmf' directory?

Running the tmt --root ... run works though so this is a bug in lint.

lukaszachy commented 1 year ago

Which tmt version is that?

$ tmt --version
tmt version: 1.22.0 (ea71a188)

$ tree -a
.
└── a
    ├── .fmf
    │   └── version
    └── t.fmf

3 directories, 2 files

$ tmt t lint

No metadata found in the '.' directory. Use 'tmt init' to get started.

$ tmt --root a t lint
/t
pass test script must be defined
pass directory path must be absolute
pass directory path must exist
warn summary is very useful for quick inspection
pass correct attributes are used
LecrisUT commented 1 year ago

I have tried with both 1.21 and 1.22. Try with this minimal example plan and with a git repo:

summary:
  simple example
discover:
  how: fmf
  filter: "tag: something"
execute:
  how: tmt
LecrisUT commented 1 year ago

@lukaszachy Let me know if you can confirm this behaviour

lukaszachy commented 1 year ago

Confirmed. Please create the issue for lint

LecrisUT commented 1 year ago

Ok, separated in #2006

LecrisUT commented 1 year ago

As for the pre-commit, I've tried a hack as:

-   id: tmt
    name: tmt
    entry: tmt
    files: '.*\.fmf$'
    verbose: true
    pass_filenames: true
    language: python
    language_version: python3

and

  - repo: https://github.com/LecrisUT/tmt.git
    rev: pre-commit
    hooks:
      - id: tmt
        args:
          - "--root"
          - "test"
          - "lint"
          - "--source"

It sort-of works, but it is not a good solution. We should still maybe make different executable that is not installed outside of a pypi environment (or maybe not even there?). Is it ok if this one is not using click and entry-point for this one?

Also, what do you think about modernizing the build to PEP621 (requires dropping python 3.6 support and rhel8 at least and switching the versioning to git tags)

lukaszachy commented 1 year ago

I'd say rhel-8 support (so python 3.6) is required for now and we will start thinking about being python3.9+ once centos-8 is EOL or rhel-8 moves to AUS

@LecrisUT If you find a way how to create helper script just for the pre-commit usage it would be nice. All I can think of now is to create separate project (e.g. teemtee/precommit) and let it live there.

LecrisUT commented 1 year ago

Yeah, I've managed to make a helper script in #2007 as you can see. So far works ok, just missing tests and this test if failing. Might be something deeply rooted in testing-farm, so I don't know how to deal with it.