-
Notifications
You must be signed in to change notification settings - Fork 186
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
Object wrappers for OBS XML #1349
Conversation
Hi, What's going on:
@lethliel @marcus-h @adrianschroeter @dirkmueller What do you think? |
Sounds like a good idea.
How are the wrappers generated? Are there wrappers for XML documents not used by osc as well? |
I have couple python scripts doing that. Extremely ugly code at the moment, but I'm planning to include it in this pull request once I clean it up.
Not yet, because I wanted to start with the document used by osc. |
From the viewpoint of a developer, who needs to handle the XML directly (either to prepare a request or process a response), I certainly would consider this a good idea: Having Python objects means that the IDE can provide helpful information, which the dev does not need to look up manually. 👍
"Unfortunately", I decided to use lxml for osc-tiny and let the invoking code deal with objects generated by By the way, did you use a tool like "generateDS"? |
osc/obs_api/choices.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be here Enum
's ?
osc/obs_api/xmlmodel/fields.py
Outdated
from .xml import ET | ||
|
||
|
||
class Field(property): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abstract Class?
I think we talked about it on OSC23 :D good thing. In the worst case, I modernize my plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this! This new API would make py-obs more or less completely obsolete (also, the API is more or less the same 😉), except for the asyncio
support, but I could live without that.
I was looking for existing tools but I missed this one. |
I think @gyr is the better person to ask but in any case here are my two cents: I think the big advantage is that if we are using auto-generated code changes in the XML will now cause compile-time/linter-time issues which would cause us to see breakage before it happens rather than during runtime when the XML is being parsed. For sure you can make the XML handling code robust enough to consider that the schema has changed but it still doesn't tell you that something is wrong before it is executed. I am overall for this change. The recursive imports are worrying me a bit but I believe that this is a WIP PR and as such this can be addressed if required at a later point. From my side please go forward with this! Maybe at some point, we can go all the way to protobuf and gRPC to not maintain our own scripting for generating the code for this. |
Hello @dmach! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2024-02-21 08:47:16 UTC |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1349 +/- ##
==========================================
- Coverage 31.51% 31.43% -0.09%
==========================================
Files 51 71 +20
Lines 17938 18465 +527
==========================================
+ Hits 5653 5804 +151
- Misses 12285 12661 +376 ☔ View full report in Codecov by Sentry. |
import types | ||
import typing |
Check notice
Code scanning / CodeQL
Module is imported with 'import' and 'import from' Note
|
||
@classmethod | ||
def xml_request(cls, method: str, apiurl: str, path: List[str], query: Optional[dict] = None, data: Optional[str] = None) -> urllib3.response.HTTPResponse: | ||
from ..connection import http_request |
Check notice
Code scanning / CodeQL
Cyclic import Note
osc.connection
@classmethod | ||
def xml_request(cls, method: str, apiurl: str, path: List[str], query: Optional[dict] = None, data: Optional[str] = None) -> urllib3.response.HTTPResponse: | ||
from ..connection import http_request | ||
from ..core import makeurl |
Check notice
Code scanning / CodeQL
Cyclic import Note
osc.core
|
||
IMPORTANT: This method is always interactive. | ||
""" | ||
from ..core import run_editor |
Check notice
Code scanning / CodeQL
Cyclic import Note
osc.core
3a6af40
to
8361cf9
Compare
So, this is the second (public) iteration of the object wrapper for OBS XML. |
edited_obj = self.__class__.from_file(f.name) | ||
f.seek(0) | ||
edited_data = f.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we truncate here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because we truncate on write()
while this performs read()
No description provided.