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

Autodetect parse() format #1046

Merged
merged 8 commits into from
Jun 1, 2020
Merged

Autodetect parse() format #1046

merged 8 commits into from
Jun 1, 2020

Conversation

dwinston
Copy link
Contributor

@dwinston dwinston commented May 11, 2020

Addresses #981

  • Use rdflib.util.guess_format to guess and try to apply format based on file extension
  • Log warning if assumed XML(not guessed from file extension) and cannot parse
  • Add tests

Close #981

rdflib/graph.py Outdated Show resolved Hide resolved
rdflib/graph.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented May 12, 2020

Coverage Status

Coverage increased (+0.03%) to 75.793% when pulling b5fa8ec on dwinston:autodetect-parse-format into 037ea51 on RDFLib:master.

@dwinston
Copy link
Contributor Author

dwinston commented May 18, 2020

@tgbugs what do you think? I hope I've resolved your concerns.

# "expicitly specify one with the format argument." % source)
format = "application/rdf+xml"
try:
format = rdflib.util.guess_format(source.file.name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Under what circumstances are you seeing these errors? I'm guessing when source.file.name is None for the TypeError and probably ... when not hasattr(source, 'file')? If that is the case then an explicit test (if statement) for the presence and non-Noneness of the values would be much clearer here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tgbugs I've adopted your suggestion for more of a look-before-you-leap approach with an explicit if-statement guard, ensuring that source.file.name is an accessible path and is a string before attempting a call to guess_format.

@nicholascar
Copy link
Member

@dwinston please merge in master branch and address conflicts since a whole host of changes were recently merged in to remove Python 2 code. This will trigger a re-checking of the code by Travis. Then we can redress the comments from @tgbugs

@dwinston
Copy link
Contributor Author

@dwinston please merge in master branch and address conflicts since a whole host of changes were recently merged in to remove Python 2 code. This will trigger a re-checking of the code by Travis. Then we can redress the comments from @tgbugs

Sure, will do.

@dwinston
Copy link
Contributor Author

@nicholascar merged in master, and I hope I addressed the comments from @tgbugs with my last commit. Also, I thought I'd note here that the more recent PR #1064 is an alternative solution to the same underlying issue.

This was referenced May 27, 2020
@nicholascar nicholascar merged commit db4b66f into RDFLib:master Jun 1, 2020
This was referenced Jun 1, 2020
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.

Auto-detect RDF type from file extension in parse()
4 participants