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
[utilities] Relax from hard dependency of python3-magic #3025
[utilities] Relax from hard dependency of python3-magic #3025
Conversation
Cc @nkshirsagar - please let me know if this PR would resolve the #3021 (in upstream). |
Congratulations! One of the builds has completed. 🍾 You can install the built RPMs by following these steps:
Please note that the RPMs should be used only in a testing environment. |
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.
Having the failover method makes sense, but is there a way we can make python3-magic
a similarly weak dep for setup.py
?
Since the current approach depends on a method that only exists in 0.4.19, should we leave the dependency in there, but simply fallback to the "read a byte" approach when an older version is installed?
You mean "try importing magic library, if succeeds and version is >=0.4.20, always use the method from magic; otherwise always fallback to the 'read a byte' approach"? That makes sense, and keep that in a variable to test inside |
Yes, but also something that provides for "Hey, $user, the sos team really suggests having python3-magic installed here, and it should be installed alongside sos if at all possible, but just in case that can't be done, you're still covered." Effectively, try to ensure that python3-magic gets installed (so, I guess, keep it as a dep), but provide failover in case that's not possible but we still want to support generating an archive. |
We have patched downstream with a very similar patch for bionic/focal Ubuntu versions, pasted below,
So we are going ahead with our 4.4 releases with that for now, and for 4.5 we will revert the patch so as to use the upstream source. |
For compatibility reasons on some distros, sos should not have a hard dependency on 'magic' python library. It should attempt to use it for detection of binary file content, but should fall back to previous "read the very first byte" method otherwise. Resolves: sosreport#3025 Relates: sosreport#3021 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
49401a6
to
429fae6
Compare
Good point with the warning, I added it. Yes the downstream Ubuntu patch was an inspiration :) - my question was rather to ensure the upstream solution will properly work on Ubuntu without a need of a downstream patch. |
The warning "It is recommended to install proper python3-magic package with the module." is moot on Ubuntu bionic/focal versions because we know they will not have the required python3-magic package. The upstream patch caters to both situations but the debian patch simply assumes no such python3-magic version will be available, so no warning is needed, and we simply revert to older approach for those distros. Thinking ahead, for 4.5 we could potentially revert the debian patch, but we'd end up spewing a warning. |
Feel free to propose any better warning text (in either better meaning or better English), I know I am not the best writer for either :). |
The warning is perfect for distributions where the upgrade of that package is actually an option :-) |
sos/utilities.py
Outdated
import magic | ||
magic.detect_from_filename(__file__) | ||
magic_mod = True | ||
except ImportError: |
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.
We'd also need to catch AttributeError
for cases where older magic
is installed and detect_from_filename()
is not present.
For compatibility reasons on some distros, sos should not have a hard dependency on 'magic' python library. It should attempt to use it for detection of binary file content, but should fall back to previous "read the very first byte" method otherwise. Resolves: sosreport#3025 Relates: sosreport#3021 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
43d41ed
to
c9861b2
Compare
sos/utilities.py
Outdated
import magic | ||
magic.detect_from_filename(__file__) | ||
magic_mod = True | ||
except ImportError, AttributeError: |
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.
Syntax error is due to these being non-parenthesized.
For compatibility reasons on some distros, sos should not have a hard dependency on 'magic' python library. It should attempt to use it for detection of binary file content, but should fall back to previous "read the very first byte" method otherwise. Resolves: sosreport#3025 Relates: sosreport#3021 Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
c9861b2
to
2cf0d3c
Compare
For compatibility reasons on some distros, sos should not have a hard dependency on 'magic' python library. It should attempt to use it for detection of binary file content, but should fall back to previous "read the very first byte" method otherwise.
Resolves: #3025
Relates: #3021
Signed-off-by: Pavel Moravec pmoravec@redhat.com
Please place an 'X' inside each '[]' to confirm you adhere to our Contributor Guidelines