Skip to content
Snippets Groups Projects
Commit 8f3781c3 authored by Sergey Kosukhin's avatar Sergey Kosukhin
Browse files

Reduce namespace pollution in Python modules

parent a6dc4e63
No related branches found
No related tags found
1 merge request!43Update python build
Pipeline #75813 passed
......@@ -75,7 +75,7 @@ __pycache__/
/**/doc/doxygen-doc/
# Install stage files
/**/python/mtime/.install/
/**/python/.install/
# Test stage files
*.py[cod]
......
......@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause
#
install_tmpdir = mtime/.install
install_tmpdir = .install
pkgpython_PYTHON = mtime/__init__.py
nodist_pkgpython_PYTHON = $(install_tmpdir)/_mtime.py
......@@ -13,10 +13,11 @@ mtime___mtime_la_LDFLAGS = -shared -avoid-version -module
mtime___mtime_la_LIBADD = $(top_builddir)/src/libmtime_c.la
$(install_tmpdir)/_mtime.py: mtime/_mtime.py
$(MKDIR_P) $(@D) && sed "s,^SOFILE = None$$,SOFILE = '$(DESTDIR)$(pkgpyexecdir)/__mtime$(acx_modext)'," $< >$@
install-data-hook:
rm -rf $(install_tmpdir)
$(MKDIR_P) $(@D) && { \
$(SED) -n '1,/^# SET-SOFILE-BEGIN-TAG$$/p' $<; \
echo '__SOFILE = "$(DESTDIR)$(pkgpyexecdir)/__mtime$(acx_modext)"'; \
$(SED) -n '/^# SET-SOFILE-END-TAG$$/,$$p' $<; \
}>$@
# overrides to make regular compilations also use libtool
COMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
......
......@@ -27,17 +27,15 @@ from ctypes import (
create_string_buffer,
)
SOFILE = None
if SOFILE is None:
import os
SOFILE = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
".libs",
"__mtime.so",
)
libmtime = cdll.LoadLibrary(SOFILE)
# SET-SOFILE-BEGIN-TAG
# This will be removed during the installation:
__os = __import__("os")
__SOFILE = __os.path.join(
__os.path.dirname(__os.path.abspath(__file__)), ".libs", "__mtime.so"
)
del __os
# SET-SOFILE-END-TAG
__mtime = cdll.LoadLibrary(__SOFILE)
# @package mtime_calendar
# @brief Provides the calendar to the users, abstracting the different
......@@ -112,7 +110,7 @@ max_calendar_str_len = c_int(32).value
# @param[in] ct the calendar type
# ct shoud be of class CALENDAR_TYPE.
#
setCalendar = libmtime.initCalendar
setCalendar = __mtime.initCalendar
setCalendar.argtypes = [CALENDAR_TYPE]
setCalendar.restype = None
......@@ -120,7 +118,7 @@ setCalendar.restype = None
# @brief called to discard the selected calendar type
#
# Usage example: resetCalendar();
resetCalendar = libmtime.freeCalendar
resetCalendar = __mtime.freeCalendar
resetCalendar.argtype = [None]
resetCalendar.restype = None
......@@ -136,7 +134,7 @@ resetCalendar.restype = None
# - 3 (year_of_360_days)
#
# @return an integer denoting the calendar in use
getCalendarType = libmtime.getCalendarType
getCalendarType = __mtime.getCalendarType
getCalendarType.argtype = [None]
getCalendarType.restype = CALENDAR_TYPE
......@@ -148,7 +146,7 @@ getCalendarType.restype = CALENDAR_TYPE
# (out will now contain the Calendar type in human readable form)
#
# @param[out] string the calendar type verbose
my_calendarToString = libmtime.calendarToString
my_calendarToString = __mtime.calendarToString
my_calendarToString.argtype = [c_char_p]
my_calendarToString.restype = None
......@@ -185,7 +183,7 @@ class _julianday(Structure):
# @param[in] ms an integer denoting the actual milli seconds of a
# day
# @return ret_julianday a pointer of type(julianday)
newJulianDay = libmtime.newJulianDay
newJulianDay = __mtime.newJulianDay
newJulianDay.argtypes = [c_long, c_long]
newJulianDay.restype = POINTER(_julianday)
......@@ -195,7 +193,7 @@ newJulianDay.restype = POINTER(_julianday)
# USAGE example: deallocateJulianDay(jd);
#
# @param my_julianday a pointer of type(julianday)
deallocateJulianDay = libmtime.deallocateJulianDay
deallocateJulianDay = __mtime.deallocateJulianDay
deallocateJulianDay.argtype = [POINTER(_julianday)]
deallocateJulianDay.restype = None
......@@ -209,7 +207,7 @@ deallocateJulianDay.restype = None
# converted to a string
# @param[in] str string where Julian day verbose is written
# @param[out] str the Julian day verbose
my_juliandayToString = libmtime.juliandayToString
my_juliandayToString = __mtime.juliandayToString
my_juliandayToString.argtype = [POINTER(_julianday), c_char_p]
my_juliandayToString.restype = None
......@@ -243,7 +241,7 @@ class _date(Structure):
#
# @param[in] string an ISO 8601 conforming date string
# @return ret_date a pointer of type(_date)
newDate = libmtime.newDate
newDate = __mtime.newDate
newDate.argtype = [c_char_p]
newDate.restype = POINTER(_date)
......@@ -253,7 +251,7 @@ newDate.restype = POINTER(_date)
# USAGE example: deallocateDate(d);
#
# @param[in] my_date a pointer of type(_date)
deallocateDate = libmtime.deallocateDate
deallocateDate = __mtime.deallocateDate
deallocateDate.argtype = [POINTER(_date)]
deallocateDate.restype = None
......@@ -267,7 +265,7 @@ deallocateDate.restype = None
# string
# @param[in] str string where Date verbose is written
# @param[out] str the Date verbose
my_dateToString = libmtime.dateToString
my_dateToString = __mtime.dateToString
my_dateToString.argtype = [POINTER(_date), c_char_p]
my_dateToString.restype = None
......@@ -300,17 +298,17 @@ class _time(Structure):
]
newTime = libmtime.newTime
newTime = __mtime.newTime
newTime.argtype = [c_char_p]
newTime.restype = POINTER(_time)
deallocateTime = libmtime.deallocateTime
deallocateTime = __mtime.deallocateTime
deallocateTime.argtype = [POINTER(_time)]
deallocateTime.restype = None
my_timeToString = libmtime.timeToString
my_timeToString = __mtime.timeToString
my_timeToString.argtype = [POINTER(_time), c_char_p]
my_timeToString.restype = None
......@@ -390,27 +388,27 @@ class _datetime(Structure):
"""
newDateTime = libmtime.newDateTime
newDateTime = __mtime.newDateTime
newDateTime.argtype = [c_char_p]
newDateTime.restype = POINTER(_datetime)
newdatetimefromraw = libmtime.newRawDateTime
newdatetimefromraw = __mtime.newRawDateTime
newdatetimefromraw.argtype = [c_long, c_int, c_int, c_int, c_int, c_int, c_int]
newdatetimefromraw.restype = POINTER(_datetime)
newdatetimefromconstructandcopy = libmtime.constructAndCopyDateTime
newdatetimefromconstructandcopy = __mtime.constructAndCopyDateTime
newdatetimefromconstructandcopy.argtype = [POINTER(_datetime)]
newdatetimefromconstructandcopy.restype = POINTER(_datetime)
deallocateDateTime = libmtime.deallocateDateTime
deallocateDateTime = __mtime.deallocateDateTime
deallocateDateTime.argtype = [POINTER(_datetime)]
deallocateDateTime.restype = None
my_datetimeToString = libmtime.datetimeToString
my_datetimeToString = __mtime.datetimeToString
my_datetimeToString.argtype = [POINTER(_datetime), c_char_p]
my_datetimeToString.restype = None
......@@ -421,32 +419,32 @@ def datetimeToString(dt):
return name.value
replaceDatetime = libmtime.replaceDatetime
replaceDatetime = __mtime.replaceDatetime
replaceDatetime.argtype = [POINTER(_datetime), POINTER(_datetime)]
replaceDatetime.restype = POINTER(_datetime)
compareDatetime = libmtime.compareDatetime
compareDatetime = __mtime.compareDatetime
compareDatetime.argtype = [POINTER(_datetime), POINTER(_datetime)]
compareDatetime.restype = c_int
getNoOfDaysInMonthDateTime = libmtime.getNoOfDaysInMonthDateTime
getNoOfDaysInMonthDateTime = __mtime.getNoOfDaysInMonthDateTime
getNoOfDaysInMonthDateTime.argtype = [POINTER(_datetime)]
getNoOfDaysInMonthDateTime.restype = c_int
getNoOfDaysInYearDateTime = libmtime.getNoOfDaysInYearDateTime
getNoOfDaysInYearDateTime = __mtime.getNoOfDaysInYearDateTime
getNoOfDaysInYearDateTime.argtype = [POINTER(_datetime)]
getNoOfDaysInYearDateTime.restype = c_int
getDayOfYearFromDateTime = libmtime.getDayOfYearFromDateTime
getDayOfYearFromDateTime = __mtime.getDayOfYearFromDateTime
getDayOfYearFromDateTime.argtype = [POINTER(_datetime)]
getDayOfYearFromDateTime.restype = c_int
getJulianDayFromDateTime = libmtime.getJulianDayFromDateTime
getJulianDayFromDateTime = __mtime.getJulianDayFromDateTime
getJulianDayFromDateTime.argtype = [POINTER(_datetime), POINTER(_julianday)]
getJulianDayFromDateTime.restype = POINTER(_julianday)
......@@ -477,17 +475,17 @@ class _timedelta(Structure):
]
newTimeDelta = libmtime.newTimeDelta
newTimeDelta = __mtime.newTimeDelta
newTimeDelta.argtype = [c_char_p]
newTimeDelta.restype = POINTER(_timedelta)
deallocateTimeDelta = libmtime.deallocateTimeDelta
deallocateTimeDelta = __mtime.deallocateTimeDelta
deallocateTimeDelta.argtype = [POINTER(_timedelta)]
deallocateTimeDelta.restype = None
addTimeDeltaToDateTime = libmtime.addTimeDeltaToDateTime
addTimeDeltaToDateTime = __mtime.addTimeDeltaToDateTime
addTimeDeltaToDateTime.argtype = [
POINTER(_datetime),
POINTER(_timedelta),
......@@ -496,7 +494,7 @@ addTimeDeltaToDateTime.argtype = [
addTimeDeltaToDateTime.restype = POINTER(_datetime)
my_timedeltaToString = libmtime.timedeltaToString
my_timedeltaToString = __mtime.timedeltaToString
my_timedeltaToString.argtype = [POINTER(_timedelta), c_char_p]
my_timedeltaToString.restype = c_char_p
......@@ -511,7 +509,7 @@ class _divisionquotienttimespan(Structure):
_fields_ = [("quotient", c_long), ("remainder_in_ms", c_long)]
divideDatetimeDifferenceInSeconds = libmtime.divideDatetimeDifferenceInSeconds
divideDatetimeDifferenceInSeconds = __mtime.divideDatetimeDifferenceInSeconds
divideDatetimeDifferenceInSeconds.argtype = [
POINTER(_datetime),
POINTER(_datetime),
......@@ -557,21 +555,21 @@ class _event(Structure):
]
newEvent = libmtime.newEvent
newEvent = __mtime.newEvent
newEvent.argtype = [c_char_p, c_char_p, c_char_p, c_char_p, c_char_p]
newEvent.restype = POINTER(_event)
deallocateEvent = libmtime.deallocateEvent
deallocateEvent = __mtime.deallocateEvent
deallocateEvent.argtype = [POINTER(_event)]
deallocateEvent.restype = None
isCurrentEventActive = libmtime.isCurrentEventActive
isCurrentEventActive = __mtime.isCurrentEventActive
isCurrentEventActive.argtype = [POINTER(_event), POINTER(_datetime)]
isCurrentEventActive.restype = c_bool
my_eventToString = libmtime.eventToString
my_eventToString = __mtime.eventToString
my_eventToString.argtype = [POINTER(_event), c_char_p]
my_eventToString.restype = c_char_p
......@@ -604,18 +602,18 @@ class _eventgroup(Structure):
]
newEventGroup = libmtime.newEventGroup
newEventGroup = __mtime.newEventGroup
newEventGroup.argtype = [c_char_p]
newEventGroup.restype = POINTER(_eventgroup)
deallocateEventGroup = libmtime.deallocateEventGroup
deallocateEventGroup = __mtime.deallocateEventGroup
deallocateEventGroup.argtype = [POINTER(_eventgroup)]
deallocateEventGroup.restype = None
addNewEventToEventGroup = libmtime.addNewEventToEventGroup
addNewEventToEventGroup = __mtime.addNewEventToEventGroup
addNewEventToEventGroup.argType = [POINTER(_event), POINTER(_eventgroup)]
addNewEventToEventGroup.resType = c_bool
removeEventFromEventGroup = libmtime.removeEventFromEventGroup
removeEventFromEventGroup = __mtime.removeEventFromEventGroup
removeEventFromEventGroup.argType = [c_char_p, POINTER(_eventgroup)]
removeEventFromEventGroup.resType = c_bool
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment