Skip to content

fix(rdfgen): binary-safe output with -o#2894

Merged
kevinschaper merged 4 commits into
linkml:mainfrom
lapkinvladimir:feat/rdf-binary-outputs
Sep 26, 2025
Merged

fix(rdfgen): binary-safe output with -o#2894
kevinschaper merged 4 commits into
linkml:mainfrom
lapkinvladimir:feat/rdf-binary-outputs

Conversation

@lapkinvladimir

Copy link
Copy Markdown
Contributor

Binary RDF serializers (e.g., Jelly) could raise a UnicodeDecodeError when writing to stdout.

With -o/--output, rdfgen now lets RDFLib write directly to the file (Graph.serialize with destination).
Binary serializers write to the file, leaving stdout empty.

Behaviour without -o is unchanged.

Tests:
Unit: mock Graph.serialize; verify file writing, empty stdout, and ttl still maps to turtle.
Integration: run with Jelly if available; check empty stdout and binary file output.

@codecov

codecov Bot commented Sep 5, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.66%. Comparing base (e3f9ab9) to head (dc2df97).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2894      +/-   ##
==========================================
+ Coverage   80.16%   83.66%   +3.50%     
==========================================
  Files         131      131              
  Lines       15159    15165       +6     
  Branches     3111     3111              
==========================================
+ Hits        12152    12688     +536     
+ Misses       2363     1797     -566     
- Partials      644      680      +36     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ostrzyciel Ostrzyciel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Makes sense to me and it works.

It's a bit of a hack, but I can't see how to make this better with how currently these methods are laid out. Maybe this could use a small refactor? Easiest way to clean it up would be to return bytes instead of str. But that's beyond the scope of this PR, I think.

Comment thread linkml/generators/rdfgen.py Outdated
Comment thread tests/test_generators/rdf/test_rdfgen_binary.py
Comment thread tests/test_generators/rdf/test_rdfgen_binary_integration.py
@lapkinvladimir

Copy link
Copy Markdown
Contributor Author

Several tests failed due to network errors, as I noticed.
This looks unrelated to my changes, so as I understand, it just needs to be rerun and everything should pass.

@Silvanoc

Copy link
Copy Markdown
Contributor

Several tests failed due to network errors, as I noticed. This looks unrelated to my changes, so as I understand, it just needs to be rerun and everything should pass.

That's right. But please take into account that it's probably some throttling pulling some resources. So retrying too many and too quickly might end up with the same result. Just be patient and retry after some time, not straightaway.

@Silvanoc

Copy link
Copy Markdown
Contributor

Makes sense to me and it works.

It's a bit of a hack, but I can't see how to make this better with how currently these methods are laid out. Maybe this could use a small refactor? Easiest way to clean it up would be to return bytes instead of str. But that's beyond the scope of this PR, I think.

I would also go for small-scoped PRs adding improvements/clean-ups/optimizations on a separate PR.
Discussions about clean-ups/improvements/optimizations on changing external interfaces (refactoring in general) are frequently more code-focused and in some cases don't require any expertise about the functionality, but rather about the Python.
Whereas PRs adding/changing functionality typically require people with more expertise about the functionality (e.g. RDF in this case).

@Silvanoc Silvanoc added bug Something that should work but isn't, with an example and a test case. generator-rdf community-generated labels Sep 26, 2025
@kevinschaper kevinschaper merged commit c8e8de5 into linkml:main Sep 26, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something that should work but isn't, with an example and a test case. community-generated generator-rdf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants