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

Add support for Python up to 3.12 #50

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/pymi-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
strategy:
max-parallel: 100
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Test and build PyMI
Expand All @@ -24,9 +24,9 @@ jobs:
pip install -r requirements.txt || exit /b
pip install nose testtools wheel || exit /b
pip install . || exit /b
nosetests wmi
python setup.py bdist_wheel
- uses: actions/upload-artifact@v1
python -m unittest discover || exit /b
python setup.py bdist_wheel || exit /b
- uses: actions/upload-artifact@v3
with:
name: pymi_wheel_py${{ matrix.python-version }}
path: 'dist'
32 changes: 16 additions & 16 deletions PyMI/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ static PyObject* Application_new(PyTypeObject *type, PyObject *args, PyObject *k

static int Application_init(Application *self, PyObject *args, PyObject *kwds)
{
wchar_t* appId = L"";
char* appId = "";
static char *kwlist[] = { "app_id", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|u", kwlist, &appId))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &appId))
return -1;

try
{
AllowThreads(&self->cs, [&]() {
self->app = std::make_shared<MI::Application>(appId);
self->app = std::make_shared<MI::Application>(ToWstring(appId).c_str());
});
return 0;
}
Expand All @@ -40,12 +40,12 @@ static int Application_init(Application *self, PyObject *args, PyObject *kwds)

static PyObject* Application_NewSession(Application *self, PyObject *args, PyObject *kwds)
{
wchar_t* protocol = L"";
wchar_t* computerName = L".";
char* protocol = "";
char* computerName = ".";
PyObject* destinationOptions = NULL;

static char *kwlist[] = { "protocol", "computer_name", "destination_options", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|uuO", kwlist, &protocol, &computerName, &destinationOptions))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ssO", kwlist, &protocol, &computerName, &destinationOptions))
return NULL;

try
Expand All @@ -57,7 +57,7 @@ static PyObject* Application_NewSession(Application *self, PyObject *args, PyObj

std::shared_ptr<MI::Session> session;
AllowThreads(&self->cs, [&]() {
session = self->app->NewSession(protocol, computerName,
session = self->app->NewSession(ToWstring(protocol).c_str(), ToWstring(computerName).c_str(),
!CheckPyNone(destinationOptions) ? ((DestinationOptions*)destinationOptions)->destinationOptions : NULL);
});
return (PyObject*)Session_New(session);
Expand All @@ -84,10 +84,10 @@ static void Application_dealloc(Application* self)
static PyObject* Application_NewMethodInboundParameters(Application *self, PyObject *args, PyObject *kwds)
{
PyObject* pyClass = NULL;
wchar_t* methodName = NULL;
char* methodName = NULL;

static char *kwlist[] = { "mi_class", "method_name", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ou", kwlist, &pyClass, &methodName))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "Os", kwlist, &pyClass, &methodName))
return NULL;

try
Expand All @@ -97,7 +97,7 @@ static PyObject* Application_NewMethodInboundParameters(Application *self, PyObj

std::shared_ptr<MI::Instance> instance;
AllowThreads(&self->cs, [&]() {
instance = self->app->NewMethodParamsInstance(*((Class*)pyClass)->miClass, methodName);
instance = self->app->NewMethodParamsInstance(*((Class*)pyClass)->miClass, ToWstring(methodName).c_str());
});
return (PyObject*)Instance_New(instance);
}
Expand All @@ -110,16 +110,16 @@ static PyObject* Application_NewMethodInboundParameters(Application *self, PyObj

static PyObject* Application_NewInstance(Application *self, PyObject *args, PyObject *kwds)
{
wchar_t* className = NULL;
char* className = NULL;
static char *kwlist[] = { "class_name", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "u", kwlist, &className))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &className))
return NULL;

try
{
std::shared_ptr<MI::Instance> instance;
AllowThreads(&self->cs, [&]() {
instance = self->app->NewInstance(className);
instance = self->app->NewInstance(ToWstring(className).c_str());
});
return (PyObject*)Instance_New(instance);
}
Expand All @@ -132,10 +132,10 @@ static PyObject* Application_NewInstance(Application *self, PyObject *args, PyOb

static PyObject* Application_NewInstanceFromClass(Application *self, PyObject *args, PyObject *kwds)
{
wchar_t* className = NULL;
char* className = NULL;
PyObject* miClass = NULL;
static char *kwlist[] = { "class_name", "mi_class", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "uO", kwlist, &className, &miClass))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sO", kwlist, &className, &miClass))
return NULL;

try
Expand All @@ -145,7 +145,7 @@ static PyObject* Application_NewInstanceFromClass(Application *self, PyObject *a

std::shared_ptr<MI::Instance> instance;
AllowThreads(&self->cs, [&]() {
instance = self->app->NewInstanceFromClass(className, *((Class*)miClass)->miClass);
instance = self->app->NewInstanceFromClass(ToWstring(className).c_str(), *((Class*)miClass)->miClass);
});
return (PyObject*)Instance_New(instance);
}
Expand Down
30 changes: 15 additions & 15 deletions PyMI/DestinationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ static PyObject* DestinationOptions_GetUILocale(DestinationOptions* self)

static PyObject* DestinationOptions_SetUILocale(DestinationOptions* self, PyObject *args, PyObject *kwds)
{
wchar_t* locale = NULL;
char* locale = NULL;
static char *kwlist[] = { "locale_name", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "u", kwlist, &locale))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &locale))
return NULL;

try
{
AllowThreads(&self->cs, [&]() {
self->destinationOptions->SetUILocale(locale);
self->destinationOptions->SetUILocale(ToWstring(locale).c_str());
});
Py_RETURN_NONE;
}
Expand Down Expand Up @@ -139,15 +139,15 @@ static PyObject* DestinationOptions_SetTimeout(DestinationOptions* self, PyObjec

static PyObject* DestinationOptions_SetTransport(DestinationOptions* self, PyObject *args, PyObject *kwds)
{
wchar_t* transport = NULL;
char* transport = NULL;
static char *kwlist[] = { "transport", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "u", kwlist, &transport))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &transport))
return NULL;

try
{
AllowThreads(&self->cs, [&]() {
self->destinationOptions->SetTransport(transport);
self->destinationOptions->SetTransport(ToWstring(transport).c_str());
});
Py_RETURN_NONE;
}
Expand Down Expand Up @@ -178,26 +178,26 @@ static PyObject* DestinationOptions_GetTransport(DestinationOptions* self)

static PyObject* DestinationOptions_AddCredentials(DestinationOptions* self, PyObject *args, PyObject *kwds)
{
wchar_t* authType = NULL;
wchar_t* domain = NULL;
wchar_t* username = NULL;
wchar_t* password = NULL;
wchar_t* certThumbprint = NULL;
char* authType = NULL;
char* domain = NULL;
char* username = NULL;
char* password = NULL;
char* certThumbprint = NULL;

static char *kwlist[] = { "auth_type", "domain", "username", "password", "cert_thumbprint", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "u|uuuu", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ssss", kwlist,
&authType, &domain, &username, &password, &certThumbprint))
return NULL;

try
{
if (certThumbprint && wcslen(certThumbprint))
if (ToWstring(certThumbprint).c_str() && wcslen(ToWstring(certThumbprint).c_str()))
AllowThreads(&self->cs, [&]() {
self->destinationOptions->AddCredentials(authType, certThumbprint);
self->destinationOptions->AddCredentials(ToWstring(authType).c_str(), ToWstring(certThumbprint).c_str());
});
else
AllowThreads(&self->cs, [&]() {
self->destinationOptions->AddCredentials(authType, domain, username, password);
self->destinationOptions->AddCredentials(ToWstring(authType).c_str(), ToWstring(domain).c_str(), ToWstring(username).c_str(), ToWstring(password).c_str());
});
Py_RETURN_NONE;
}
Expand Down
6 changes: 3 additions & 3 deletions PyMI/OperationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ static PyObject* OperationOptions_SetTimeout(OperationOptions* self, PyObject* t

static PyObject* OperationOptions_SetCustomOption(OperationOptions* self, PyObject *args, PyObject *kwds)
{
wchar_t* optionName = NULL;
char* optionName = NULL;
unsigned int optionValueType = 0;
PyObject* optionValue = NULL;
PyObject* mustComply = NULL;

static char *kwlist[] = { "name", "value_type", "value", "must_comply", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwds, "uIO|O", kwlist,
if (!PyArg_ParseTupleAndKeywords(args, kwds, "sIO|O", kwlist,
&optionName, &optionValueType,
&optionValue, &mustComply))
return NULL;
Expand All @@ -116,7 +116,7 @@ static PyObject* OperationOptions_SetCustomOption(OperationOptions* self, PyObj
{
auto miValue = Py2MI(optionValue, (MI_Type)optionValueType);
AllowThreads(&self->cs, [&]() {
self->operationOptions->SetCustomOption(optionName, (MI_Type)optionValueType,
self->operationOptions->SetCustomOption(ToWstring(optionName).c_str(), (MI_Type)optionValueType,
*miValue, PyObject_IsTrue(mustComply));
});
Py_RETURN_NONE;
Expand Down
Loading