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

Add package to FunctionReference #69

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Add package to FunctionReference #69

wants to merge 3 commits into from

Conversation

dalonsoa
Copy link
Collaborator

@dalonsoa dalonsoa commented Sep 3, 2020

Register the package name when adding a reference, important to later find out what source file the reference information should be look into.

Works with the runtime tracker but breaks the docstring parser 😟 . Working on it.

@dalonsoa
Copy link
Collaborator Author

dalonsoa commented Sep 3, 2020

@de-code , I've added a new field to the FunctionReference namedtuple, package. It has implications for the docstring parser. I can try to solve it myself, but I might need some guidance form you about what needs to be modify. Any ssugestion?

@de-code
Copy link
Contributor

de-code commented Sep 3, 2020

It is currently failing in the static_parser where I have only added exception handling. The docstring_reference_parser is currently parsing the file separately (should be refactored to share more common functionality).

I guess the challenge for both is the same though, you want to determine the package based on the filename. I am not sure whether Python has helper function. With __init__.py files, one could try to determine based on that. Or you could just use the directory name and replace / with .. That might be good enough for your use-case? (Why is the package important?)

@dalonsoa
Copy link
Collaborator Author

dalonsoa commented Sep 3, 2020

When tracking the references at runtime, different packages (numpy, scipy, etc.) will have their own references. R2T2 needs a why to distinguish what references correspond to each of them in order to retrieve the full reference information form the correspoinding source file.

Using the path is an option but, at least for the runtime tracker, it might be unreliable (specially when there is a direct way of getting that information). For the parser, however, we might have no other option than to use the path, as you suggest.

@dalonsoa dalonsoa marked this pull request as ready for review September 3, 2020 18:34
@dalonsoa
Copy link
Collaborator Author

dalonsoa commented Sep 3, 2020

@de-code , I've updated this setting the package attribute to an empty string given that for the static parser, it does not make much sense to specify any package.

Now, we still need to speficy a reference source so, when finding a reference in the docstrings, for example, it is able to retrieve the full reference from somewhere. The simplest way would be the via the cli that you are currently cracking, but you might have a better suggestion.

def test_should_parse_docstring_reference(self, temp_dir: Path):
file_path = temp_dir / "test.py"
file_path.write_text(
"\n".join(["def some_function():" ' """', " " + DOI_1, ' """'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a minor "rant" at using a code formatter. Like here it is loosing the logical formatting that is multiple lines, of course it could have used a multi-line string. It's good to be consistent though. (I just personally don't think it necessarily improves readability)


if identifier in BIBLIOGRAPHY and ref in BIBLIOGRAPHY[identifier].references:
return wrapped(*args, **kwargs)

if identifier not in BIBLIOGRAPHY:
BIBLIOGRAPHY[identifier] = FunctionReference(
wrapped.__name__, line, source, [], []
wrapped.__name__, line, source, package, [], []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: with that many arguments it might be good to use keyword arguments?

line=docstring.lineno or 0,
name=docstring.name or '',
package=docstring.package or "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: perhaps we should allow package to be None? (see #67 (comment))
To be honest, the only reason why I added those or "" was because it wasn't marked as optional in FunctionReference and I just wanted to get passed the linter.

@de-code
Copy link
Contributor

de-code commented Sep 3, 2020

@de-code , I've updated this setting the package attribute to an empty string given that for the static parser, it does not make much sense to specify any package.

Yes, it doesn't seem to make sense trying to populate it if it is not going to be used in that scenario.

Now, we still need to speficy a reference source so, when finding a reference in the docstrings, for example, it is able to retrieve the full reference from somewhere. The simplest way would be the via the cli that you are currently cracking, but you might have a better suggestion.

CLI argument sounds good to me. It's simple and explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants