tmt icon indicating copy to clipboard operation
tmt copied to clipboard

pre-commit fmf subpath

Open LecrisUT opened this issue 2 years ago • 13 comments
trafficstars

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

LecrisUT avatar Apr 18 '23 14:04 LecrisUT

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

lukaszachy avatar Apr 18 '23 16:04 lukaszachy

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

lukaszachy avatar Apr 18 '23 16:04 lukaszachy

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?

LecrisUT avatar Apr 18 '23 16:04 LecrisUT

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 .

lukaszachy avatar Apr 18 '23 19:04 lukaszachy

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.

LecrisUT avatar Apr 19 '23 07:04 LecrisUT

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

lukaszachy avatar Apr 19 '23 07:04 lukaszachy

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 avatar Apr 19 '23 07:04 LecrisUT

@lukaszachy Let me know if you can confirm this behaviour

LecrisUT avatar Apr 19 '23 08:04 LecrisUT

Confirmed. Please create the issue for lint

lukaszachy avatar Apr 19 '23 08:04 lukaszachy

Ok, separated in #2006

LecrisUT avatar Apr 19 '23 09:04 LecrisUT

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)

LecrisUT avatar Apr 19 '23 09:04 LecrisUT

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.

lukaszachy avatar Apr 19 '23 16:04 lukaszachy

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.

LecrisUT avatar Apr 19 '23 16:04 LecrisUT