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

Allow representing paths as pathlib.Path #283

Open
bkeryan opened this issue Jun 8, 2023 · 2 comments
Open

Allow representing paths as pathlib.Path #283

bkeryan opened this issue Jun 8, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@bkeryan
Copy link
Collaborator

bkeryan commented Jun 8, 2023

Problem to Solve

Python 3.x has a standard data type for paths, pathlib.Path, but we are not using it. Specifying that has a configuration parameter has a data type of ni_measurementlink_service.DataType.Path yields a str, not a pathlib.Path.

Proposed Solution

Interpret ni_measurementlink_service.DataType.Path as pathlib.Path, possibly with a opt-in for compatibility.

AB#2414585

@bkeryan
Copy link
Collaborator Author

bkeryan commented Sep 1, 2023

How does this work for enums?

@measurement_service.configuration(
    "measurement_type", nims.DataType.Enum, Function.DC_VOLTS, enum_type=Function
)

enum_type is used to build the annotations dictionary, but it's not actually used to construct enum values: https://github.com/ni/measurementlink-python/blob/main/ni_measurementlink_service/measurement/service.py#L309

Instead, we use type(parameter_metadata.default_value) to get the enum type: https://github.com/ni/measurementlink-python/blob/main/ni_measurementlink_service/_internal/parameter/serializer.py#L249

We could use the same approach to get the path type:

# use str
@measurement_service.configuration("levels_file_path", nims.DataType.Path, "PinLevels.digilevels")

# use pathlib.Path
@measurement_service.configuration("levels_file_path", nims.DataType.Path, pathlib.Path("PinLevels.digilevels"))

@bkeryan
Copy link
Collaborator Author

bkeryan commented Sep 1, 2023

This approach would not work for path arrays when the default value is an empty list, because there is no 1st element from which to infer the element type. See #366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant