Skip to content
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
18 changes: 0 additions & 18 deletions Pipfile

This file was deleted.

296 changes: 0 additions & 296 deletions Pipfile.lock

This file was deleted.

80 changes: 72 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,84 @@ requires = [
"packaging>=21.3"
]

[tool.flake8]
filename = ["*.py", "*.pyx", "*.pxd"]
max-line-length = 80
exclude = [
".git",
"__pycache__",
[project]
name = "pyslurm"
dynamic = ["version"]
license = "GPL-2.0-only"
description = "Python Interface for Slurm"
readme = "README.md"
requires-python = ">=3.6"
authors = [
{ name = "Mark Roberts" },
{ name = "Giovanni Torres" },
{ name = "Toni Harzendorf" },
]
maintainers = [
{ name = "Toni Harzendorf", email = "toni.harzendorf@gmail.com" },
]
keywords = [
"HPC",
"Batch Scheduler",
"Resource Manager",
"Slurm",
"Cython",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Natural Language :: English",
"Operating System :: POSIX :: Linux",
"Programming Language :: Cython",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Distributed Computing",
]

[project.urls]
Homepage = "https://github.com/PySlurm/pyslurm"
Repository = "https://github.com/PySlurm/pyslurm"
Issues = "https://github.com/PySlurm/pyslurm/issues"
Discussions = "https://github.com/PySlurm/pyslurm/discussions"

[project.optional-dependencies]
dev = [
"ruff",
"cython-lint",
"pytest",
"pytest-sugar",
]

[tool.setuptools.dynamic]
version = { attr = "pyslurm.version.__version__" }

[tool.setuptools.packages.find]
include = ["pyslurm*"]

[tool.ruff]
line-length = 80
extend-exclude = [
".eggs",
"*.egg",
"build",
"tests",
"examples",
"scripts",
]
extend-ignore = ["E203", "E901", "E225", "E226", "E227", "E999"]

[tool.ruff.lint]
extend-ignore = ["E203", "E225", "E226", "E227"]

[tool.ruff.lint.isort]

[tool.cython-lint]
max-line-length = 80
Expand Down
35 changes: 21 additions & 14 deletions scripts/griffe_exts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,30 @@
SLURM_DOCS_URL_BASE = "https://slurm.schedmd.com/archive"
SLURM_DOCS_URL_VERSIONED = f"{SLURM_DOCS_URL_BASE}/slurm-{SLURM_VERSION}-latest"

config_files = ["acct_gather.conf",
"slurm.conf",
"cgroup.conf",
"mpi.conf",
"scontrol"]
config_files = [
"acct_gather.conf",
"slurm.conf",
"cgroup.conf",
"mpi.conf",
"scontrol",
]


def replace_with_slurm_docs_url(match):
first_part = match.group(1)
second_part = match.group(2)
ref = f"[{first_part}{second_part}]"
return f'{ref}({SLURM_DOCS_URL_VERSIONED}/{first_part}.html{second_part})'
return f"{ref}({SLURM_DOCS_URL_VERSIONED}/{first_part}.html{second_part})"


pattern = re.compile(
r'\{('
+ '|'.join([re.escape(config) for config in config_files])
+ r')' # Match the first word before "#"
+ r'([#][^}]+)\}' # Match "#" and everything after it until }
r"\{("
+ "|".join([re.escape(config) for config in config_files])
+ r")" # Match the first word before "#"
+ r"([#][^}]+)\}" # Match "#" and everything after it until }
)


# This class is inspired from here, with a few adaptions:
# https://github.com/mkdocstrings/griffe/blob/97f3613c5f0ae5653e8b91479c716b9ec44baacc/docs/guide/users/extending.md#full-example
#
Expand All @@ -70,8 +73,11 @@ def replace_with_slurm_docs_url(match):
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
class DynamicDocstrings(griffe.Extension):
def __init__(self, include_paths: list[str] | None = None,
ignore_paths: list[str] | None = None) -> None:
def __init__(
self,
include_paths: list[str] | None = None,
ignore_paths: list[str] | None = None,
) -> None:

self.include_paths = include_paths
self.ignore_paths = ignore_paths
Expand All @@ -84,8 +90,9 @@ def on_instance(
**kwargs,
) -> None:

if ((self.include_paths and obj.path not in self.include_paths)
or (self.ignore_paths and obj.path in self.ignore_paths)):
if (self.include_paths and obj.path not in self.include_paths) or (
self.ignore_paths and obj.path in self.ignore_paths
):
return

try:
Expand Down
29 changes: 19 additions & 10 deletions scripts/pyslurm_bindgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
import click
from datetime import datetime
import os
import re
import pathlib
from collections import OrderedDict

UINT8_RANGE = range((2**8))
UINT16_RANGE = range((2**16))
UINT32_RANGE = range((2**32))
UINT64_RANGE = range((2**64))
INT8_RANGE = range(-128, 127+1)
INT8_RANGE = range(-128, 127 + 1)

# TODO: also translate slurm enums automatically as variables like:
# <ENUM-NAME> = slurm.<ENUM_NAME>


def get_data_type(val):
if val in UINT8_RANGE:
return "uint8_t"
Expand Down Expand Up @@ -67,14 +67,14 @@ def capture_copyright(hdr_file):

def try_get_macro_value(s):
if s.startswith("SLURM_BIT"):
val = int(s[s.find("(")+1:s.find(")")])
val = int(s[s.find("(") + 1 : s.find(")")])
return 1 << val

if s.startswith("0x"):
return int(s, 16)

if s.startswith("(0x"):
_s = s[s.find("(")+1:s.find(")")]
_s = s[s.find("(") + 1 : s.find(")")]
return int(_s, 16)

try:
Expand Down Expand Up @@ -103,7 +103,10 @@ def translate_slurm_header(hdr_dir, hdr):
macros = "".join(translate_hdr_macros(lines, hdr))

c = click.get_current_context()
if c.params["show_unparsed_macros"] or c.params["generate_python_const"]:
if (
c.params["show_unparsed_macros"]
or c.params["generate_python_const"]
):
return

codegen = autopxd.AutoPxd("slurm/" + hdr)
Expand Down Expand Up @@ -204,7 +207,7 @@ def translate_hdr_macros(s, hdr):
unknown = []
for line in s:
if line.startswith("#define"):
name, ty = parse_macro(line.rstrip('\n'), hdr)
name, ty = parse_macro(line.rstrip("\n"), hdr)
if ty:
vals.update({name: ty})
elif name and not ty:
Expand All @@ -226,13 +229,14 @@ def translate_hdr_macros(s, hdr):
print("{} = slurm.{}".format(name, name))
else:
hdr_file = "slurm/" + hdr
out.append(f"cdef extern from \"{hdr_file}\":\n")
out.append(f'cdef extern from "{hdr_file}":\n')
out.append("\n")
for name, ty in vals.items():
out.append(f" {ty} {name}\n")

return out


def setup_include_path(hdr_dir):
include_dir = pathlib.Path(hdr_dir).parent.as_posix()
if not os.environ.get("C_INCLUDE_PATH", None):
Expand Down Expand Up @@ -277,13 +281,18 @@ def setup_include_path(hdr_dir):
is_flag=True,
help="Instead of writing everything to files, just print to stdout.",
)
def main(slurm_header_dir, show_unparsed_macros,
generate_python_const, output_dir, stdout):
def main(
slurm_header_dir,
show_unparsed_macros,
generate_python_const,
output_dir,
stdout,
):
setup_include_path(slurm_header_dir)
translate_slurm_header(slurm_header_dir, "slurm_errno.h")
translate_slurm_header(slurm_header_dir, "slurm.h")
translate_slurm_header(slurm_header_dir, "slurmdb.h")


if __name__ == '__main__':
if __name__ == "__main__":
main()
9 changes: 0 additions & 9 deletions setup.cfg

This file was deleted.

Loading