pyclickplc 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/.github/workflows/ci.yml +4 -1
  2. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/.github/workflows/docs.yml +1 -1
  3. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/.github/workflows/publish.yml +1 -1
  4. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/CHANGELOG.md +6 -0
  5. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/Makefile +5 -4
  6. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/PKG-INFO +2 -2
  7. pyclickplc-0.3.2/devtools/lint.py +79 -0
  8. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/pyproject.toml +4 -10
  9. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/blocks.py +4 -4
  10. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/client.py +2 -7
  11. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/nicknames.py +3 -1
  12. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/plcdata.py +2 -2
  13. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/server.py +4 -3
  14. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_nicknames.py +12 -0
  15. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/uv.lock +195 -211
  16. pyclickplc-0.3.0/devtools/lint.py +0 -89
  17. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/.claude/settings.local.json +0 -0
  18. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/.gitignore +0 -0
  19. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/CLAUDE.md +0 -0
  20. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/LICENSE +0 -0
  21. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/README.md +0 -0
  22. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/CLAUDE.md +0 -0
  23. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/gen_reference.py +0 -0
  24. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/getting-started/quickstart.md +0 -0
  25. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/addressing.md +0 -0
  26. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/client.md +0 -0
  27. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/examples.md +0 -0
  28. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/files.md +0 -0
  29. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/modbus_service.md +0 -0
  30. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/server.md +0 -0
  31. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/guides/types.md +0 -0
  32. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/index.md +0 -0
  33. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/releases/v0.2.0.md +0 -0
  34. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/docs/releases/v0.3.0.md +0 -0
  35. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/examples/sync_clickplc_datetime.py +0 -0
  36. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/examples/traffic_light.py +0 -0
  37. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/examples/traffic_light_dataview.cdv +0 -0
  38. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/examples/traffic_light_nicknames.csv +0 -0
  39. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/mkdocs.yml +0 -0
  40. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/__init__.py +0 -0
  41. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/addresses.py +0 -0
  42. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/banks.py +0 -0
  43. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/dataview.py +0 -0
  44. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/modbus.py +0 -0
  45. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/modbus_service.py +0 -0
  46. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/py.typed +0 -0
  47. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/server_tui.py +0 -0
  48. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/src/pyclickplc/validation.py +0 -0
  49. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/__init__.py +0 -0
  50. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/examples/__init__.py +0 -0
  51. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/examples/_traffic_light_loader.py +0 -0
  52. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/examples/test_sync_clickplc_datetime.py +0 -0
  53. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/examples/test_traffic_light_cycle.py +0 -0
  54. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/examples/test_traffic_light_files.py +0 -0
  55. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/examples/test_traffic_light_smoke.py +0 -0
  56. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_addresses.py +0 -0
  57. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_banks.py +0 -0
  58. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_blocks.py +0 -0
  59. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_client.py +0 -0
  60. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_dataview.py +0 -0
  61. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_integration.py +0 -0
  62. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_modbus.py +0 -0
  63. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_modbus_service.py +0 -0
  64. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_plcdata.py +0 -0
  65. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_server.py +0 -0
  66. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_server_tui.py +0 -0
  67. {pyclickplc-0.3.0 → pyclickplc-0.3.2}/tests/test_validation.py +0 -0
@@ -54,7 +54,10 @@ jobs:
54
54
  # python-version: ${{ matrix.python-version }}
55
55
 
56
56
  - name: Install all dependencies
57
- run: uv sync --all-extras --dev
57
+ run: uv sync --locked --all-extras --dev
58
+
59
+ - name: Report locked tool versions
60
+ run: uv run python -c "import importlib.metadata as md; print('ruff', md.version('ruff')); print('ty', md.version('ty'))"
58
61
 
59
62
  - name: Run linting (read-only checks)
60
63
  run: uv run python devtools/lint.py --check
@@ -32,7 +32,7 @@ jobs:
32
32
  run: uv python install
33
33
 
34
34
  - name: Install docs dependencies
35
- run: uv sync --group docs
35
+ run: uv sync --locked --group docs
36
36
 
37
37
  - name: Build docs
38
38
  run: uv run mkdocs build --strict
@@ -29,7 +29,7 @@ jobs:
29
29
  run: uv python install
30
30
 
31
31
  - name: Install all dependencies
