ni / ni/nimi-python

nimi-python functions that take paths do not accept `pathlib.Path` objects

Open
#1,949 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
128
Forks
110
Avg merge
5d 14h
Merged PRs (30d)
10

Description

Description of issue

nimi-python has a number of API functions that take paths, such as import_attribute_configuration_file and nidigital's load_pin_map, load_specifications_levels_and_timing, and load_pattern.

Most of these only accept str. Some also accept Iterable[str].

pathlib has been part of the Python standard library since Python 3.4, so it would be nice if nimi-python supported it.

System report

python -c "import nidigital; nidigital.print_diagnostic_information()" output

OS:
    Name:      Windows
    Version:   10.0.19045
    Bits:      64
Driver:
    Name:      NI-Digital Pattern Driver
    Version:   Unknown
Module:
    Name:      nidigital
    Version:   1.4.4
Python:
    Version:   3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]
    Bits:      64
    Is_Venv:   True
    Installed Packages:
        click==8.1.3
        colorama==0.4.6
        grpcio==1.53.0
        hightime==0.2.1
        mypy==1.2.0
        mypy-extensions==1.0.0
        ni-measurementlink-service==1.0.1
        nidigital==1.4.4
        nitclk==1.4.4
        pip==23.0.1
        protobuf==4.22.3
        pywin32==303
        setuptools==67.6.1
        tomli==2.0.1
        typing-extensions==4.5.0
        wheel==0.40.0
Steps to reproduce issue
  1. Run this on a system with an NI Digital Pattern instrument installed, using files from the LabVIEW SPI example:
import nidigital
import pathlib

session = nidigital.Session("DigitalPattern1")
session.load_pin_map(pathlib.Path("PinMap.pinmap"))
session.load_specifications_levels_and_timing(pathlib.Path("Specifications.specs"), pathlib.Path("PinLevels.digileve
ls"), pathlib.Path("Timing.digitiming"))

load_pin_map error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\dev\measurementlink-python\examples\nidigital_spi\.venv\lib\site-packages\nidigital\session.py", line 41, in aux
    return f(*xs, **kws)
  File "D:\dev\measurementlink-python\examples\nidigital_spi\.venv\lib\site-packages\nidigital\session.py", line 3683, in load_pin_map
    self._interpreter.load_pin_map(file_path)
  File "D:\dev\measurementlink-python\examples\nidigital_spi\.venv\lib\site-packages\nidigital\_library_interpreter.py", line 729, in load_pin_map
    file_path_ctype = ctypes.create_string_buffer(file_path.encode(self._encoding))  # case C020
AttributeError: 'WindowsPath' object has no attribute 'encode'

load_specifications_levels_and_timing error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\dev\measurementlink-python\examples\nidigital_spi\.venv\lib\site-packages\nidigital\session.py", line 41, in aux
    return f(*xs, **kws)
  File "D:\dev\measurementlink-python\examples\nidigital_spi\.venv\lib\site-packages\nidigital\session.py", line 3451, in load_specifications_levels_and_timing
    self._call_method_with_iterable(self._load_specifications, specifications_file_paths)
  File "D:\dev\measurementlink-python\examples\nidigital_spi\.venv\lib\site-packages\nidigital\session.py", line 3460, in _call_method_with_iterable
    for f in files:
TypeError: 'WindowsPath' object is not iterable
    ```

### Workaround

Call `str(...)` on `Path` objects before passing them to nimi-python.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in nidigital/session.py at load_pin_map and load_specifications_levels_and_timing, then follow their calls into nidigital/_library_interpreter.py. Reproduce the pathlib.Path failures from the issue and inspect the related path and iterable handling; done means the listed path-taking APIs accept pathlib.Path objects while preserving existing string and iterable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.