Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
monacofj opened this issue Mar 25, 2024 · 1 comment
Open

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

monacofj opened this issue Mar 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@monacofj
Copy link
Contributor

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 carmenbianca added the bug Something isn't working label Apr 8, 2024
@carmenbianca
Copy link
Member

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:

  • Relative from project root
  • Relative from CWD

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

Thanks for reporting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants