Skip to content

Commit 72366c7

Browse files
committed
fix: correct 6 typos in DAQmxErrors names; keep old names as aliases; document the process in CONTRIBUTING.md
1 parent 0dfd55f commit 72366c7

7 files changed

Lines changed: 178 additions & 16 deletions

File tree

.config/cspell/daqmx-api-elements.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ AOHW # unseparated initialisms; AO HW
2020
APFI # initialism; Analog Programmable Function Interface
2121
asyn # abbreviation; asynchronous
2222
atten # abbreviation; attenuation
23-
attentuation # Typo; should be: attenuation
24-
BBULK # Typo; should be USB_BULK instead of US_BBULK
23+
attentuation # Typo in C API; remapped via enum_helpers.py
24+
BBULK # Typo in C API; remapped via enum_helpers.py
2525
BHigh # unseparated words; B high
2626
calibrationInfo # unseparated words
2727
CAPI # unseparated words; C API
28-
certiticates # Typo; should be: certificates
28+
certiticates # Typo in C API; remapped via enum_helpers.py
2929
cfgd # abbreviation; configured
3030
cfgs # abbreviation; configurations
3131
chans # abbreviation; channels
@@ -63,7 +63,7 @@ HWTSP # initialism; Hardware-Timed Single Point
6363
hyst # abbreviation; hysteresis
6464
hysts # abbreviation; hysteresis
6565
immed # abbreviation; immediate
66-
invalidc # Typo; should be: INVALID_CDAQ_SYNC_PORT_CONNECTION_FORMAT
66+
invalidc # Typo in C API; remapped via enum_helpers.py
6767
IRIGB # initialism; IRIG-B
6868
isoc # abbreviation; isochronous
6969
lvls # abbreviation; levels
@@ -82,7 +82,7 @@ persistedChannel # unseparated words
8282
persistedScale # unseparated words
8383
persistedTask # unseparated words
8484
physicalChannel # unseparated words
85-
posssible # Typo; should be: possible
85+
posssible # Typo in C API; remapped via enum_helpers.py
8686
pretrig # abbreviation; pre-trigger
8787
prpty # abbreviation; property
8888
rangeWith # unseparated words
@@ -93,11 +93,11 @@ samp # abbreviation; sample
9393
samps # abbreviation; samples
9494
scanList # unseparated words
9595
sensord # Deprecated; see attribute_helpers.py
96-
sensitivit # Typo; should be: sensitivity
96+
sensitivit # Typo in C API; remapped via enum_helpers.py
9797
SMIO # initialism; Simultaneously-sampling Multifunction I/O
9898
specd # abbreviation; specified
9999
srcs # abbreviation; sources
100-
subsytem # Typo; should be: subsystem
100+
subsytem # Typo in C API; remapped via enum_helpers.py
101101
taskToCopy # unseparated words; task to copy
102102
tcpip # initialism; TCP/IP
103103
TEDSAI # unseparated initialisms; TEDS AI

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ All notable changes to this project will be documented in this file.
3636

3737
* ### Major Changes
3838
* [cspell](https://cspell.org/) is now used for spell checking.
39+
* The following `DAQmxErrors` enum members were renamed to fix typos inherited from the C API:
40+
* `FILTER_DELAY_REMOVAL_NOT_POSSSIBLE_WITH_ANALOG_TRIGGER``FILTER_DELAY_REMOVAL_NOT_POSSIBLE_WITH_ANALOG_TRIGGER`
41+
* `INVALID_ATTENTUATION_BASED_ON_MIN_MAX``INVALID_ATTENUATION_BASED_ON_MIN_MAX`
42+
* `INVALIDC_DAQ_SYNC_PORT_CONNECTION_FORMAT``INVALID_CDAQ_SYNC_PORT_CONNECTION_FORMAT`
43+
* `MAX_SOUND_PRESSURE_MIC_SENSITIVIT_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV``MAX_SOUND_PRESSURE_MIC_SENSITIVITY_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV`
44+
* `MULTIPLE_SUBSYTEM_CALIBRATION``MULTIPLE_SUBSYSTEM_CALIBRATION`
45+
* `ONLY_PEM_OR_DER_CERTITICATES_ACCEPTED``ONLY_PEM_OR_DER_CERTIFICATES_ACCEPTED`
46+
47+
The old names are preserved as aliases for backward compatibility.
3948

4049
* ### Known Issues
4150
* ...

CONTRIBUTING.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,81 @@ $ poetry install --with docs
110110
$ poetry run sphinx-build -b html docs docs\_build
111111
```
112112

113+
# Fixing API Typos
114+
115+
Public API names may contain typos. If you identify a typo in such names, the remediation path
116+
depends on the type of API name. Subsections below cover some API name categories. If you
117+
encounter a typo that does not fit any documented category, follow the general spirit of the
118+
existing subsections and document the new approach in a new subsection below.
119+
120+
## Typos in Python Property Names
121+
122+
Python property names are defined in
123+
[`src/codegen/utilities/attribute_helpers.py`](src/codegen/utilities/attribute_helpers.py) and
124+
generated from metadata. Because renaming a public property is a breaking change, typos are fixed
125+
using a deprecation process rather than being corrected immediately.
126+
127+
To fix a typo in a generated property:
128+
129+
1. Add an entry to `DEPRECATED_ATTRIBUTES` in
130+
[`src/codegen/utilities/attribute_helpers.py`](src/codegen/utilities/attribute_helpers.py):
131+
```python
132+
"old_typo_name": {"new_name": "correct_name", "deprecated_in": "<current version>"},
133+
```
134+
The code generator will automatically emit a shim property for the old name that delegates to
135+
the new name and raises `DeprecationWarning` on access.
136+
137+
2. Regenerate the code:
138+
```sh
139+
$ poetry run python src/codegen --dest generated/nidaqmx
140+
```
141+
142+
3. Update the cspell dictionary in
143+
[`.config/cspell/daqmx-api-elements.txt`](.config/cspell/daqmx-api-elements.txt):
144+
- If the typo word is already present, update its comment to
145+
`# Deprecated; see attribute_helpers.py`. Otherwise, add it with that comment.
146+
- The entry must remain in the dictionary for as long as the deprecated shim property exists in
147+
the generated code.
148+
- Add the correct name if it is not already known to cspell.
149+
150+
4. Add a bullet point to the `CHANGELOG.md` section for the current version describing the rename
151+
and deprecation.
152+
153+
For typos in handwritten functions or constants, apply the `@deprecation.deprecated` decorator
154+
directly and add a correctly named alias. See
155+
[`src/handwritten/errors.py`](src/handwritten/errors.py) for examples.
156+
157+
## Typos in Error Code Names
158+
159+
Error code names are derived from the NI-DAQmx C API metadata in
160+
[`src/codegen/metadata/enums.py`](src/codegen/metadata/enums.py) and historically were used
161+
verbatim as the Python names. This means typos in the C API shipped as-is in the Python API, and
162+
renaming them requires preserving the old names as aliases for backward compatibility.
163+
164+
To fix a typo in an error code name:
165+
166+
1. Add an entry to `ERROR_CODE_NAME_SUBSTITUTIONS` in
167+
[`src/codegen/utilities/enum_helpers.py`](src/codegen/utilities/enum_helpers.py):
168+
```python
169+
"C_API_NAME_WITH_TYPO": "CORRECTED_NAME",
170+
```
171+
The code generator will emit the corrected name as the primary member and keep the old typo
172+
name as an alias pointing to it, annotated with a comment noting it is kept for backward
173+
compatibility.
174+
175+
2. Regenerate the code:
176+
```sh
177+
$ poetry run python src/codegen --dest generated/nidaqmx
178+
```
179+
180+
3. Update the cspell dictionary in
181+
[`.config/cspell/daqmx-api-elements.txt`](.config/cspell/daqmx-api-elements.txt):
182+
- If the typo word is already present, update its comment to
183+
`# Typo in C API; remapped via enum_helpers.py`. Otherwise, add it with that comment.
184+
185+
4. Add a bullet point to `CHANGELOG.md` for the current version noting the rename and that the
186+
old name is preserved as an alias for backward compatibility.
187+
113188
# Branching Policy
114189

115190
Active development for the next release occurs on the `master` branch.
@@ -152,7 +227,7 @@ can be verified once that has been completed.
152227
- If the new version number is incorrect, update it by posting and committing a suggestion.
153228
8. Create a PR adding a section to `CHANGELOG.md` for the new version with empty subsections.
154229

155-
# Updating gRPC stubs when the .proto file is modified
230+
# Updating gRPC Stubs When the .proto File Is Modified
156231

157232
The `generated\nidaqmx\_stubs` directory contains the auto-generated Python files based on the NI-DAQmx protobuf (`.proto`) file.
158233

generated/nidaqmx/error_codes.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ class DAQmxErrors(IntEnum):
170170
OPERATION_ABORTED = -201452
171171
TWO_PORTS_REQUIRED = -201451
172172
DEVICE_DOES_NOT_SUPPORT_CDAQ_SYNC_CONNECTIONS = -201450
173-
INVALIDC_DAQ_SYNC_PORT_CONNECTION_FORMAT = -201449
173+
INVALID_CDAQ_SYNC_PORT_CONNECTION_FORMAT = -201449
174+
# Typo in C API; kept for backward compatibility
175+
INVALIDC_DAQ_SYNC_PORT_CONNECTION_FORMAT = INVALID_CDAQ_SYNC_PORT_CONNECTION_FORMAT
174176
ROSETTE_MEASUREMENTS_NOT_SPECIFIED = -201448
175177
INVALID_NUM_OF_PHYS_CHANS_FOR_DELTA_ROSETTE = -201447
176178
INVALID_NUM_OF_PHYS_CHANS_FOR_TEE_ROSETTE = -201446
@@ -187,7 +189,9 @@ class DAQmxErrors(IntEnum):
187189
CANT_PRIME_WITH_EMPTY_BUFFER = -201435
188190
CONFIG_FAILED_BECAUSE_WATCHDOG_EXPIRED = -201434
189191
WRITE_FAILED_BECAUSE_WATCHDOG_CHANGED_LINE_DIRECTION = -201433
190-
MULTIPLE_SUBSYTEM_CALIBRATION = -201432
192+
MULTIPLE_SUBSYSTEM_CALIBRATION = -201432
193+
# Typo in C API; kept for backward compatibility
194+
MULTIPLE_SUBSYTEM_CALIBRATION = MULTIPLE_SUBSYSTEM_CALIBRATION
191195
INCORRECT_CHANNEL_FOR_OFFSET_ADJUSTMENT = -201431
192196
INVALID_NUM_REF_VOLTAGES_TO_WRITE = -201430
193197
START_TRIG_DELAY_WITH_DSA_MODULE = -201429
@@ -223,7 +227,9 @@ class DAQmxErrors(IntEnum):
223227
MODULE_MISMATCH_IN_SAME_TIMED_TASK = -201399
224228
INVALID_ATTRIBUTE_VALUE_POSSIBLY_DUE_TO_OTHER_ATTRIBUTE_VALUES = -201398
225229
CHANGE_DETECTION_STOPPED_TO_PREVENT_DEVICE_HANG = -201397
226-
FILTER_DELAY_REMOVAL_NOT_POSSSIBLE_WITH_ANALOG_TRIGGER = -201396
230+
FILTER_DELAY_REMOVAL_NOT_POSSIBLE_WITH_ANALOG_TRIGGER = -201396
231+
# Typo in C API; kept for backward compatibility
232+
FILTER_DELAY_REMOVAL_NOT_POSSSIBLE_WITH_ANALOG_TRIGGER = FILTER_DELAY_REMOVAL_NOT_POSSIBLE_WITH_ANALOG_TRIGGER
227233
NONBUFFERED_OR_NO_CHANNELS = -201395
228234
TRISTATE_LOGIC_LEVEL_NOT_SPECD_FOR_ENTIRE_PORT = -201394
229235
TRISTATE_LOGIC_LEVEL_NOT_SUPPORTED_ON_DIG_OUT_CHAN = -201393
@@ -343,7 +349,9 @@ class DAQmxErrors(IntEnum):
343349
INVALID_COUPLING_FOR_MEASUREMENT_TYPE = -201279
344350
DIGITAL_LINE_UPDATE_TOO_FAST_FOR_DEVICE = -201278
345351
CERTIFICATE_IS_TOO_BIG_TO_TRANSFER = -201277
346-
ONLY_PEM_OR_DER_CERTITICATES_ACCEPTED = -201276
352+
ONLY_PEM_OR_DER_CERTIFICATES_ACCEPTED = -201276
353+
# Typo in C API; kept for backward compatibility
354+
ONLY_PEM_OR_DER_CERTITICATES_ACCEPTED = ONLY_PEM_OR_DER_CERTIFICATES_ACCEPTED
347355
CAL_COUPLING_NOT_SUPPORTED = -201275
348356
DEVICE_NOT_SUPPORTED_IN_64_BIT = -201274
349357
NETWORK_DEVICE_IN_USE = -201273
@@ -758,7 +766,9 @@ class DAQmxErrors(IntEnum):
758766
WHEN_ACQ_COMP_AND_NO_REF_TRIG = -200864
759767
WAIT_FOR_NEXT_SAMP_CLK_NOT_SUPPORTED = -200863
760768
DEV_IN_UNIDENTIFIED_PXI_CHASSIS = -200862
761-
MAX_SOUND_PRESSURE_MIC_SENSITIVIT_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV = -200861
769+
MAX_SOUND_PRESSURE_MIC_SENSITIVITY_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV = -200861
770+
# Typo in C API; kept for backward compatibility
771+
MAX_SOUND_PRESSURE_MIC_SENSITIVIT_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV = MAX_SOUND_PRESSURE_MIC_SENSITIVITY_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV
762772
MAX_SOUND_PRESSURE_AND_MIC_SENSITIVITY_NOT_SUPPORTED_BY_DEV = -200860
763773
AO_BUFFER_SIZE_ZERO_FOR_SAMP_CLK_TIMING_TYPE = -200859
764774
AO_CALL_WRITE_BEFORE_START_FOR_SAMP_CLK_TIMING_TYPE = -200858
@@ -1290,7 +1300,9 @@ class DAQmxErrors(IntEnum):
12901300
DEV_ABSENT_OR_UNAVAILABLE = -200324
12911301
NO_ADV_TRIG_FOR_MULTI_DEV_SCAN = -200323
12921302
INTERRUPTS_INSUFFICIENT_DATA_XFER_MECH = -200322
1293-
INVALID_ATTENTUATION_BASED_ON_MIN_MAX = -200321
1303+
INVALID_ATTENUATION_BASED_ON_MIN_MAX = -200321
1304+
# Typo in C API; kept for backward compatibility
1305+
INVALID_ATTENTUATION_BASED_ON_MIN_MAX = INVALID_ATTENUATION_BASED_ON_MIN_MAX
12941306
CABLED_MODULE_CANNOT_ROUTE_SSH = -200320
12951307
CABLED_MODULE_CANNOT_ROUTE_CONV_CLK = -200319
12961308
INVALID_EXCIT_VAL_FOR_SCALING = -200318

src/codegen/templates/error_codes.mako

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<%
2+
from codegen.utilities.enum_helpers import ERROR_CODE_NAME_SUBSTITUTIONS
23
errors_metadata, warnings_metadata = data['DAQmxErrors'], data['DAQmxWarnings']
4+
5+
def _fix_name(name):
6+
return ERROR_CODE_NAME_SUBSTITUTIONS.get(name, name)
37
%>\
48
# Do not edit this file; it was automatically generated.
59

@@ -10,13 +14,21 @@ __all__ = ['DAQmxErrors', 'DAQmxWarnings']
1014

1115
class DAQmxErrors(IntEnum):
1216
%for value in errors_metadata['values']:
13-
${value['name']} = ${value['value']}
17+
${_fix_name(value['name'])} = ${value['value']}
18+
%if value['name'] in ERROR_CODE_NAME_SUBSTITUTIONS:
19+
# Typo in C API; kept for backward compatibility
20+
${value['name']} = ${_fix_name(value['name'])}
21+
%endif
1422
%endfor
1523
UNKNOWN = -1
1624

1725

1826
class DAQmxWarnings(IntEnum):
1927
UNKNOWN = -1
2028
%for value in warnings_metadata['values']:
21-
${value['name']} = ${value['value']}
29+
${_fix_name(value['name'])} = ${value['value']}
30+
%if value['name'] in ERROR_CODE_NAME_SUBSTITUTIONS:
31+
# Typo in C API; kept for backward compatibility
32+
${value['name']} = ${_fix_name(value['name'])}
33+
%endif
2234
%endfor

src/codegen/utilities/enum_helpers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@
127127
"GROUND": "GND",
128128
}
129129

