-
Notifications
You must be signed in to change notification settings - Fork 17
ft: Instantiate Specfile from strings or file-like objects #458
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
Conversation
Build failed. ❌ pre-commit FAILURE in 1m 56s |
Build succeeded. ✔️ pre-commit SUCCESS in 2m 00s |
Specfile
to Instantiate from string
Thank you for the contribution! |
I tried implementing as described and converted even the path to a fileobject (
and this will fail for objects instantiated from string and open() as well. Not really sure how to handle this. |
Right, that will require doing something similar to what is done in specfile/specfile/spec_parser.py Lines 81 to 90 in 01f6a7c
The |
Build failed. ❌ pre-commit FAILURE in 1m 57s |
The tests are passing now. Currently:
will write new tests for them. |
Build failed. ❌ pre-commit FAILURE in 1m 59s |
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.
Nice, this looks much better.
Build failed. ❌ pre-commit FAILURE in 1m 54s |
Build failed. ❌ pre-commit FAILURE in 1m 55s |
I had a doubt in the def reload(self) -> None:
"""Reloads the spec file content."""
self._lines, self._trailing_newline = self._read_lines(self._file) Why we are not parsing again here ? I think this causes the specfile object to be inconsistent after a reload. |
Build failed. ❌ pre-commit FAILURE in 1m 57s |
By parsing do you mean calling |
yes, I was talking about that. It's clear now |
Specfile
to Instantiate from string
Build failed. ❌ pre-commit FAILURE in 1m 56s |
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.
It's starting to look really good, thanks!
Could you please squash the commits into one (or a couple if you feel it's necessary)?
It would also be nice to check why the source-git tests in packit integration test suite are failing and if it is related to these changes.
Build failed. ❌ pre-commit FAILURE in 1m 58s |
These are the failing tests, I think the last one might have something to do with this PR. I am having trouble squashing commits from my side they seem to be getting duplicated. |
No, all of the failures are related to this PR. I haven't check all of them but they all most likely fail for the same reason - the spec file is replaced with a different file, so the That brings me to another step that will be necessary and that's adding tests covering every new feature and changed behavior, including this one. |
|
Actually, thinking about it, it should rather be done in |
Got it done eventually i was avoiding force push and rewriting the commits. |
Build failed. ❌ pre-commit FAILURE in 1m 59s |
I think the current test cases should be reused, but with different input types, such as a raw string, a file-based input, and a file without a 'name' attribute, it might be overkill though |
specfile/types.py
Outdated
|
||
|
||
try: | ||
from typing import TypedDict | ||
except ImportError: | ||
from typing_extensions import TypedDict | ||
|
||
EncodingArgs = TypedDict("EncodingArgs", {"encoding": str, "errors": str}) |
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.
Hm, black doesn't seem to care, but I think it would make more sense to either move the double newline:
try: | |
from typing import TypedDict | |
except ImportError: | |
from typing_extensions import TypedDict | |
EncodingArgs = TypedDict("EncodingArgs", {"encoding": str, "errors": str}) | |
try: | |
from typing import TypedDict | |
except ImportError: | |
from typing_extensions import TypedDict | |
EncodingArgs = TypedDict("EncodingArgs", {"encoding": str, "errors": str}) |
or remove it:
try: | |
from typing import TypedDict | |
except ImportError: | |
from typing_extensions import TypedDict | |
EncodingArgs = TypedDict("EncodingArgs", {"encoding": str, "errors": str}) | |
try: | |
from typing import TypedDict | |
except ImportError: | |
from typing_extensions import TypedDict | |
EncodingArgs = TypedDict("EncodingArgs", {"encoding": str, "errors": str}) |
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.
This shows as resolved, but nothing has changed.
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 think i forgot to commit that change my bad
# IO doesn't implement getvalue() so tell mypy this is StringIO | ||
# (could also be BytesIO) | ||
sio = cast(StringIO, self._file) | ||
# not a named file, try `getvalue()` | ||
specfile._file = type(sio)(sio.getvalue()) |
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'm not a fan of this, but I don't know how to do this better without actually checking for type.
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.
You could also a type ignore, but I think that's worse.
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 can't think of any alternative method so far.
Build succeeded. ✔️ pre-commit SUCCESS in 2m 00s |
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.
Thank you for the work on this!
Could you please squash the commits and update the release notes?
specfile/specfile.py
Outdated
path: Path to the spec file. | ||
file: File object representing the spec file. | ||
content: String containing the spec file content. |
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.
Can we document the fact that these arguments are mutually exclusive? Probably in the description above, to avoid repetition.
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.
Also, maybe it would make sense to change the order and swap file
and content
, file
is on a lower level than path
and content
and we can't move path
for backward compatibility.
specfile/types.py
Outdated
|
||
|
||
try: | ||
from typing import TypedDict | ||
except ImportError: | ||
from typing_extensions import TypedDict | ||
|
||
EncodingArgs = TypedDict("EncodingArgs", {"encoding": str, "errors": str}) |
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.
This shows as resolved, but nothing has changed.
Build succeeded. ✔️ pre-commit SUCCESS in 1m 54s |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 59s |
… fixture (#2580) Initiate dist-git repo after spec file is present in `cockpit_ostree` fixture The spec file is copied to the dist-git repo after it is initialized, which means it isn't commited to git and eventually gets removed, but that doesn't make the tests fail because the related Specfile instance keeps its content in memory even though the file no longer exists. That however changes once the Specfile instance gets properly reloaded when needed and the tests start to fail. Fix that. Related to #2532, packit/specfile#458. Reviewed-by: Laura Barcziová Reviewed-by: Matej Focko
/packit build |
/packit-stg build |
Build succeeded. ✔️ pre-commit SUCCESS in 2m 00s |
Thanks for actively guiding throughout the process !! |
Build succeeded. ✔️ pre-commit SUCCESS in 1m 54s |
85de55e
to
10904a6
Compare
Build succeeded. ✔️ pre-commit SUCCESS in 1m 52s |
specfile/specfile.py
Outdated
sourcedir: Optional[Union[Path, str]] = None, | ||
autosave: bool = False, | ||
macros: Optional[List[Tuple[str, Optional[str]]]] = None, | ||
force_parse: bool = False, | ||
) -> None: | ||
""" | ||
Initializes a specfile object. | ||
|
||
The arguments `path`, `file` and `content` are mutually exclusive and only one can be used. |
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'm not able to apply the suggestion from the start of the docstring, nevertheless:
The arguments `path`, `file` and `content` are mutually exclusive and only one can be used. | |
Initializes a specfile object. You can specify either a path to the spec file, | |
its content as a string or a file object representing it. `sourcedir` is optional | |
if `path` or a named `file` is provided and will be set to the parent directory. | |
Could you modify the description a bit: It's not only related to those issues, it does fix them.
Release notes are supposed to describe user-facing changes. |
Build succeeded. ✔️ pre-commit SUCCESS in 2m 00s |
Build succeeded. ✔️ pre-commit SUCCESS in 2m 01s |
/packit build |
/packit-stg build |
Build succeeded (gate pipeline). ✔️ pre-commit SUCCESS in 1m 58s |
6daed02
into
packit:main
TODO:
Fixes #206
Fixes #248
RELEASE NOTES BEGIN
RELEASE NOTES END