helpers icon indicating copy to clipboard operation
helpers copied to clipboard

Assert if Linter is not run from repo root

Open sonniki opened this issue 9 months ago • 2 comments

Currently if Linter is run not from the repo root, it will fail because it will compose an incorrect path to the env file and won't be able to find it. E.g. running from docs/:

Couldn't find env file: /data/sonyan/src/helpers1/docs/devops/env/default.env

We should put an assertion in the code to make it clearer for the user that the error is because Linter is run from the wrong directory and they should just run from the repo root to fix it.

sonniki avatar Mar 10 '25 10:03 sonniki

Makes sense.

The only thing is that sometimes I run from the root of cmamp and sometimes from the root of helpers and they both work (although probably pick a different file but it doesn't make a difference).

In any case I'm ok to force running from the top of the outermost repo.

FYI @heanhsok

gpsaggese avatar Mar 11 '25 22:03 gpsaggese

The only thing is that sometimes I run from the root of cmamp and sometimes from the root of helpers and they both work (although probably pick a different file but it doesn't make a difference).

Yes, correct, Linter will run fine if it is run from the root of the repo one is developing in, be it helpers, cmamp, or any other repo.

sonniki avatar Mar 12 '25 09:03 sonniki

@Peeyush4 helpful functions regarding checking for repo root should be found in helpers/hgit.py

sonniki avatar Apr 09 '25 20:04 sonniki

Maybe the fix is

create a function like

def is_cwd_git_repo():
   return os.path.exists(".git")

and then a dassert on that

The invariant is that in any repo (super and sub) there is a git file or dir.

gpsaggese avatar Apr 10 '25 00:04 gpsaggese

Done

sonniki avatar Apr 14 '25 09:04 sonniki