Skip to content

SRC/API/PYTHON: add pylint checks in CI #658

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

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
84f51a2
PYPROJECT.TOML: added pylint configuration
roiedanino Jul 28, 2025
070cdde
SRC/API/PYTHON: fix pylint warnings in src, examples and tests
roiedanino Aug 3, 2025
f5c7827
EXAMPLES/PYTHON: fixed formatting
roiedanino Aug 3, 2025
f221647
EXAMPLES/PYTHON: added missing copyrights, mypy config
roiedanino Aug 4, 2025
f7ca214
PYPROJECT.TOML: True -> true
roiedanino Aug 4, 2025
88159e7
EXAMPLES/PYTHON: added blank line
roiedanino Aug 4, 2025
f3e932d
SRC/API/PYTHON: changed backends param type to Optional
roiedanino Aug 4, 2025
502dd48
SRC/API/PYTHON: formatting
roiedanino Aug 4, 2025
14015bd
.PRE-COMMIT-CONFIG.YAML: added pylint to pre-commit
roiedanino Aug 4, 2025
63d2dd4
.PRE-COMMIT-CONFIG: formatting
roiedanino Aug 4, 2025
c89f3fb
PYPROJECT.TOML: fix pylint import issues in CI
roiedanino Aug 4, 2025
ae9ec1d
.GITLAB: fixed import issue
roiedanino Aug 5, 2025
82dc3a9
PYPROJECT.TOML: reverted ignore-modules
roiedanino Aug 6, 2025
30c0e93
EXAMPLES/PYTHON: changed relative import in examples to examples.python
roiedanino Aug 6, 2025
92d4c7c
EXAMPLES/PYTHON: fixed import order
roiedanino Aug 6, 2025
8f4c735
EXAMPLES/PYTHON: fixed import order again
roiedanino Aug 6, 2025
ac1c86a
.PRE_COMMIT-CONFIG: add . to dependencies for pylint
roiedanino Aug 6, 2025
b167c98
.PRE_COMMIT-CONFIG: add source roots to dependencies for pylint
roiedanino Aug 6, 2025
c8087a0
.PRE_COMMIT-CONFIG: fix import issues in pylint - another try
roiedanino Aug 6, 2025
67d1866
.PRE-COMMIT-CONFIG: pip install before running pre-commit to recogniz…
roiedanino Aug 7, 2025
ce5b87c
.GITHUB/WORKFLOWS: trying adding nixl to the path without installing it
roiedanino Aug 7, 2025
4299b06
.GITHUB/WORKFLOWS: trying adding nixl to PYTHONPATH
roiedanino Aug 7, 2025
b8436a9
.GITLAB: add pylint checks in test_python.sh instead as nixl package …
roiedanino Aug 7, 2025
264c505
EXAMPLES/PYTHON: fixed import issues
roiedanino Aug 11, 2025
97d0d49
TEST/PYTHON: added __init__.py files to fix imports
roiedanino Aug 11, 2025
2a5f5d4
EXAMPLES/PYTHON: fixed import issues
roiedanino Aug 11, 2025
e3496ae
EXAMPLES/PYTHON: import ordering
roiedanino Aug 11, 2025
748bfce
Merge branch 'main' into pylint-ci-fixed
roiedanino Aug 11, 2025
eaaa862
EXAMPLES/PYTHON: fixed formatting
roiedanino Aug 11, 2025
99603fb
EXAMPLES/PYTHON: fixed more pylint issues from upstream
roiedanino Aug 11, 2025
76334e8
EXAMPLES/PYTHON: formatting
roiedanino Aug 11, 2025
79ea489
EXAMPLE/PYTHON: removed a blank line
roiedanino Aug 11, 2025
2f9ad2d
.GITLAB: fixed paths on pylint execution
roiedanino Aug 11, 2025
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
13 changes: 6 additions & 7 deletions .gitlab/test_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ etcd --listen-client-urls ${NIXL_ETCD_ENDPOINTS} --advertise-client-urls ${NIXL_
sleep 5

echo "==== Running python tests ===="
python3 examples/python/nixl_api_example.py
python3 examples/python/partial_md_example.py
python3 examples/python/partial_md_example.py --etcd
python3 -m examples.python.nixl_api_example
python3 -m examples.python.partial_md_example
python3 -m examples.python.partial_md_example --etcd
pytest test/python

python3 test/python/prep_xfer_perf.py list
Expand All @@ -75,11 +75,10 @@ python3 test/python/prep_xfer_perf.py array
echo "==== Running python examples ===="
blocking_send_recv_port=$(get_next_tcp_port)

cd examples/python
python3 blocking_send_recv_example.py --mode="target" --ip=127.0.0.1 --port="$blocking_send_recv_port"&
python3 -m examples.python.blocking_send_recv_example --mode="target" --ip=127.0.0.1 --port="$blocking_send_recv_port"&
sleep 5
python3 blocking_send_recv_example.py --mode="initiator" --ip=127.0.0.1 --port="$blocking_send_recv_port"
python3 -m examples.python.blocking_send_recv_example --mode="initiator" --ip=127.0.0.1 --port="$blocking_send_recv_port"

python3 query_mem_example.py
python3 -m examples.python.query_mem_example

pkill etcd
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ repos:
args: ["--max-line-length=88", "--select=C,E,F,W,B,B950", "--extend-ignore=E203,E501,W503"]
types_or: [python, cython]

- repo: https://github.com/pylint-dev/pylint
rev: v3.3.7
hooks:
- id: pylint
args: []
additional_dependencies: [torch, numpy, pytest]
types_or: [python, cython]

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
Expand Down
14 changes: 14 additions & 0 deletions examples/python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need to run with python -m ?

Copy link
Contributor Author

@roiedanino roiedanino Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise relative imports won't work - from . import util

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems wait_for_transfer_completion is used only in 2 place so maybe just keep it as is without introducing utilities module?

Copy link
Contributor Author

@roiedanino roiedanino Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we would need to import the other module in the same way to avoid that code duplication. If you meant leaving the code duplication as it was, I don't think we want to suppress those pylint warnings.

Maybe I'll try using full path import instead

# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
18 changes: 13 additions & 5 deletions examples/python/blocking_send_recv_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
# limitations under the License.

import argparse
import enum
import sys

import torch

from nixl._api import nixl_agent, nixl_agent_config


class BlockingSendRecvErrCodes(enum.Enum):
MEM_REG_FAILED = 1
TRANSFER_FAILED = 2
DATA_VERIFICATION_FAILED = 3


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str, required=True)
Expand Down Expand Up @@ -63,7 +71,7 @@ def parse_args():
reg_descs = agent.register_memory(tensors)
if not reg_descs: # Same as reg_descs if successful
print("Memory registration failed.")
exit()
sys.exit(BlockingSendRecvErrCodes.MEM_REG_FAILED.value)

