gauge-sh/tach

Move '<root>' module to the bottom/end of modules in tach.yml

emdoyle opened this issue · 5 comments

The implicit root boundary appears in the modules list in tach.yml with the path: <root>

Right now, when this module exists, it is always at the beginning of the modules list (sorted lexicographically). This is not ideal, because as a reader (especially a new user), the meaning of <root> is hard to parse before first seeing the rest of the modules. This is because a reasonable definition of the root boundary is the 'leftover' code - any code which is not covered by another module.

Given this, it is easier to read the explicit modules first, and then see the 'leftovers' at the end of the file. Tach should explicitly sort this module last when writing the project config to yml.

I have just pushed one to fix this arrangement, plz revieew . I havent added description in the PR yet.

Can you give me an example use case of what the tach.yml might look before and after this enhancement

@dhananjaypai08 sure! here is an example. I have removed a lot of extra content so that it is easier to read, but the only real difference is that right now, the <root> module (if it exists) appears first, and it should instead appear last.

modules:
- path: <root>  # root module is first
  depends_on:
  - tach.filesystem
- path: tach.check
  depends_on:
  - <root>
  - tach.errors
  - tach.filesystem
  - tach.parsing
  strict: true
- path: tach.cli
  depends_on:
  - <root>
  - tach.check
  strict: true
...
modules:
- path: tach.check
  depends_on:
  - <root>
  - tach.errors
  - tach.filesystem
  - tach.parsing
  strict: true
- path: tach.cli
  depends_on:
  - <root>
  - tach.check
  strict: true
- path: <root>  # root module should be last
  depends_on:
  - tach.filesystem
...

This is a easy fix by just finding the selected root folder in the config.modules list and then popping it and appending to the same list in the config::dump_project_config_to_yaml. But I don't know why in my case in the tach.yaml there is no -path: <root module> anywhere. I tried it using in different cases(via my own build as well as through the actual released library) and every time the -path: <root> the root is not added in the tach.yaml file

This is a easy fix by just finding the selected root folder in the config.modules list and then popping it and appending to the same list in the config::dump_project_config_to_yaml. But I don't know why in my case in the tach.yaml there is no -path: <root module> anywhere. I tried it using in different cases(via my own build as well as through the actual released library) and every time the -path: <root> the root is not added in the tach.yaml file

That fix should be totally fine! The reason you're not seeing it is because it is a kind of implicit boundary that is only included when necessary. If you have a setup like this:

/
    python/  <-- source root
        mod1/  <-- NOT marked as a module
        mod2/  <-- module

then when mod1 imports from mod2, it will appear as:

- path: <root>
  depends_on:
  - mod2

The '' module will collect all of the dependencies that exist outside of other modules. I'll make a task for myself to add this to the documentation!