fsfe / reuse-tool

reuse is a tool for compliance with the REUSE recommendations.
https://reuse.software
382 stars 146 forks source link

Wrong project root if invoked from a sub-directory #936

Open monacofj opened 5 months ago

monacofj commented 5 months ago

Would anyone confirm or provide hints on the following issue.

Suppose that the project directory has the following structure:

 proj
 |___.reuse
      |____ dep5
      |____ templates
           |_____ proj.jinja2
 |___ file1.py
 |___ subdir
      |_____ file2.py

From within the project root directory, we want to annotate file1.py using the custom template proj.jinja2.

$ cd <path>/proj
$ reuse annotate --copyright=John --license=CC0-1.0 --template=proj file1.py
Successfully changed header of file1.py

So far so good.

However, suppose we also want to annotate file2 within subdir.

$ cd <path>/proj
$ cd subdir
$ reuse annotate --copyright=John --license=CC0-1.0 --template=proj file2.py
reuse annotate: error: template ../proj could not be found

To have it work, he have to move up to the root directory

$ cd <path>proj
$ reuse annotate --copyright=John --license=CC0-1.0 --template=proj subdir/file2.py
Successfully changed header of file2.py

Intriguingly, I have another project which was cloned from a remote Git repository where the problem does not occur, which led me to wonder if the issue had something to do with proj not being a git repo. However, I then recreated proj as a Git repo, cloned it and repeated the tests only to check that the problem persists.

As a note, I performed some debugging in reuse-tool source and could see that for my working project, the program correctly detects the project root dir (.. if I invoke reuse from a first-level subdir) , while for proj, the program identifies the project root as the absolute path <path>proj/subidr. I could not dig deeper in the problem, though.

carmenbianca commented 5 months ago

Oof… Using reuse from subdirectories is one of those things that requires quite a bit of plumbing, but doesn't have nearly enough in the way of tests. It's a bit of a mess, especially because there are two types of relative paths:

These are normally identical, but not always, and the bug here is probably something of that type.

Thanks for reporting.