Skip to content

Commit 9d58617

Browse files
authored
Use analyze-project from ni/python-actions (#1252)
* Use analyze-project from ni/python-actions * Add check docs. Add matrix checking for analyze-project * Minor cleanup * Only check for out-of-date stubs with oldest Python version * Fix traceloggingdynamic configuration * Fix _config typing * Fix _config typing * Fix lint error * Fix lint error * PR feedback from Brad * Remove unused comment. Re-lock service package * Fix check NIMS * Fix _config import error * Fix nps errors * Add all other exports to __all__ * Check docs at publish time. * Remove __all__ from _configuration.py * Remove fail-fast: false * Remove unneeded docstring * Remove unneeded docstring * Remove traceloggingdynamic and _tracelogging.py * Add 'checks_succeeded' job to summarize matrix from check NIMS and check NIMG * Add 'unit_tests_succeeded' job to summarize matrix unit test results
1 parent 193ecf4 commit 9d58617

File tree

9 files changed

+115
-293
lines changed

9 files changed

+115
-293
lines changed

.github/workflows/CI.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,31 @@ jobs:
1212
check_nims:
1313
name: Check NIMS
1414
uses: ./.github/workflows/check_nims.yml
15+
check_nims_docs:
16+
name: Check NIMS docs
17+
uses: ./.github/workflows/check_nims_docs.yml
1518
check_nimg:
1619
name: Check NIMG
1720
uses: ./.github/workflows/check_nimg.yml
21+
checks_succeeded:
22+
name: Checks succeeded
23+
needs: [check_nims, check_nims_docs, check_nimg]
24+
runs-on: ubuntu-latest
25+
steps:
26+
- run: exit 0
1827
check_examples:
1928
name: Check examples
2029
uses: ./.github/workflows/check_examples.yml
2130
run_unit_tests:
2231
name: Run unit tests
2332
uses: ./.github/workflows/run_unit_tests.yml
2433
needs: [check_nims]
34+
unit_tests_succeeded:
35+
name: Unit tests succeeded
36+
needs: [run_unit_tests]
37+
runs-on: ubuntu-latest
38+
steps:
39+
- run: exit 0
2540
run_system_tests:
2641
name: Run system tests
2742
uses: ./.github/workflows/run_system_tests.yml

.github/workflows/check_nimg.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ on:
77
jobs:
88
check_nimg:
99
name: Check NIMG
10-
runs-on: ubuntu-latest
10+
env:
11+
oldest-python-version: '3.9'
12+
strategy:
13+
matrix:
14+
os: [windows-latest, ubuntu-latest, macos-latest]
15+
python-version: [3.9, 3.13]
16+
runs-on: ${{ matrix.os }}
1117
defaults:
1218
run:
1319
# Set the working-directory for all steps in this job.
@@ -18,33 +24,26 @@ jobs:
1824
- name: Set up Python
1925
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
2026
id: setup-python
27+
with:
28+
python-version: ${{ matrix.python-version }}
2129
- name: Set up Poetry
2230
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
23-
- name: Check for lock changes (ni-measurement-plugin-sdk-generator)
24-
run: poetry check --lock
25-
- name: Cache virtualenv (ni-measurement-plugin-sdk-generator)
26-
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
27-
id: cache
31+
- name: Analyze generator
32+
uses: ni/python-actions/analyze-project@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
2833
with:
29-
path: packages/generator/.venv
30-
key: ni-measurement-plugin-sdk-generator-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('packages/generator/poetry.lock') }}
31-
- name: Install ni-measurement-plugin-sdk-generator
32-
run: poetry install -v
33-
- name: Lint ni-measurement-plugin-sdk-generator
34-
run: poetry run ni-python-styleguide lint
35-
- name: Mypy static analysis (ni-measurement-plugin-sdk-generator, Linux)
36-
run: poetry run mypy
37-
- name: Mypy static analysis (ni-measurement-plugin-sdk-generator, Windows)
38-
run: poetry run mypy --platform win32
34+
project-directory: packages/generator
3935
- name: Bandit security checks (ni-measurement-plugin-sdk-generator, example_renders)
4036
run: poetry run bandit -c pyproject.toml -r ni_measurement_plugin_sdk_generator tests/test_assets/example_renders
4137
- name: Generate gRPC stubs
38+
if: matrix.python-version == env.oldest-python-version
4239
run: |
4340
find tests/utilities/measurements/non_streaming_data_measurement/_stubs -name \*_pb2.py\* -o -name \*_pb2_grpc.py\* -delete
4441
poetry run python scripts/generate_grpc_stubs.py
4542
- name: Check for out-of-date gRPC stubs
43+
if: matrix.python-version == env.oldest-python-version
4644
run: git diff --exit-code
4745
- name: Revert gRPC stubs
46+
if: matrix.python-version == env.oldest-python-version
4847
run: |
4948
git clean -dfx tests/utilities/measurements/non_streaming_data_measurement/_stubs
5049
git restore tests/utilities/measurements/non_streaming_data_measurement/_stubs

