Skip to content

Commit cf0d1bf

Browse files
committed
Fix compilation with Cython 0.29 (#371)
* fix compilation with cython 0.29.37 * do not import LOCAL_CLUSTER directly, access it via settings module (cherry picked from commit 2fc4622)
1 parent c4e9ece commit cf0d1bf

File tree

13 files changed

+50
-46
lines changed

13 files changed

+50
-46
lines changed

pyslurm/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
sys.setdlopenflags(sys.getdlopenflags() | os.RTLD_GLOBAL | os.RTLD_DEEPBIND)
99

10-
# Initialize slurm api
11-
from pyslurm.api import slurm_init, slurm_fini
12-
slurm_init()
13-
1410
from .version import __version__
1511

1612
from pyslurm import db
@@ -35,3 +31,7 @@
3531

3632
# The old API in deprecated.pyx
3733
from pyslurm.deprecated import *
34+
35+
# Initialize slurm api
36+
from pyslurm.api import slurm_init, slurm_fini
37+
slurm_init()

pyslurm/api.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
# cython: c_string_type=unicode, c_string_encoding=default
2323
# cython: language_level=3
2424

25+
from pyslurm import settings
26+
2527

2628
def slurm_init(config_path=None):
2729
"""Initialize the Slurm API.
@@ -36,6 +38,7 @@ def slurm_init(config_path=None):
3638
None, so libslurm will automatically detect its config.
3739
"""
3840
slurm.slurm_init(cstr.from_unicode(config_path))
41+
settings.init()
3942

4043

4144
def slurm_fini():

pyslurm/core/job/job.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ from typing import Union
3434
from pyslurm.utils import cstr, ctime
3535
from pyslurm.utils.uint import *
3636
from pyslurm.core.job.util import *
37-
from pyslurm.settings import LOCAL_CLUSTER
37+
from pyslurm import settings
3838
from pyslurm import xcollections
3939
from pyslurm.core.error import (
4040
RPCError,
@@ -236,7 +236,7 @@ cdef class Job:
236236
self.ptr.job_id = job_id
237237
self.passwd = {}
238238
self.groups = {}
239-
cstr.fmalloc(&self.ptr.cluster, LOCAL_CLUSTER)
239+
cstr.fmalloc(&self.ptr.cluster, settings.LOCAL_CLUSTER)
240240
self.steps = JobSteps()
241241
self.stats = JobStatistics()
242242
self.pids = {}

pyslurm/core/job/step.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ from typing import Union
2626
from pyslurm.utils import cstr, ctime
2727
from pyslurm.utils.uint import *
2828
from pyslurm.core.error import RPCError, verify_rpc
29-
from pyslurm.settings import LOCAL_CLUSTER
29+
from pyslurm import settings
3030
from pyslurm import xcollections
3131
from pyslurm.utils.helpers import (
3232
signal_to_num,
@@ -159,7 +159,7 @@ cdef class JobStep:
159159
self.id = step_id
160160
self.stats = JobStepStatistics()
161161
self.pids = {}
162-
cstr.fmalloc(&self.ptr.cluster, LOCAL_CLUSTER)
162+
cstr.fmalloc(&self.ptr.cluster, settings.LOCAL_CLUSTER)
163163

164164
# Initialize attributes, if any were provided
165165
for k, v in kwargs.items():

pyslurm/core/node.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ from pyslurm.utils import ctime
2828
from pyslurm.utils.uint import *
2929
from pyslurm.core.error import RPCError, verify_rpc
3030
from pyslurm.utils.ctime import timestamp_to_date, _raw_time
31-
from pyslurm.settings import LOCAL_CLUSTER
31+
from pyslurm import settings
3232
from pyslurm import xcollections
3333
from pyslurm.utils.helpers import (
3434
uid_to_name,
@@ -222,7 +222,7 @@ cdef class Node:
222222
def __init__(self, name=None, **kwargs):
223223
self._alloc_impl()
224224
self.name = name
225-
self.cluster = LOCAL_CLUSTER
225+
self.cluster = settings.LOCAL_CLUSTER
226226
for k, v in kwargs.items():
227227
setattr(self, k, v)
228228

@@ -270,7 +270,7 @@ cdef class Node:
270270
wrap._alloc_info()
271271
wrap.passwd = {}
272272
wrap.groups = {}
273-
wrap.cluster = LOCAL_CLUSTER
273+
wrap.cluster = settings.LOCAL_CLUSTER
274274
memcpy(wrap.info, in_ptr, sizeof(node_info_t))
275275
return wrap
276276

pyslurm/core/partition.pxd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ from pyslurm.utils cimport cstr
5555
from pyslurm.utils cimport ctime
5656
from pyslurm.utils.ctime cimport time_t
5757
from pyslurm.utils.uint cimport *
58-
from pyslurm.core cimport slurmctld
5958
from pyslurm.xcollections cimport MultiClusterMap
6059

6160

@@ -217,7 +216,7 @@ cdef class Partition:
217216
cdef:
218217
partition_info_t *ptr
219218
int power_save_enabled
220-
slurmctld.Config slurm_conf
219+
slurm_conf
221220

222221
cdef readonly cluster
223222

pyslurm/core/partition.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ from pyslurm.utils.uint import *
3030
from pyslurm.core.error import RPCError, verify_rpc
3131
from pyslurm.utils.ctime import timestamp_to_date, _raw_time
3232
from pyslurm.constants import UNLIMITED
33-
from pyslurm.settings import LOCAL_CLUSTER
33+
from pyslurm import settings
34+
from pyslurm.core import slurmctld
3435
from pyslurm.core.slurmctld.config import _get_memory
3536
from pyslurm import xcollections
3637
from pyslurm.utils.helpers import (
@@ -78,7 +79,6 @@ cdef class Partitions(MultiClusterMap):
7879
Partitions partitions = Partitions()
7980
int flags = slurm.SHOW_ALL
8081
Partition partition
81-
slurmctld.Config slurm_conf
8282
int power_save_enabled = 0
8383

8484
verify_rpc(slurm_load_partitions(0, &partitions.info, flags))
@@ -168,7 +168,7 @@ cdef class Partition:
168168
def __init__(self, name=None, **kwargs):
169169
self._alloc_impl()
170170
self.name = name
171-
self.cluster = LOCAL_CLUSTER
171+
self.cluster = settings.LOCAL_CLUSTER
172172
for k, v in kwargs.items():
173173
setattr(self, k, v)
174174

@@ -194,7 +194,7 @@ cdef class Partition:
194194
cdef Partition from_ptr(partition_info_t *in_ptr):
195195
cdef Partition wrap = Partition.__new__(Partition)
196196
wrap._alloc_impl()
197-
wrap.cluster = LOCAL_CLUSTER
197+
wrap.cluster = settings.LOCAL_CLUSTER
198198
memcpy(wrap.ptr, in_ptr, sizeof(partition_info_t))
199199
return wrap
200200

@@ -801,7 +801,7 @@ def _preempt_mode_str_to_int(mode):
801801
return pmode
802802

803803

804-
def _preempt_mode_int_to_str(mode, slurmctld.Config slurm_conf):
804+
def _preempt_mode_int_to_str(mode, slurm_conf):
805805
if mode == slurm.NO_VAL16:
806806
return slurm_conf.preempt_mode if slurm_conf else None
807807
else:

pyslurm/core/slurmctld/__init__.pxd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
# cython: c_string_type=unicode, c_string_encoding=default
2-
# cython: language_level=3
3-
4-
from .config cimport Config

pyslurm/db/assoc.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ from pyslurm.utils.helpers import (
2929
)
3030
from pyslurm.utils.uint import *
3131
from pyslurm.db.connection import _open_conn_or_error
32-
from pyslurm.settings import LOCAL_CLUSTER
32+
from pyslurm import settings
3333
from pyslurm import xcollections
3434

3535

@@ -65,7 +65,7 @@ cdef class Associations(MultiClusterMap):
6565
# Fetch Assoc Data
6666
assoc_data = SlurmList.wrap(slurmdb_associations_get(
6767
conn.ptr, cond.ptr))
68-
68+
6969
if assoc_data.is_null:
7070
raise RPCError(msg="Failed to get Association data from slurmdbd")
7171

@@ -135,7 +135,7 @@ cdef class Associations(MultiClusterMap):
135135
else:
136136
# Autodetects the last slurm error
137137
raise RPCError()
138-
138+
139139
if not db_connection:
140140
# Autocommit if no connection was explicitly specified.
141141
conn.commit()
@@ -185,7 +185,7 @@ cdef class Association:
185185
def __init__(self, **kwargs):
186186
self._alloc_impl()
187187
self.id = 0
188-
self.cluster = LOCAL_CLUSTER
188+
self.cluster = settings.LOCAL_CLUSTER
189189
for k, v in kwargs.items():
190190
setattr(self, k, v)
191191

pyslurm/db/job.pyx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
from typing import Union, Any
2626
from pyslurm.core.error import RPCError, PyslurmError
27-
from pyslurm.core import slurmctld
28-
from typing import Any
2927
from pyslurm.utils.uint import *
30-
from pyslurm.settings import LOCAL_CLUSTER
28+
from pyslurm import settings
3129
from pyslurm import xcollections
3230
from pyslurm.utils.ctime import (
3331
date_to_timestamp,
@@ -106,7 +104,7 @@ cdef class JobFilter:
106104
if not self.clusters:
107105
# This is a requirement for some other parameters to function
108106
# correctly, like self.nodelist
109-
return [LOCAL_CLUSTER]
107+
return [settings.LOCAL_CLUSTER]
110108
elif self.clusters == "all":
111109
return None
112110
else:
@@ -450,7 +448,7 @@ cdef class Job:
450448
self._alloc_impl()
451449
self.ptr.jobid = int(job_id)
452450
cstr.fmalloc(&self.ptr.cluster,
453-
LOCAL_CLUSTER if not cluster else cluster)
451+
settings.LOCAL_CLUSTER if not cluster else cluster)
454452
self.qos_data = QualitiesOfService()
455453
self.steps = JobSteps()
456454
self.stats = JobStatistics()
@@ -511,7 +509,7 @@ cdef class Job:
511509
>>> db_job = pyslurm.db.Job.load(10000, with_script=True)
512510
>>> print(db_job.script)
513511
"""
514-
cluster = LOCAL_CLUSTER if not cluster else cluster
512+
cluster = settings.LOCAL_CLUSTER if not cluster else cluster
515513
jfilter = JobFilter(ids=[int(job_id)], clusters=[cluster],
516514
with_script=with_script, with_env=with_env)
517515
job = Jobs.load(jfilter).get((cluster, int(job_id)))

pyslurm/settings.pyx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@
2222
# cython: c_string_type=unicode, c_string_encoding=default
2323
# cython: language_level=3
2424

25-
from pyslurm.core import slurmctld
2625
from pyslurm cimport slurm
2726
from pyslurm.utils cimport cstr
2827

2928

30-
LOCAL_CLUSTER = cstr.to_unicode(slurm.slurm_conf.cluster_name)
31-
if not LOCAL_CLUSTER:
32-
slurm_conf = slurmctld.Config.load()
33-
LOCAL_CLUSTER = slurm_conf.cluster_name
29+
LOCAL_CLUSTER = "UNKNOWN"
30+
31+
32+
def init():
33+
from pyslurm.core import slurmctld
34+
35+
global LOCAL_CLUSTER
36+
LOCAL_CLUSTER = cstr.to_unicode(slurm.slurm_conf.cluster_name)
37+
if not LOCAL_CLUSTER:
38+
slurm_conf = slurmctld.Config.load()
39+
LOCAL_CLUSTER = slurm_conf.cluster_name

pyslurm/xcollections.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ cdef class MultiClusterMap:
9595
_key_type
9696
_val_type
9797
_id_attr
98+
_cluster

pyslurm/xcollections.pyx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# cython: language_level=3
2424
"""Custom Collection utilities"""
2525

26-
from pyslurm.settings import LOCAL_CLUSTER
26+
from pyslurm import settings
2727
import json
2828
from typing import Union, Any
2929

@@ -193,6 +193,7 @@ cdef class MultiClusterMap:
193193
self._key_type = key_type
194194
self._val_type = val_type
195195
self._id_attr = id_attr
196+
self._cluster = settings.LOCAL_CLUSTER
196197
if init_data:
197198
self._init_data(data)
198199

@@ -201,15 +202,15 @@ cdef class MultiClusterMap:
201202
for item in data:
202203
if isinstance(item, self._key_type):
203204
item = self._val_type(item)
204-
if LOCAL_CLUSTER not in self.data:
205-
self.data[LOCAL_CLUSTER] = {}
205+
if self._cluster not in self.data:
206+
self.data[self._cluster] = {}
206207

207-
self.data[LOCAL_CLUSTER].update({self._item_id(item): item})
208+
self.data[self._cluster].update({self._item_id(item): item})
208209
elif isinstance(data, str):
209210
itemlist = data.split(",")
210211
items = {self._key_type(item):self._val_type(item)
211212
for item in itemlist}
212-
self.data[LOCAL_CLUSTER] = items
213+
self.data[self._cluster] = items
213214
elif isinstance(data, dict):
214215
self.update(data)
215216
elif data is not None:
@@ -223,8 +224,8 @@ cdef class MultiClusterMap:
223224

224225
def _get_cluster(self):
225226
cluster = None
226-
if not self.data or LOCAL_CLUSTER in self.data:
227-
cluster = LOCAL_CLUSTER
227+
if not self.data or self._cluster in self.data:
228+
cluster = self._cluster
228229
else:
229230
try:
230231
cluster = next(iter(self.keys()))
@@ -259,7 +260,7 @@ cdef class MultiClusterMap:
259260
try:
260261
cluster = self._get_cluster()
261262
except KeyError:
262-
cluster = LOCAL_CLUSTER
263+
cluster = self._cluster
263264

264265
if not cluster in self.data:
265266
self.data[cluster] = {}
@@ -394,7 +395,7 @@ cdef class MultiClusterMap:
394395
according to `next(iter(self.keys()))` will be used.
395396
396397
Examples:
397-
Get a Job from the LOCAL_CLUSTER
398+
Get a Job from the local Cluster.
398399
399400
>>> job_id = 1
400401
>>> job = data.get(job_id)

0 commit comments

Comments
 (0)