Skip to content

Commit

Permalink
Merge pull request #3162 from grondo/python-split-job-module
Browse files Browse the repository at this point in the history
python: split flux.job module into multiple files
  • Loading branch information
mergify[bot] committed Aug 27, 2020
2 parents fe91847 + 6cc9dda commit e31fab0
Show file tree
Hide file tree
Showing 13 changed files with 731 additions and 601 deletions.
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ AC_CONFIG_FILES( \
src/bindings/lua/Makefile \
src/bindings/python/Makefile \
src/bindings/python/flux/Makefile \
src/bindings/python/flux/core/Makefile \
src/bindings/python/_flux/Makefile \
src/broker/Makefile \
src/cmd/Makefile \
Expand Down
46 changes: 29 additions & 17 deletions src/bindings/python/flux/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
fluxpy_PYTHON=\
__init__.py\
kvs.py\
wrapper.py\
rpc.py\
message.py\
constants.py\
job.py \
util.py \
future.py \
memoized_property.py \
debugged.py
nobase_fluxpy_PYTHON = \
__init__.py \
kvs.py \
wrapper.py \
rpc.py \
message.py \
constants.py \
util.py \
future.py \
memoized_property.py \
debugged.py \
core/__init__.py \
core/watchers.py \
core/inner.py \
core/handle.py \
core/trampoline.py \
job/__init__.py \
job/JobID.py \
job/Jobspec.py \
job/event.py \
job/kill.py \
job/kvs.py \
job/list.py \
job/submit.py \
job/wait.py \
job/_wrapper.py

if HAVE_FLUX_SECURITY
fluxpy_PYTHON += security.py
nobase_fluxpy_PYTHON += security.py
endif

clean-local:
-rm -f *.pyc *.pyo
-rm -rf __pycache__

SUBDIRS = core
-rm -f *.pyc */*.pyc *.pyo */*.pyo
-rm -rf __pycache__ */__pycache__

install-data-hook:
$(AM_V_at)echo Linking python modules in non-standard location... && \
Expand Down
11 changes: 0 additions & 11 deletions src/bindings/python/flux/core/Makefile.am

This file was deleted.

99 changes: 99 additions & 0 deletions src/bindings/python/flux/job/JobID.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
###############################################################
# Copyright 2020 Lawrence Livermore National Security, LLC
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
#
# This file is part of the Flux resource manager framework.
# For details, see https://github.com/flux-framework.
#
# SPDX-License-Identifier: LGPL-3.0
###############################################################

from flux.job._wrapper import _RAW as RAW
from _flux._core import ffi


def id_parse(jobid_str):
"""
returns: An integer jobid
:rtype int
"""
jobid = ffi.new("flux_jobid_t[1]")
RAW.id_parse(jobid_str, jobid)
return int(jobid[0])


def id_encode(jobid, encoding="f58"):
"""
returns: Jobid encoded in encoding
:rtype str
"""
buflen = 128
buf = ffi.new("char[]", buflen)
RAW.id_encode(int(jobid), encoding, buf, buflen)
return ffi.string(buf, buflen).decode("utf-8")


class JobID(int):
"""Class used to represent a Flux JOBID
JobID is a subclass of `int`, so may be used in place of integer.
However, a JobID may be created from any valid RFC 19 FLUID
encoding, including:
- decimal integer (no prefix)
- hexidecimal integer (prefix 0x)
- dotted hex (dothex) (xxxx.xxxx.xxxx.xxxx)
- kvs dir (dotted hex with `job.` prefix)
- RFC19 F58: (Base58 encoding with prefix `ƒ` or `f`)
A JobID object also has properties for encoding a JOBID into each
of the above representations, e.g. jobid.f85, jobid.words, jobid.dothex...
"""

def __new__(cls, value):
if isinstance(value, int):
jobid = value
else:
jobid = id_parse(value)
return super(cls, cls).__new__(cls, jobid)

def encode(self, encoding="dec"):
"""Encode a JobID to alternate supported format"""
return id_encode(self, encoding)

@property
def dec(self):
"""Return decimal integer representation of a JobID"""
return self.encode()

@property
def f58(self):
"""Return RFC19 F58 representation of a JobID"""
return self.encode("f58")

@property
def hex(self):
"""Return 0x-prefixed hexidecimal representation of a JobID"""
return self.encode("hex")

@property
def dothex(self):
"""Return dotted hexidecimal representation of a JobID"""
return self.encode("dothex")

@property
def words(self):
"""Return words (mnemonic) representation of a JobID"""
return self.encode("words")

@property
def kvs(self):
"""Return KVS directory path of a JobID"""
return self.encode("kvs")

def __str__(self):
return self.encode("f58")

def __repr__(self):
return f"JobID({self.dec})"

0 comments on commit e31fab0

Please sign in to comment.