Skip to content
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

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

Open
bkeryan opened this issue Apr 18, 2023 · 0 comments
Open

Comments

@bkeryan
Copy link
Contributor

bkeryan commented Apr 18, 2023

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants