Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Static tracker behavior with multiple targets #54

Open
billbrod opened this issue Sep 2, 2020 · 4 comments
Open

Static tracker behavior with multiple targets #54

billbrod opened this issue Sep 2, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@billbrod
Copy link
Contributor

billbrod commented Sep 2, 2020

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
@dalonsoa dalonsoa added the bug Something isn't working label Sep 3, 2020
@de-code
Copy link
Contributor

de-code commented Sep 3, 2020

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

I think I would suggest two things:

  • Change the syntax to using -- before passing in args. That way there is a clear separation of the two. It could also warn that args are not supported for the static parser.
  • Use sub-commands instead of the --static flag. Because really they are doing two different 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
Copy link
Contributor Author

billbrod commented Sep 3, 2020

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
Copy link
Contributor

de-code commented Sep 3, 2020

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
Copy link
Contributor

de-code commented Sep 3, 2020

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.

This was referenced Sep 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants