Skip to content

Commit

Permalink
Refactor Readme based on review comment on internal drop. (#43)
Browse files Browse the repository at this point in the history
* Update the pywin32 to 303 version and update the readme with minro refactoring

* Move examples to top and change  Managing Measurement as Python Package(Project) as Appendix based on comments on internal drop.

* Update the Build number of package to 1. Since build number should start with 1.

* Removed poetry option from the quick start based on comments from review comment on the internal drop.

* Finalize Python Readme based on comments from internal drop.

* Minor Refactors.

* Remove the Template Support section.

* Update the command in Contributing.md
  • Loading branch information
Vasantha-Kumar-J authored Apr 1, 2022
1 parent 4fe3018 commit e44c753
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 84 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ git clone https://github.com/ni/measurement-services-python.git

## Initializing the repo with .venv

From the root directory of the repo, initialize the project using the [poetry init](https://python-poetry.org/docs/cli/#init) command. This will set up a .venv with all the required dependencies based on poetry.lock file and pyproject.toml.
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.

```cmd
poetry init
Expand Down
143 changes: 74 additions & 69 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,87 @@
- [Introduction](#introduction)
- [Abbreviations](#abbreviations)
- [Dependencies](#dependencies)
- [Quick Start](#quick-start)
- [Examples](#examples)
- [Setting up the Example Measurements](#setting-up-the-example-measurements)
- [Executing the Example Measurements](#executing-the-example-measurements)
- [Developing Measurements: Quick Start](#developing-measurements-quick-start)
- [Installation](#installation)
- [Developing a minimal python measurement](#developing-a-minimal-python-measurement)
- [Steps to run the measurement service](#steps-to-run-the-measurement-service)
- [Managing Measurement as Python Package(Project)](#managing-measurement-as-python-packageproject)
- [Steps to run/debug the measurement service](#steps-to-rundebug-the-measurement-service)
- [Appendix: Managing Measurement as Python Package(Project)](#appendix-managing-measurement-as-python-packageproject)
- [Create and Manage Python Measurement Package using poetry](#create-and-manage-python-measurement-package-using-poetry)
- [Create and Manage Python Measurement Package using venv](#create-and-manage-python-measurement-package-using-venv)
- [Create and Manage Python Measurement Package by directly installing NIMS as a system-level package](#create-and-manage-python-measurement-package-by-directly-installing-nims-as-a-system-level-package)
- [Examples](#examples)
- [Setting up the Example Measurements](#setting-up-the-example-measurements)
- [Executing the Example Measurements](#executing-the-example-measurements)

---

## Introduction

`ni_measurement_service` is a python framework that enables measurement developers to quickly create python measurements and run them as a service(gRPC).
The `ni_measurement_service` is a python framework that enables measurement developers to quickly create python measurements and run them as a service(gRPC).

---

## Abbreviations

- NIMS - Nationals Instrument Measurement Service Framework - `ni_measurement_service`.
- NIMS - NI Measurement Service Framework - `ni_measurement_service`.

---

## Dependencies

- [Python >= 3.8( 3.8 recommended)](https://www.python.org/downloads/release/python-3810/)
- Python >= 3.8 [(3.8 recommended)](https://www.python.org/downloads/release/python-3810/)
- [grpcio = 1.41.1](https://pypi.org/project/grpcio/1.41.1/)
- [protobuf = 3.19.1](https://pypi.org/project/protobuf/3.19.1/)
- [pywin32 >= 303 (Only for Windows)](https://pypi.org/project/pywin32/303/)

---

## Quick Start
## Examples

### Installation
The `measurement-services-python\examples` directory contains the below list of python measurement example projects:

Download the `ni_measurement_service.tar.gz` and install the NIMS Framework.
1. **Sample measurement**: Sample Measurement is a simple python-based example that has configurations defined for all supported data types. The measurement logic simply assigns the configuration values to respective output values.
2. **DC Measurements**: Simple python measurement example that interacts with DCPower 4145 Instrument.
1. DC Measurement with Screen file UI
2. DC Measurement with LabVIEW UI

If using [pip](https://pip.pypa.io/).
### Setting up the Example Measurements

``` cmd
REM Activate the required virtual environment if any.
pip install <path_of_ni_measurement_service-x.x.x.tar.gz>
```
The example measurements shared are *poetry-based* projects. Follow the below steps to for setting up the example measurement:

1. Install `poetry`. Refer to <https://python-poetry.org/docs/#installation> for information on installing poetry.

2. Open a command prompt, and change the working directory to the directory of the example measurement you want to work with.

If using [poetry](https://python-poetry.org/) to manage a python project.
``` cmd
cd <path_of_example_measurement>
REM Example: cd "..\measurement-services-python\examples\dc_measurement"
```
3. Run poetry install. The command creates/updates the .venv and installs all the dependencies(including `ni_measurement_service` package) needed for the Example into `.venv`
``` cmd
poetry install
```
### Executing the Example Measurements
1. Start the discovery service if not already started.
2. Run/Debug the measurement file (`measurement.py`) after activating the `.venv`. For detailed info check the section ["Steps to run/debug the measurement service".](#steps-to-rundebug-the-measurement-service)
---
## Developing Measurements: Quick Start
This section provides instructions to develop custom python measurement services using NIMS.
### Installation
Make sure the system has the recommended python version is installed. Download the `ni_measurement_service-x.x.x.x.tar.gz` and install the NIMS Framework using [pip](https://pip.pypa.io/).
``` cmd
REM Run the command from within the poetry project directory.
poetry add <path_of_ni_measurement_service-x.x.x.tar.gz>
REM Activate the required virtual environment if any.
pip install <path_of_ni_measurement_service-x.x.x.tar.gz>
```

### Developing a minimal python measurement
Expand All @@ -78,9 +107,9 @@ poetry add <path_of_ni_measurement_service-x.x.x.tar.gz>
product_type="", # The Product Type related to the measurement.
# Absolute file path of the UI File.
ui_file_path="",
# Developer can construct related this .py file like this:
# Developer can construct relative path w.r.t the .py file like this:
# ui_file_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "FileName.isscr")
ui_file_type="", # Type of UI File.
ui_file_type=nims.UIFileType.ScreenFile, # Type of UI File, use UIFileType Enum.
)

service_info = nims.ServiceInfo(
Expand All @@ -90,7 +119,7 @@ poetry add <path_of_ni_measurement_service-x.x.x.tar.gz>
)
```

4. Create a new `MeasurementService` Instance.
4. Create a new `MeasurementService` instance.

``` python
foo_measurement_service = nims.MeasurementService(measurement_info, service_info)
Expand Down Expand Up @@ -151,57 +180,67 @@ poetry add <path_of_ni_measurement_service-x.x.x.tar.gz>
foo_measurement_service.close_service()
```

### Steps to run the measurement service
9. Run/Debug the created measurement by following the steps discussed in the section ["Steps to run/debug the measurement service".](#steps-to-rundebug-the-measurement-service)

---

## Steps to run/debug the measurement service

1. Start the discovery service if not already started.

2. Activate related virtual environments. Measurement developers can skip this step if they are not using any virtual environments or poetry-based projects.
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)

```cmd
.venv\scripts\activate
```

- After successful activation, you can see the name of the environment, `(.venv)` is added to the command prompt.
- If you face an access issue when trying to activate, retry after allowing scripts to run as Administrator by executing the below command in Windows PowerShell:

```cmd
Set-ExecutionPolicy RemoteSigned
```

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 created using NIMS
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 created using NIMS.

4. To stop the running measurement service, press `Enter` in the terminal to properly close the service.

5. After the usage of measurement, deactivate the virtual environment. Measurement developers can skip this step if they are not using any virtual environments or poetry-based projects.
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)

```cmd
deactivate
```

---

## Managing Measurement as Python Package(Project)
## Appendix: Managing Measurement as Python Package(Project)

Measurement and its related files can be maintained as a python package. The basic Components of any Python Measurement Package are:
Measurement and its related files can be maintained as a python package. The basic components of any Python Measurement Package are:

1. Measurement Python Module(.py file)
- This file contains all the details related to the measurement and also contains the logic for the measurement execution.
- This file is run to start the measurement as a service.

2. UI File
- UI file for the Measurement. Type of Supported UI Files are:
- UI file for the Measurement. Types of supported UI file are:
- Screen file(.isscr): created using the **Plugin UI Editor application**.
- LabVIEW UI(.vi)
- The path and type of this file is configured by `ui_file_path` and `ui_file_type` respectively in `measurement_info` variable definition in Measurement Python Module(.py file).

Python communities have different ways of managing a python package and its 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.

Note: Once we have the template support for Python measurement, the approach to managing the python measurement package(project) will be streamlined and simplified.

### Create and Manage Python Measurement Package using poetry

1. Setting up Poetry(One-time setup)
1. Make sure the system has the recommended python version installed.
1. Make sure the system has the recommended python version is installed.

2. Install `poetry` using the installation steps given in <https://python-poetry.org/docs/#installation>.

2. Create a new python project and add NIMS Framework as a dependency to the project.

1. Open a command prompt, change the working directory to the directory of your choice where you want to create the project.
1. Open a command prompt, and change the working directory to the directory of your choice where you want to create the project.

``` cmd
cd <path_of_directory_of_your_choice>
Expand Down Expand Up @@ -233,9 +272,9 @@ For detailed info on managing projects using poetry [refer to the official docum

### Create and Manage Python Measurement Package using venv

1. Make sure the system has the recommended python version installed.
1. Make sure the system has the recommended python version is installed.

2. Open a command prompt, change the working directory to the directory of your choice where you want to create a project.
2. Open a command prompt, and change the working directory to the directory of your choice where you want to create a project.

``` cmd
cd <path_of_directory_of_your_choice>
Expand Down Expand Up @@ -281,40 +320,6 @@ Measurement developers can also install the NIMS framework as a system package i
pip install <path_of_ni_measurement_service-x.x.x.tar.gz>
```

2. Create measurement modules as described in ["Developing a minimal python measurement"]

---

## Examples

`measurement-services-python\examples` contains the below list of python measurement example projects:
1. **Sample measurement**: Sample Measurement is a simple python-based example that has configurations defined for all supported data types. The measurement logic simply assigns the configuration values to respective output values.
2. **DC Measurements**: Simple python measurement example that interacts with DCPower 4145 Instrument.
1. DC Measurement with Screen file UI
2. DC Measurement with LabVIEW UI

### Setting up the Example Measurements

The example measurements shared are based on poetry. Follow the below steps to for setting up the example measurement:

1. Install `poetry` if not already installed. Refer to <https://python-poetry.org/docs/#installation> for information on installing poetry.

2. Open a command prompt, change the working directory to the directory of the example measurement you want to work with.

``` cmd
cd <path_of_example_measurement>
REM Example: cd "..\measurement-services-python\examples\dc_measurement"
```

3. Run poetry install. The command creates/updates the .venv and installs all the dependencies needed for the Example into `.venv`

``` cmd
poetry install
```

### Executing the Example Measurements

1. Run/Debug the measurement(`measurement.py`) by following the steps discussed in the section ["Steps to run the measurement service".](#steps-to-run-the-measurement-service)
2. Create measurement modules as described in ["Developing a minimal python measurement"](#developing-a-minimal-python-measurement)

---
26 changes: 14 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude = '''

[tool.poetry]
name = "ni_measurement_service"
version = "0.5.0.0"
version = "0.5.0.1"
description = "Develop language agnostic measurement plugins reusable by both the Interactive Debugging/Validation and Test Automation workflow."
authors = ["NationalInstruments"]
repository = "https://github.com/ni/measurement-services-python/"
Expand All @@ -20,7 +20,7 @@ repository = "https://github.com/ni/measurement-services-python/"
python = "^3.8"
grpcio = "1.41.1"
protobuf = "3.19.1"
pywin32 = {version = "301", platform = "win32"}
pywin32 = {version = "^303", platform = "win32"}

[tool.poetry.dev-dependencies]
pytest = "^5.2"
Expand Down

0 comments on commit e44c753

Please sign in to comment.