130+
# Typos in the C API error code names that are fixed in the Python names
131+
ERROR_CODE_NAME_SUBSTITUTIONS = {
132+
"FILTER_DELAY_REMOVAL_NOT_POSSSIBLE_WITH_ANALOG_TRIGGER": "FILTER_DELAY_REMOVAL_NOT_POSSIBLE_WITH_ANALOG_TRIGGER",
133+
"INVALID_ATTENTUATION_BASED_ON_MIN_MAX": "INVALID_ATTENUATION_BASED_ON_MIN_MAX",
134+
"INVALIDC_DAQ_SYNC_PORT_CONNECTION_FORMAT": "INVALID_CDAQ_SYNC_PORT_CONNECTION_FORMAT",
135+
"MAX_SOUND_PRESSURE_MIC_SENSITIVIT_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV": "MAX_SOUND_PRESSURE_MIC_SENSITIVITY_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV",
136+
"MULTIPLE_SUBSYTEM_CALIBRATION": "MULTIPLE_SUBSYSTEM_CALIBRATION",
137+
"ONLY_PEM_OR_DER_CERTITICATES_ACCEPTED": "ONLY_PEM_OR_DER_CERTIFICATES_ACCEPTED",
138+
}
139+
130140
# bitfield type enums are prefixed with '_'.
131141
BITFIELD_ENUMS = ["CouplingTypes", "Callback", "TriggerUsageTypes", "Save", "TermCfg"]
132142

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""Tests for error code renames that fixed typos inherited from the C API."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from nidaqmx.error_codes import DAQmxErrors
8+
9+
# Each tuple is (old_typo_name, new_correct_name).
10+
_RENAMED_ERROR_CODES = [
11+
(
12+
"FILTER_DELAY_REMOVAL_NOT_POSSSIBLE_WITH_ANALOG_TRIGGER",
13+
"FILTER_DELAY_REMOVAL_NOT_POSSIBLE_WITH_ANALOG_TRIGGER",
14+
),
15+
(
16+
"INVALID_ATTENTUATION_BASED_ON_MIN_MAX",
17+
"INVALID_ATTENUATION_BASED_ON_MIN_MAX",
18+
),
19+
(
20+
"INVALIDC_DAQ_SYNC_PORT_CONNECTION_FORMAT",
21+
"INVALID_CDAQ_SYNC_PORT_CONNECTION_FORMAT",
22+
),
23+
(
24+
"MAX_SOUND_PRESSURE_MIC_SENSITIVIT_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV",
25+
"MAX_SOUND_PRESSURE_MIC_SENSITIVITY_RELATED_AI_PROPERTIES_NOT_SUPPORTED_BY_DEV",
26+
),
27+
(
28+
"MULTIPLE_SUBSYTEM_CALIBRATION",
29+
"MULTIPLE_SUBSYSTEM_CALIBRATION",
30+
),
31+
(
32+
"ONLY_PEM_OR_DER_CERTITICATES_ACCEPTED",
33+
"ONLY_PEM_OR_DER_CERTIFICATES_ACCEPTED",
34+
),
35+
]
36+
37+
38+
@pytest.mark.parametrize("old_name,new_name", _RENAMED_ERROR_CODES)
39+
def test___renamed_error_code___old_and_new_names___refer_to_same_member(
40+
old_name: str, new_name: str
41+
) -> None:
42+
old_member = DAQmxErrors[old_name]
43+
new_member = DAQmxErrors[new_name]
44+
assert old_member is new_member

0 commit comments

Comments
 (0)