.github/workflows/check_nims.yml

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ on:
77
jobs:
88
check_nims:
99
name: Check NIMS
10-
runs-on: ubuntu-latest
10+
env:
11+
oldest-python-version: '3.9'
12+
strategy:
13+
matrix:
14+
os: [windows-latest, ubuntu-latest, macos-latest]
15+
python-version: [3.9, 3.13]
16+
runs-on: ${{ matrix.os }}
1117
defaults:
1218
run:
1319
# Set the working-directory for all steps in this job.
@@ -20,64 +26,27 @@ jobs:
2026
- name: Set up Python
2127
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
2228
id: setup-python
29+
with:
30+
python-version: ${{ matrix.python-version }}
2331
- name: Set up Poetry
2432
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
25-
- name: Check for lock changes (ni-measurement-plugin-sdk-service)
26-
run: poetry check --lock
27-
28-
# ni-measurement-plugin-sdk-service, all extras
29-
- name: Restore cached virtualenv (ni-measurement-plugin-sdk-service, all extras)
30-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
31-
id: restore-nims-all-extras
33+
- name: Analyze generator
34+
uses: ni/python-actions/analyze-project@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
3235
with:
33-
path: packages/service/.venv
34-
key: ni-measurement-plugin-sdk-service-all-extras-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('packages/service/poetry.lock') }}
35-
- name: Install ni-measurement-plugin-sdk-service (all extras)
36-
run: poetry install -v --all-extras
37-
- name: Save cached virtualenv (ni-measurement-plugin-sdk-service, all extras)
38-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
39-
if: steps.restore-nims-all-extras.outputs.cache-hit != 'true'
40-
with:
41-
path: packages/service/.venv
42-
key: ${{ steps.restore-nims-all-extras.outputs.cache-primary-key }}
43-
- name: Lint ni-measurement-plugin-sdk-service
44-
run: poetry run ni-python-styleguide lint
45-
- name: Mypy static analysis (ni-measurement-plugin-sdk-service, Linux)
46-
run: poetry run mypy
47-
- name: Mypy static analysis (ni-measurement-plugin-sdk-service, Windows)
48-
run: poetry run mypy --platform win32
36+
project-directory: packages/service
37+
install-args: --all-extras
4938
- name: Bandit security checks (ni-measurement-plugin-sdk-service)
5039
run: poetry run bandit -c pyproject.toml -r ni_measurement_plugin_sdk_service
51-
52-
# ni-measurement-plugin-sdk-service, all extras, docs
53-
- name: Restore cached virtualenv (ni-measurement-plugin-sdk-service, all extras, docs)
54-
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
55-
id: restore-nims-all-extras-docs
56-
with:
57-
path: packages/service/.venv
58-
key: ni-measurement-plugin-sdk-service-all-extras-docs-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('packages/service/poetry.lock') }}
59-
- name: Install ni-measurement-plugin-sdk-service (all extras, docs)
60-
run: poetry install -v --all-extras --with docs
61-
- name: Save cached virtualenv (ni-measurement-plugin-sdk-service, all extras, docs)
62-
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
63-
if: steps.restore-nims-all-extras-docs.outputs.cache-hit != 'true'
64-
with:
65-
path: packages/service/.venv
66-
key: ${{ steps.restore-nims-all-extras-docs.outputs.cache-primary-key }}
67-
- name: Build docs and check for errors/warnings
68-
run: |
69-
rm -rf docs
70-
mkdir -p docs
71-
poetry run sphinx-build _docs_source docs -b html -W
72-
- name: Revert docs
73-
run: rm -rf docs
7440
- name: Generate gRPC stubs
41+
if: matrix.python-version == env.oldest-python-version
7542
run: |
7643
find tests/utilities/stubs/ -name \*_pb2.py\* -o -name \*_pb2_grpc.py\* -delete
7744
poetry run python scripts/generate_grpc_stubs.py
7845
- name: Check for out-of-date gRPC stubs
46+
if: matrix.python-version == env.oldest-python-version
7947
run: git diff --exit-code
8048
- name: Revert gRPC stubs
49+
if: matrix.python-version == env.oldest-python-version
8150
run: |
8251
git clean -dfx tests/utilities/stubs/
8352
git restore tests/utilities/stubs/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Check NIMS Docs
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
jobs:
8+
check_nims:
9+
name: Check NIMS Docs
10+
runs-on: ubuntu-latest
11+
defaults:
12+
run:
13+
# Set the working-directory for all steps in this job.
14+
working-directory: ./packages/service
15+
steps:
16+
- name: Check out repo
17+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
18+
with:
19+
submodules: true
20+
- name: Set up Python
21+
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
22+
id: setup-python
23+
- name: Set up Poetry
24+
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
25+
- name: Install ni-measurement-plugin-sdk-service (all extras, docs)
26+
run: poetry install -v --all-extras --with docs
27+
- name: Build docs and check for errors/warnings
28+
run: |
29+
rm -rf docs
30+
mkdir -p docs
31+
poetry run sphinx-build _docs_source docs -b html -W
32+
- name: Revert docs
33+
run: rm -rf docs