32
- run: uv sync --all-extras --dev
32
+ run: uv sync --locked --all-extras --dev
33
33
 
34
34
  - name: Run tests
35
35
  run: uv run pytest
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1 - 2026-03-29
4
+
5
+ ### Fixed
6
+
7
+ - `read_csv()` no longer rejects duplicate nicknames for system addresses (SC/SD). Click auto-populates these and may produce duplicates that users cannot control.
8
+
3
9
  ## 0.3.0 - 2026-03-26
4
10
 
5
11
  ### Added
@@ -9,7 +9,7 @@
9
9
  default: install lint test
10
10
 
11
11
  install:
12
- uv sync --all-extras --dev
12
+ uv sync --locked --all-extras --dev
13
13
 
14
14
  lint:
15
15
  uv run devtools/lint.py
@@ -18,16 +18,17 @@ test:
18
18
  uv run pytest
19
19
 
20
20
  upgrade:
21
- uv sync --upgrade
21
+ uv lock --upgrade
22
+ uv sync --locked --all-extras --dev
22
23
 
23
24
  build:
24
25
  uv build
25
26
 
26
27
  docs-serve:
27
- uv run --group docs mkdocs serve
28
+ DISABLE_MKDOCS_2_WARNING=true uv run --group docs mkdocs serve
28
29
 
29
30
  docs-build:
30
- uv run --group docs mkdocs build --strict
31
+ DISABLE_MKDOCS_2_WARNING=true uv run --group docs mkdocs build --strict
31
32
 
32
33
  docs-check: docs-build
33
34
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyclickplc
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Utilities for AutomationDirect CLICK PLCs: Modbus TCP client/server, address helpers, nickname CSV I/O, and DataView CDV I/O.
5
5
  Project-URL: Repository, https://github.com/ssweber/pyclickplc
6
6
  Project-URL: Documentation, https://ssweber.github.io/pyclickplc/
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Programming Language :: Python :: 3.14
19
19
  Classifier: Typing :: Typed
20
20
  Requires-Python: <4.0,>=3.11
21
- Requires-Dist: pymodbus>=3.8
21
+ Requires-Dist: pymodbus<3.13,>=3.12
22
22
  Description-Content-Type: text/markdown
23
23
 
24
24
  # pyclickplc