# Target code
if args.mode == "target":
Expand Down Expand Up @@ -113,25 +121,25 @@ def parse_args():

if not xfer_handle:
print("Creating transfer failed.")
exit()
sys.exit(BlockingSendRecvErrCodes.TRANSFER_FAILED.value)

state = agent.transfer(xfer_handle)
if state == "ERR":
print("Posting transfer failed.")
exit()
sys.exit(BlockingSendRecvErrCodes.TRANSFER_FAILED.value)
while True:
state = agent.check_xfer_state(xfer_handle)
if state == "ERR":
print("Transfer got to Error state.")
exit()
sys.exit(BlockingSendRecvErrCodes.TRANSFER_FAILED.value)
elif state == "DONE":
break

# Verify data after read
for i, tensor in enumerate(tensors):
if not torch.allclose(tensor, torch.ones(10)):
print(f"Data verification failed for tensor {i}.")
exit()
sys.exit(BlockingSendRecvErrCodes.DATA_VERIFICATION_FAILED.value)
print(f"{args.mode} Data verification passed - {tensors}")

if args.mode != "target":
Expand Down
41 changes: 19 additions & 22 deletions examples/python/nixl_api_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,26 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import os
import sys

import numpy as np
import torch

import nixl._utils as nixl_utils
from nixl._api import nixl_agent, nixl_agent_config

from . import util


class NixlApiExampleErrCodes(enum.Enum):
CREATE_TRANSFER_FAILED = 1
PREP_TRANSFER_SIDE_HANDLES_FAILED = 2
MAKE_PREPPED_TRANSFER_FAILED = 3
TRANSFER_FAILED = 4