.github/workflows/publish.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ jobs:
4343
check_nims:
4444
name: Check service
4545
uses: ./.github/workflows/check_nims.yml
46+
check_nims_docs:
47+
name: Check NIMS docs
48+
uses: ./.github/workflows/check_nims_docs.yml
4649
build_package:
4750
name: Build ${{ matrix.package }}
4851
runs-on: ubuntu-latest
49-
needs: [check_nimg, check_nims]
52+
needs: [check_nimg, check_nims, check_nims_docs]
5053
strategy:
5154
matrix:
5255
package: [generator, sdk, service]

packages/service/ni_measurement_plugin_sdk_service/_configuration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@
1818

1919
_PREFIX = "MEASUREMENT_PLUGIN"
2020

21-
_config = AutoConfig(str(get_dotenv_search_path()))
21+
# Work around decouple's lack of type hints.
22+
_T = TypeVar("_T")
2223

2324
if TYPE_CHECKING:
24-
# Work around decouple's lack of type hints.
25-
_T = TypeVar("_T")
2625

2726
def _config(
2827
option: str,
2928
default: _T | Undefined = undefined,
3029
cast: Callable[[str], _T] | Undefined = undefined,
3130
) -> _T: ...
3231

32+
else:
33+
_config = AutoConfig(str(get_dotenv_search_path()))
34+
3335

3436
# ----------------------------------------------------------------------
3537
# NI Modular Instrument Driver Options

0 commit comments

Comments
 (0)