Skip to content

Commit

Permalink
Switch VersionInfo -> Version for ModOrganizer2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Jun 30, 2024
1 parent 6623e19 commit ed387d9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
55 changes: 54 additions & 1 deletion src/mobase/wrappers/basic_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,49 @@ namespace mo2::python {

void add_versioninfo_classes(py::module_ m)
{
// Version
py::class_<Version> pyVersion(m, "Version");

py::enum_<Version::ReleaseType>(pyVersion, "ReleaseType")
.value("DEVELOPMENT", Version::Development)
.value("ALPHA", Version::Alpha)
.value("BETA", Version::Beta)
.value("RELEASE_CANDIDATE", Version::ReleaseCandidate)
.export_values();

py::enum_<Version::ParseMode>(pyVersion, "ParseMode")
.value("SEMVER", Version::ParseMode::SemVer)
.value("MO2", Version::ParseMode::MO2);

pyVersion
.def_static("parse", &Version::parse, "value"_a,
"mode"_a = Version::ParseMode::SemVer)
.def(py::init<int, int, int, QString>(), "major"_a, "minor"_a, "patch"_a,
"metadata"_a = "")
.def(py::init<int, int, int, Version::ReleaseType, QString>(), "major"_a,
"minor"_a, "patch"_a, "type"_a, "metadata"_a = "")
.def(py::init<int, int, int, Version::ReleaseType, int, QString>(),
"major"_a, "minor"_a, "patch"_a, "type"_a, "prerelease"_a,
"metadata"_a = "")
.def(py::init<int, int, int,
std::vector<std::variant<int, Version::ReleaseType>>,
QString>(),
"major"_a, "minor"_a, "patch"_a, "pre_releases"_a, "metadata"_a = "")
.def("isPreRelease", &Version::isPreRelease)
.def_property_readonly("major", &Version::major)
.def_property_readonly("minor", &Version::minor)
.def_property_readonly("patch", &Version::patch)
.def_property_readonly("prerelease", &Version::preReleases)
.def_property_readonly("build_metadata", &Version::buildMetadata)
.def("__str__", &Version::string)
.def(py::self < py::self)
.def(py::self > py::self)
.def(py::self <= py::self)
.def(py::self >= py::self)
.def(py::self != py::self)
.def(py::self == py::self);

// VersionInfo
py::enum_<MOBase::VersionInfo::ReleaseType>(m, "ReleaseType")
.value("final", MOBase::VersionInfo::RELEASE_FINAL)
.value("candidate", MOBase::VersionInfo::RELEASE_CANDIDATE)
Expand Down Expand Up @@ -447,7 +490,17 @@ namespace mo2::python {
.def("overwritePath", &IOrganizer::overwritePath)
.def("basePath", &IOrganizer::basePath)
.def("modsPath", &IOrganizer::modsPath)
.def("appVersion", &IOrganizer::appVersion)
.def("appVersion",
[](IOrganizer& o) {
mo2::python::show_deprecation_warning(
"appVersion", "IOrganizer::appVersion() is deprecated, use "
"IOrganizer::version() instead.");
#pragma warning(push)
#pragma warning(disable : 4996)
return o.appVersion();
#pragma warning(pop)
})
.def("version", &IOrganizer::version)
.def("createMod", &IOrganizer::createMod,
py::return_value_policy::reference, "name"_a)
.def("getGame", &IOrganizer::getGame, py::return_value_policy::reference,
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/MockOrganizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MockOrganizer : public IOrganizer {
MOCK_METHOD(QString, basePath, (), (const, override));
MOCK_METHOD(QString, modsPath, (), (const, override));
MOCK_METHOD(VersionInfo, appVersion, (), (const, override));
MOCK_METHOD(Version, version, (), (const, override));
MOCK_METHOD(IModInterface*, createMod, (GuessedValue<QString> &name), (override));
MOCK_METHOD(IPluginGame*, getGame, (const QString &gameName), (const, override));
MOCK_METHOD(void, modDataChanged, (IModInterface *mod), (override));
Expand Down
1 change: 1 addition & 0 deletions tests/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ foreach (test_file ${test_files})
pybind11_add_module(${target} EXCLUDE_FROM_ALL THIN_LTO ${test_file})
set_target_properties(${target}
PROPERTIES
CXX_STANDARD 20
OUTPUT_NAME ${pymodule}
FOLDER tests/python
LIBRARY_OUTPUT_DIRECTORY "${PYLIB_DIR}/mobase_tests")
Expand Down

0 comments on commit ed387d9

Please sign in to comment.