ImperialCollegeLondon / R2T2

Research References Tracking Tool
MIT License
14 stars 155 forks source link

Static tracker behavior with multiple targets #54

Open billbrod opened 4 years ago

billbrod commented 4 years ago

If you pass multiple targets to the static tracker, it will only give the outputs from the first file, silently ignoring the rest. This is true for static by itself, and also with the --docstring flag. It should probably either parse all the files or raise an Exception if it gets multiple files?

Minimal working example:

file example1.py:

from r2t2 import add_reference

@add_reference(
    short_purpose="Roasted chicken recipe", reference="Great British Roasts, 2019"
)
def sample_function_1():
    pass

file example2.py:

from r2t2 import add_reference

@add_reference(
    short_purpose="Roasted beef recipe", reference="Great British Roasts, 2019"
)
def sample_function_2():
    pass

Run:

python -m r2t2 --static example1.py example2.py 

Output:

Referenced in: sample_function_1
Source file: example1.py
Line: 7
    [1] Roasted chicken recipe - Great British Roasts, 2019

Expected output:

Referenced in: sample_function_1
Source file: example1.py
Line: 7
    [1] Roasted chicken recipe - Great British Roasts, 2019

Referenced in: sample_function_2
Source file: example2.py
Line: 7
    [1] Roasted beef recipe - Great British Roasts, 2019
de-code commented 4 years ago

I think that is because args is the last argument, which would get passed to the script.

I think I would suggest two things:

Putting both together, commands would look like:

$python -m r2t2 static example1.py example2.py

$python -m r2t2 run example1.py -- arg1 arg2

(static may not be the best sub command name)

billbrod commented 4 years ago

I like the idea of sub-commands, from a user's perspective that's much clearer (and I think static is fine).

I also think using -- to clearly separate args from targets makes sense; while putting this issue together, I completely missed the fact that the scripts also accept args and that was where the issue was coming from.

The run sub-command would only accept one target, right? It should raise an Exception (or a warning or something) if multiple targets are passed?

de-code commented 4 years ago

The run sub-command would only accept one target, right? It should raise an Exception (or a warning or something) if multiple targets are passed?

Yes, at the moment it accepts only one argument, and it cannot be a directory I believe (unlike for the static checker). That differentiation would also be more clear with sub commands.

de-code commented 4 years ago

If the format argument is used, then it will default to output to the directory of the passed in script. Not quite sure what to do if multiple files are passed in. It should probably write to each of the target directories. But that requires a change to the output handlers.