@@ -0,0 +1,79 @@
1
+ import argparse
2
+ import subprocess
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ # Use canonical absolute paths so ty behaves consistently on Windows regardless
7
+ # of how cwd casing is typed (e.g., "Documents" vs "documents").
8
+ PROJECT_ROOT = Path.cwd().resolve()
9
+ SRC_PATHS = [
10
+ str(PROJECT_ROOT / "src"),
11
+ str(PROJECT_ROOT / "tests"),
12
+ str(PROJECT_ROOT / "devtools"),
13
+ ]
14
+
15
+
16
+ def parse_args() -> argparse.Namespace:
17
+ parser = argparse.ArgumentParser(description="Run lint/type checks for the repository.")
18
+ parser.add_argument(
19
+ "--check",
20
+ action="store_true",
21
+ help="Run read-only checks suitable for CI (no autofix).",
22
+ )
23
+ return parser.parse_args()
24
+
25
+
26
+ def main() -> int:
27
+ args = parse_args()
28
+ print()
29
+
30
+ errcount = 0
31
+
32
+ if args.check:
33
+ errcount += run(["ruff", "check", *SRC_PATHS])
34
+ else:
35
+ errcount += run(["ruff", "check", "--fix", *SRC_PATHS])
36
+
37
+ if args.check:
38
+ errcount += run(["ruff", "format", "--check", *SRC_PATHS])
39
+ else:
40
+ errcount += run(["ruff", "format", *SRC_PATHS])
41
+
42
+ errcount += run(
43
+ [
44
+ "ty",
45
+ "check",
46
+ "--project",
47
+ str(PROJECT_ROOT),
48
+ ]
49
+ )
50
+
51
+ print()
52
+
53
+ if errcount != 0:
54
+ print(f"Lint failed with {errcount} error(s).")
55
+ else:
56
+ print("Lint passed.")
57
+ print()
58
+
59
+ return errcount
60
+
61
+
62
+ def run(cmd: list[str]) -> int:
63
+ print()
64
+ print(f"==> {' '.join(cmd)}")
65
+
66
+ try:
67
+ subprocess.run(cmd, text=True, check=True)
68
+ except subprocess.CalledProcessError as exc:
69
+ print(f"Error: {exc}")
70
+ return 1
71
+ except FileNotFoundError as exc:
72
+ print(f"Executable not found: {exc}")
73
+ return 1
74
+
75
+ return 0
76
+
77
+
78
+ if __name__ == "__main__":
79
+ sys.exit(main())
@@ -37,7 +37,7 @@ classifiers = [
37
37
  # ---- Main dependencies ----
38
38
 
39
39
  dependencies = [
40
- "pymodbus>=3.8",
40
+ "pymodbus>=3.12,<3.13",
41
41
  ]
42
42
 
43
43
 
@@ -48,13 +48,10 @@ dev = [
48
48
  "pytest>=8.3.5",
49
49
  "pytest-asyncio>=1.0",
50
50
  "ruff>=0.11.0",
51
- "codespell>=2.4.1",
52
- "rich>=13.9.4",
53
51
  "ty>=0.0.14",
54
- "funlog>=0.2.0",
55
52
  ]
56
53
  docs = [
57
- "mkdocs>=1.6.1",
54
+ "mkdocs>=1.6.1,<2",
58
55
  "mkdocs-material>=9.6.0",
59
56
  "mkdocstrings[python]>=0.29.0",
60
57
  "mkdocs-gen-files>=0.5.0",
@@ -89,6 +86,8 @@ bump = true
89
86
  # The source location for the package.
90
87
  packages = ["src/pyclickplc"]
91
88
 
89
+ [tool.uv]
90
+ exclude-newer = "7 days"
92
91
 
93
92
  # ---- Settings ----
94
93
 
@@ -150,11 +149,6 @@ exclude = [
150
149
  # projects and relative imports. The code runs correctly with Python.
151
150
  unresolved-import = "ignore"
152
151
 
153
- [tool.codespell]
154
- # Add here as needed:
155
- # ignore-words-list = "foo,bar"
156
- # skip = "foo.py,bar.py"
157
-
158
152
  [tool.pytest.ini_options]
159
153
  python_files = ["*.py"]
160
154
  python_classes = ["Test*"]
@@ -7,7 +7,7 @@ block operations for CLICK PLC address editors.
7
7
  from __future__ import annotations
8
8
 
9
9
  import re
10
- from collections.abc import Iterable
10
+ from collections.abc import Iterable, Sequence
11
11
  from dataclasses import dataclass
12
12
  from typing import TYPE_CHECKING, Literal, Protocol
13
13
 
@@ -412,7 +412,7 @@ def is_block_name_available(
412
412
 
413
413
 
414
414
  def find_paired_tag_index(
415
- rows: list[HasComment], row_idx: int, tag: BlockTag | None = None
415
+ rows: Sequence[HasComment], row_idx: int, tag: BlockTag | None = None
416
416
  ) -> int | None:
417
417
  """Find the row index of the paired open/close block tag.
418
418
 
@@ -473,7 +473,7 @@ def find_paired_tag_index(
473
473
 
474
474
 
475
475
  def find_block_range_indices(
476
- rows: list[HasComment], row_idx: int, tag: BlockTag | None = None
476
+ rows: Sequence[HasComment], row_idx: int, tag: BlockTag | None = None
477
477
  ) -> tuple[int, int] | None:
478
478
  """Find the (start_idx, end_idx) range for a block tag.
479
479
 
@@ -514,7 +514,7 @@ def find_block_range_indices(
514
514
  return None
515
515
 
516
516
 
517
- def compute_all_block_ranges(rows: list[HasComment]) -> list[BlockRange]:
517
+ def compute_all_block_ranges(rows: Sequence[HasComment]) -> list[BlockRange]:
518
518
  """Compute all block ranges from a list of rows using stack-based matching.
519
519
 
520
520
  Correctly handles nested blocks and multiple blocks with the same name.
@@ -757,13 +757,8 @@ class ClickClient:
757
757
  self.tags = _build_tags_from_records(tags)
758
758
 
759
759
  async def _call_modbus(self, method: Any, /, **kwargs: Any) -> Any:
760
- """Call pymodbus methods with device_id, falling back to legacy slave."""
761
- try:
762
- return await method(device_id=self._device_id, **kwargs)
763
- except TypeError as exc:
764
- if "device_id" not in str(exc):
765
- raise
766
- return await method(slave=self._device_id, **kwargs)
760
+ """Call a pymodbus client method with device_id."""
761
+ return await method(device_id=self._device_id, **kwargs)
767
762
 
768
763
  @overload
769
764
  def _get_accessor(self, bank: BoolBankName) -> AddressAccessor[bool]: ...
@@ -244,7 +244,9 @@ def read_csv(path: str | Path) -> AddressRecordMap:
244
244
 
245
245
  if nickname:
246
246
  key = nickname.lower()
247
- if key in seen_nicknames:
247
+ # Allow duplicate nicknames for system addresses (SC/SD) —
248
+ # Click auto-populates these and may produce duplicates.
249
+ if key in seen_nicknames and mem_type not in {"SC", "SD"}:
248
250
  first_nickname, first_address, first_line = seen_nicknames[key]
249
251
  raise ValueError(
250
252
  "Case-insensitive duplicate nickname in CSV at "
@@ -9,7 +9,7 @@ directions.
9
9
  from __future__ import annotations
10
10
 
11
11
  import re
12
- from collections.abc import Iterable
12
+ from collections.abc import Iterable, Mapping
13
13
  from pathlib import Path
14
14
 
15
15
  from .addresses import format_address_display
@@ -178,7 +178,7 @@ def _format_value(value: bool | int | float | str, data_type: DataType) -> str:
178
178
 
179
179
  def write_plc_data(
180
180
  path: str | Path,
181
- data: dict[str, bool | int | float | str],
181
+ data: Mapping[str, bool | int | float | str],
182
182
  *,
183
183
  banks: Iterable[str] | None = None,
184
184
  ) -> None:
@@ -6,11 +6,12 @@ routed to a user-supplied DataProvider.
6
6
 
7
7
  from __future__ import annotations
8
8
 
9
+ from collections.abc import Mapping
9
10
  from dataclasses import dataclass
10
11
  from typing import Any, Protocol, runtime_checkable
11
12
 
12
13
  from pymodbus.constants import ExcCodes
13
- from pymodbus.datastore import ModbusBaseDeviceContext, ModbusServerContext
14
+ from pymodbus.datastore import ModbusDeviceContext, ModbusServerContext
14
15
  from pymodbus.server import ModbusTcpServer
15
16
 
16
17
  from .addresses import AddressNormalizerMixin, format_address_display, parse_address
@@ -88,7 +89,7 @@ class MemoryDataProvider(AddressNormalizerMixin):
88
89
  """Synchronous write convenience."""
89
90
  self.write(address, value)
90
91
 
91
- def bulk_set(self, values: dict[str, PlcValue]) -> None:
92
+ def bulk_set(self, values: Mapping[str, PlcValue]) -> None:
92
93
  """Set multiple values at once."""
93
94
  for address, value in values.items():
94
95
  self.set(address, value)
@@ -120,7 +121,7 @@ def _format_plc_address(bank: str, index: int) -> str:
120
121
  return format_address_display(bank, index)
121
122
 
122
123
 
123
- class _ClickDeviceContext(ModbusBaseDeviceContext):
124
+ class _ClickDeviceContext(ModbusDeviceContext):
124
125
  """Custom pymodbus context routing Modbus requests to a DataProvider."""
125
126
 
126
127
  def __init__(self, provider: DataProvider) -> None:
@@ -143,6 +143,18 @@ class TestReadCsv:
143
143
  with pytest.raises(ValueError, match="Case-insensitive duplicate nickname"):
144
144
  read_csv(csv_path)
145
145
 
146
+ def test_read_duplicate_system_nickname_allowed(self, tmp_path):
147
+ """SC/SD system addresses may have duplicate nicknames from Click."""
148
+ csv_path = tmp_path / "test.csv"
149
+ csv_path.write_text(
150
+ "Address,Data Type,Nickname,Initial Value,Retentive,Address Comment\n"
151
+ 'SD1,SINT,"SysFlag",0,No,""\n'
152
+ 'SD2,SINT,"SysFlag",0,No,""\n',
153
+ encoding="utf-8",
154
+ )
155
+ records = read_csv(csv_path)
156
+ assert len(records) == 2
157
+
146
158
  def test_tag_lookup_rejects_case_collisions_after_mutation(self):
147
159
  records = AddressRecordMap(
148
160
  {