if __name__ == "__main__":
buf_size = 256
# Allocate memory and register with NIXL
Expand Down Expand Up @@ -104,30 +116,15 @@
)
if not xfer_handle_1:
print("Creating transfer failed.")
exit()
sys.exit(NixlApiExampleErrCodes.CREATE_TRANSFER_FAILED.value)

# test multiple postings
for _ in range(2):
state = nixl_agent2.transfer(xfer_handle_1)
assert state != "ERR"

target_done = False
init_done = False

while (not init_done) or (not target_done):
if not init_done:
state = nixl_agent2.check_xfer_state(xfer_handle_1)
if state == "ERR":
print("Transfer got to Error state.")
exit()
elif state == "DONE":
init_done = True
print("Initiator done")

if not target_done:
if nixl_agent1.check_remote_xfer_done("initiator", b"UUID1"):
target_done = True
print("Target done")
util.wait_for_transfer_completion(
nixl_agent2, nixl_agent1, xfer_handle_1, b"UUID1"
)

# prep transfer mode
local_prep_handle = nixl_agent2.prep_xfer_dlist(
Expand Down Expand Up @@ -165,11 +162,11 @@
)
if not local_prep_handle or not remote_prep_handle:
print("Preparing transfer side handles failed.")
exit()
sys.exit(NixlApiExampleErrCodes.PREP_TRANSFER_SIDE_HANDLES_FAILED.value)

if not xfer_handle_2:
print("Make prepped transfer failed.")
exit()
sys.exit(NixlApiExampleErrCodes.MAKE_PREPPED_TRANSFER_FAILED.value)

state = nixl_agent2.transfer(xfer_handle_2)
assert state != "ERR"
Expand All @@ -184,7 +181,7 @@
state = nixl_agent2.check_xfer_state(xfer_handle_2)
if state == "ERR":
print("Transfer got to Error state.")
exit()
sys.exit(NixlApiExampleErrCodes.TRANSFER_FAILED.value)
elif state == "DONE":
init_done = True
print("Initiator done")
Expand Down
20 changes: 15 additions & 5 deletions examples/python/nixl_gds_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import enum
import os
import sys

import nixl._utils as nixl_utils
from nixl._api import nixl_agent, nixl_agent_config


class NixlGdsExampleErrCodes(enum.Enum):
MISSING_FILE_PATH = 1
CREATE_TRANSFER_FAILED = 2
TRANSFER_FAILED = 3
INIT_XFER_FAILED = 4
DATA_VERIFICATION_FAILED = 5


if __name__ == "__main__":
buf_size = 16 * 4096
# Allocate memory and register with NIXL

if len(sys.argv) < 2:
print("Please specify file path in argv")
exit(0)
sys.exit(NixlGdsExampleErrCodes.MISSING_FILE_PATH.value)

print("Using NIXL Plugins from:")
print(os.environ["NIXL_PLUGIN_DIR"])
Expand Down Expand Up @@ -79,7 +89,7 @@
)
if not xfer_handle_1:
print("Creating transfer failed.")
exit()
sys.exit(NixlGdsExampleErrCodes.CREATE_TRANSFER_FAILED.value)

state = nixl_agent1.transfer(xfer_handle_1)
assert state != "ERR"
Expand All @@ -90,7 +100,7 @@
state = nixl_agent1.check_xfer_state(xfer_handle_1)
if state == "ERR":
print("Transfer got to Error state.")
exit()
sys.exit(NixlGdsExampleErrCodes.TRANSFER_FAILED.value)
elif state == "DONE":
done = True
print("Initiator done")
Expand All @@ -101,7 +111,7 @@
)
if not xfer_handle_2:
print("Creating transfer failed.")
exit()
sys.exit(NixlGdsExampleErrCodes.INIT_XFER_FAILED.value)

state = nixl_agent1.transfer(xfer_handle_2)
assert state != "ERR"
Expand All @@ -112,7 +122,7 @@
state = nixl_agent1.check_xfer_state(xfer_handle_2)
if state == "ERR":
print("Transfer got to Error state.")
exit()
sys.exit(NixlGdsExampleErrCodes.TRANSFER_FAILED.value)
elif state == "DONE":
done = True
print("Initiator done")
Expand Down
Loading