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

SWIG bindings and unit tests for Vars::detect_release() #1804

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jrohel
Copy link
Contributor

@jrohel jrohel commented Oct 28, 2024

Closes: #1803

The vars.hpp file is included in the conf module and the Vars class is
wrapped in the conf module. VarsWeakPtr was packaged in the base module.
Which will bring problems in the following changes.

So the VarsWeakPtr wrapper has been moved to the conf module.
The original `Vars::detect_release` returns `std::unique_ptr<std::string>`
This makes it complicated for wrapping into other languages.

The modified version returns `char *` - a standard C string.
Tests in Python, Ruby, Perl.

It only tests the situation where a release cannot be detected.
To detect an installed release, a system database with the corresponding
installed packages is required.
@gotmax23
Copy link
Contributor

gotmax23 commented Nov 5, 2024

fedrq has the following which uses the original version of this that @j-mracek added as a "raw prototype" after discussion in #281.

def get_releasever() -> str:
    """
    Return the system releasever
    """
    # libdnf5 >= 5.0.10
    # https://github.com/rpm-software-management/dnf5/pull/448
    base = libdnf5.base.Base()
    return libdnf5.conf.Vars.detect_release(base.get_weak_ptr(), "/").get()

Returning a proper string instead of a wrapper type is definitely nicer but does represent a breaking change.

Although, with python3-libdnf5-5.1.17-2.fc40.x86_64, it seems that is now broken and returns an empty string when it used to return the proper releasever.

@jrohel
Copy link
Contributor Author

jrohel commented Nov 5, 2024

Returning a proper string instead of a wrapper type is definitely nicer

Returning a proper string is nicer.
And, I tested the wrong version. It really returns a wrapped std::unique_ptr<std::string>. And get() can be used to get the string. The problem is that it doesn't distinguish between None and an empty string, which was probably the original intent of the unpleasant std::unique_ptr<string> construct.

but does represent a breaking change.

But as you write. It's breaking change.
I'm considering whether to close this PR... Anyway, it complicates my further work.

gotmax23 added a commit to gotmax23/fedrq-mirror that referenced this pull request Nov 7, 2024
This partially reverts commit 467bdfe.
See explanation in the code comments for why this was reverted.

Ref: rpm-software-management/dnf5#281
Ref: rpm-software-management/dnf5#1804
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SWIG bindings: Method Vars::detect_release unusable, returns unwrapped std::unique_ptr<std::string>
2 participants