You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the root directory of the repo, initialize the project using the [poetry install](https://python-poetry.org/docs/cli/#install) command. This will set up a .venv with all the required dependencies based on poetry.lock file and pyproject.toml.
41
+
From the root directory of the repo, initialize the project using the [`poetry install`](https://python-poetry.org/docs/cli/#install) command. This will set up a virtual environment (`.venv`) with the required dependencies based on the `poetry.lock` file and `pyproject.toml`.
42
42
43
43
```cmd
44
-
poetry init
44
+
poetry install
45
45
```
46
46
47
47
## Ensure that the `./.venv` virtual environment is activated
48
48
49
49
- In the command prompt: `poetry shell`
50
-
- In the vscode ([link](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment))
51
-
-ALTERNATIVE: run commands with `poetry run`. i.e., `poetry run python measurement.py`
50
+
- In VS Code ([link](https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment))
51
+
-Alternative: run commands with `poetry run`. i.e., `poetry run python measurement.py`
52
52
53
53
# Adding dependencies
54
54
55
-
Add dependency package for `ni_measurementlink_service` using [poetry add](https://python-poetry.org/docs/cli/#add) command.
55
+
Add dependency package for `ni_measurementlink_service` using the [`poetry add`](https://python-poetry.org/docs/cli/#add) command.
# Updating gRPC stubs when a .proto file is modified
68
68
69
-
The `ni_measurementlink_service\_internal\stubs` directory contains the auto-generated python files based on MeasurementLink protobuf (.proto) files. The file needs to be replaced whenever there is a change to these .proto files:
69
+
The `ni_measurementlink_service\_internal\stubs` directory contains the auto-generated Python files based on MeasurementLink protobuf (`.proto`) files. The file needs to be replaced whenever there is a change to these `.proto` files:
@@ -76,9 +76,9 @@ The `ni_measurementlink_service\_internal\stubs` directory contains the auto-gen
76
76
- nidevice_grpc/README.md
77
77
- nidevice_grpc/session.proto
78
78
79
-
The latest .proto files are available in [Azure Repo](https://dev.azure.com/ni/DevCentral/_git/ASW?path=/Source/Protos). From the Azure Repo manually download and overwrite the proto files under the `ni_measurementlink_service\_internal\stubs\proto` folder.
79
+
The latest .proto files are available in [Azure Repo](https://dev.azure.com/ni/DevCentral/_git/ASW?path=/Source/Protos). From the Azure Repo manually download and overwrite the `.proto` files under the `ni_measurementlink_service\_internal\stubs\proto` folder.
80
80
81
-
Run `poetry run python scripts/generate_grpc_stubs.py`. This generates the required *.py file for the listed proto files. The required `grpcio-tools` package is already added as a development dependency in pyproject.toml.
81
+
Run `poetry run python scripts/generate_grpc_stubs.py`. This generates the required `.py` files for the listed `.proto` files. The required `grpcio-tools` package is already added as a development dependency in pyproject.toml.
82
82
83
83
# Lint and Build Code
84
84
@@ -100,7 +100,7 @@ Running this command from the repo's root directory will generate the tar.gz fil
100
100
101
101
# Testing
102
102
103
-
`ni-measurementlink-service` includes tests under the directory `tests\` that exercises the python and grpc modules. The GitHub CI run these tests for PRs targeting the main branch. It is recommended that during development you run the tests locally before creating a PR.
103
+
`ni-measurementlink-service` includes regression tests under the `tests/` directory. The GitHub CI runs these tests for PRs targeting the main branch. It is recommended that during development you run the tests locally before creating a PR.
104
104
105
105
In order to run the `ni-measurementlink-service` tests locally:
106
106
@@ -113,7 +113,7 @@ In order to run the `ni-measurementlink-service` tests locally:
113
113
(.venv) PS D:\TAF\measurementlink-python> poetry run pytest -v
114
114
```
115
115
116
-
## Using VS code Test Explorer extension(UI)
116
+
## Using VS Code Test Explorer extension(UI)
117
117
118
118
Install and configure the `Python Test Explorer for Visual Studio Code` extension to execute/debug the tests using UI. For more details related to the extension, refer [here](https://marketplace.visualstudio.com/items?itemName=LittleFoxTeam.vscode-python-test-adapter).
Copy file name to clipboardExpand all lines: README.md
+33-32Lines changed: 33 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,16 +13,16 @@
13
13
-[Create a batch file that runs a python measurement](#create-a-batch-file-that-runs-a-python-measurement)
14
14
-[Create Executable for Python Scripts](#create-executable-for-python-scripts)
15
15
-[API References](#api-references)
16
-
-[Appendix: Managing Measurement as Python Package(Project)](#appendix-managing-measurement-as-python-packageproject)
17
-
-[Create and Manage Python Measurement Package using poetry](#create-and-manage-python-measurement-package-using-poetry)
18
-
-[Create and Manage Python Measurement Package using venv](#create-and-manage-python-measurement-package-using-venv)
16
+
-[Appendix: Managing Measurement as Python Package(Project)](#appendix-managing-measurement-as-python-package-project)
17
+
-[Create and Manage Python Measurement Package using Poetry](#create-and-manage-python-measurement-package-using-poetry)
18
+
-[Create and Manage Python Measurement Package using `venv`](#create-and-manage-python-measurement-package-using-venv)
19
19
-[Create and Manage Python Measurement Package by directly installing `ni-measurementlink-service` as a system-level package](#create-and-manage-python-measurement-package-by-directly-installing-ni-measurementlink-service-as-a-system-level-package)
20
20
21
21
---
22
22
23
23
## Introduction
24
24
25
-
MeasurementLink Support for Python (`ni-measurementlink-service`) is a python framework that enables measurement developers to quickly create python measurements and run them as a service (gRPC).
25
+
MeasurementLink Support for Python (`ni-measurementlink-service`) is a Python framework that enables measurement developers to quickly create Python measurements and run them as a service (gRPC).
26
26
27
27
---
28
28
@@ -63,7 +63,7 @@ This section provides instructions to develop custom measurement services in Pyt
63
63
64
64
### Installation
65
65
66
-
Make sure the system has the recommended python version is installed. Install MeasurementLink Support for Python using [pip](https://pip.pypa.io/).
66
+
Make sure the system has the recommended Python version is installed. Install MeasurementLink Support for Python using [pip](https://pip.pypa.io/).
67
67
68
68
```cmd
69
69
REM Activate the required virtual environment if any.
@@ -76,7 +76,7 @@ Check if you have installed the expected version of MeasurementLink Support for
76
76
pip show ni-measurementlink-service
77
77
```
78
78
79
-
### Developing a minimal python measurement
79
+
### Developing a minimal Python measurement
80
80
81
81
1. Install the `ni-measurementlink-generator` package.
be placed in a new folder under the current directory
108
108
named after the display name without spaces.
109
109
110
-
3. To customize the created measurement, provide metadata of the measurement's configuration(input parameters) and outputs(output parameters) in `measurement.py`.
110
+
3. To customize the created measurement, provide metadata of the measurement's configuration(input parameters) and outputs(output parameters) in `measurement.py`.
111
111
1. Use the `configuration()` decorator to provide metadata about the configurations.**The order of the configuration decorator must match with the order of the parameters defined in the function signature.**
1. Start the discovery service ifnot already started.
142
142
143
-
2. (Optional)Activate related virtual environments. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)
143
+
2. (Optional)Activate related virtual environments. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)
3. [Run](https://code.visualstudio.com/docs/python/python-tutorial#_run-hello-world)/[Debug](https://code.visualstudio.com/docs/python/debugging#_basic-debugging) the measurement python file.
156
+
3. [Run](https://code.visualstudio.com/docs/python/python-tutorial#_run-hello-world)/[Debug](https://code.visualstudio.com/docs/python/debugging#_basic-debugging) the measurement Python file.
157
157
158
158
4. To stop the running measurement service, press `Enter`in the terminal to properly close the service.
159
159
160
-
5. (Optional)After the usage of measurement, deactivate the virtual environment. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)
160
+
5. (Optional)After the usage of measurement, deactivate the virtual environment. Measurement developers can skip this step if they are not using any [virtual environments](#create-and-manage-python-measurement-package-using-venv) or [poetry-based projects.](#create-and-manage-python-measurement-package-using-poetry)
161
161
162
162
```cmd
163
163
deactivate
@@ -179,7 +179,7 @@ To statically register a measurement service with the MeasurementLink discovery
179
179
180
180
Once your measurement service is statically registered, the MeasurementLink discovery service makes it visible in supported NI applications.
181
181
182
-
### Create a batch file that runs a python measurement
182
+
### Create a batch file that runs a Python measurement
183
183
184
184
The batch file used for static registration is responsible for starting the Python Scripts.
If copying or running a measurement service produces "File not found"or"No such file or directory" errors, make sure to [enable Win32 long paths](#enable-win32-long-paths). If you are unable to enable Win32 long paths, consider deploying the measurement service to a directory with a shorter path.
229
229
230
-
## Appendix: Managing Measurement as Python Package(Project)
230
+
## Appendix: Managing Measurement as Python Package(Project)
231
231
232
-
Measurement and its related files can be maintained as a python package. The basic components of any Python Measurement Package are:
232
+
Measurement and its related files can be maintained as a Python package. The basic components of any Python measurement package are:
233
233
234
-
1. Measurement Python Module(.py file)
234
+
1. Measurement Python module (`.py`file)
235
235
- This file contains all the details related to the measurement and also contains the logic for the measurement execution.
236
236
- This fileis run to start the measurement as a service.
237
237
238
238
2. UI File
239
-
-UIfilefor the Measurement. Types of supported UI files are:
240
-
- Measurement UI(.measui): created using the **Measurement UI Editor application**.
241
-
- LabVIEW UI(.vi)
242
-
- The path of this fileis configured by `ui_file_path`in`measurement_info` variable definition inMeasurement Python Module(.pyfile).
239
+
-UIfilefor the measurement. Types of supported UI files are:
240
+
- Measurement UI (`.measui`): created using the **Measurement UI Editor application**.
241
+
- LabVIEW UI (`.vi`)
242
+
- The path of this fileis configured by `ui_file_path`in`measurement_info` variable definition inmeasurement Python module (`.py`).
243
243
244
-
Python communities have different ways of managing a python package andits dependencies. It is up to the measurement developer, on how they wanted to maintain the package and dependencies. Measurement developers can choose from a few common approaches discussed below based on their requirements.
244
+
Python communities have different ways of managing Python packages andtheir dependencies. It is up to the measurement developer to decide how to maintain the package and dependencies. Measurement developers can choose from a few common approaches discussed below based on their requirements.
245
245
246
-
### Create and Manage Python Measurement Package using poetry
246
+
### Create and Manage Python Measurement Package using Poetry
247
247
248
-
1. Setting up Poetry(One-time setup)
249
-
1. Make sure the system has the recommended python version installed.
248
+
1. Install `poetry` (one-time setup)
250
249
251
-
2. Install the `poetry` using the installation steps given in<https://python-poetry.org/docs/#installation>.
250
+
1. Make sure the system has the recommended Python version installed.
252
251
253
-
2. Create a new python project and add `ni-measurementlink-service`as a dependency to the project.
252
+
2. Install `poetry` using the installation steps given in<https://python-poetry.org/docs/#installation>.
253
+
254
+
2. Create a new Python project and add `ni-measurementlink-service`as a dependency to the project.
254
255
255
256
1. Open a command prompt, and change the working directory to the directory of your choice where you want to create the project.
256
257
257
258
``` cmd
258
259
cd <path_of_directory_of_your_choice>
259
260
```
260
261
261
-
2. Create a python package(project) using the poetry new command. Poetry will create boilerplate files and folders that are commonly needed for a python project.
262
+
2. Create a Python package(project) using the `poetry new` command. Poetry will create boilerplate files and folders that are commonly needed for a Python project.
262
263
263
264
``` cmd
264
265
poetry new <name_of_the_project>
265
266
```
266
267
267
-
3. Add the `ni-measurementlink-service` package as a dependency using the [poetry add command](https://python-poetry.org/docs/cli/#add).
268
+
3. Add the `ni-measurementlink-service` package as a dependency using the [`poetry add`](https://python-poetry.org/docs/cli/#add) command.
268
269
269
270
``` cmd
270
271
cd <name_of_the_project>
@@ -273,7 +274,7 @@ Python communities have different ways of managing a python package and its depe
273
274
274
275
4. The virtual environment will be auto-created by poetry.
275
276
276
-
5. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)
277
+
5. Create measurement modules as described in ["Developing a minimal Python measurement"](#developing-a-minimal-python-measurement)
277
278
- Any additional dependencies required by measurement can be added using [add command](https://python-poetry.org/docs/cli/#add).
278
279
279
280
``` cmd
@@ -282,9 +283,9 @@ Python communities have different ways of managing a python package and its depe
282
283
283
284
For detailed info on managing projects using poetry [refer to the official documentation](https://python-poetry.org/docs/cli/).
284
285
285
-
### Create and Manage Python Measurement Package using venv
286
+
### Create and Manage Python Measurement Package using `venv`
286
287
287
-
1. Make sure the system has the recommended python version installed.
288
+
1. Make sure the system has the recommended Python version installed.
288
289
289
290
2. Open a command prompt, and change the working directory to the directory of your choice where you want to create a project.
290
291
@@ -313,14 +314,14 @@ For detailed info on managing projects using poetry [refer to the official docum
313
314
pip install ni-measurementlink-service
314
315
```
315
316
316
-
6. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)
317
+
6. Create measurement modules as described in ["Developing a minimal Python measurement"](#developing-a-minimal-python-measurement)
317
318
- Any additional dependencies required by measurement can be added pip install.
318
319
319
320
``` cmd
320
321
pip install <dependency_package_name>
321
322
```
322
323
323
-
For detailed info on managing projects with a virtual environment [refer to the official documentation](https://docs.python.org/3/tutorial/venv.html).
324
+
For detailed info on managing projects with a virtual environment, refer to the [official documentation](https://docs.python.org/3/tutorial/venv.html).
324
325
325
326
### Create and Manage Python Measurement Package by directly installing `ni-measurementlink-service` as a system-level package
326
327
@@ -332,6 +333,6 @@ Measurement developers can also install `ni-measurementlink-service` as a system
332
333
pip install ni-measurementlink-service
333
334
```
334
335
335
-
2. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)
336
+
2. Create measurement modules as described in ["Developing a minimal Python measurement"](#developing-a-minimal-python-measurement)
0 commit comments