Skip to content

Commit f5aef38

Browse files
authored
Merge pull request #41 from us-irs/dep-updates
dependency updates
2 parents d907217 + 7f41ac3 commit f5aef38

File tree

13 files changed

+109
-70
lines changed

13 files changed

+109
-70
lines changed

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,25 @@ The following features have not been implemented yet. PRs or notifications for d
2929

3030
You can install this package from PyPI
3131

32-
Install command assuming an active virtual environment:
32+
For example, using [`uv`](https://docs.astral.sh/uv/)
33+
34+
Setting up virtual environment:
35+
36+
```sh
37+
uv venv
38+
```
39+
40+
Regular install:
3341

3442
```sh
35-
pip install cfdp-py
43+
uv pip install -e .
3644
```
3745

46+
Interactive install with testing support:
47+
48+
```sh
49+
uv pip install -e ".[test]"
50+
```
3851

3952
# Examples
4053

@@ -47,14 +60,13 @@ If you want to run the tests, it is recommended to install `pytest` and `coverag
4760
first. You also have to install the package with the optional `test` feature:
4861

4962
```sh
50-
pip install coverage pytest
51-
pip install cfdp-py[test]
63+
uv pip install -e ".[test]"
5264
```
5365

5466
Running tests regularly:
5567

5668
```sh
57-
pytest .
69+
pytest
5870
```
5971

6072
Running tests with coverage:
@@ -91,11 +103,11 @@ make doctest
91103
Linting:
92104

93105
```sh
94-
ruff check .
106+
ruff check
95107
```
96108

97109
Formatting:
98110

99111
```sh
100-
ruff format .
112+
ruff format
101113
```

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
intersphinx_mapping = {
6565
"python": ("https://docs.python.org/3", None),
6666
"spacepackets": ("https://spacepackets.readthedocs.io/en/latest/", None),
67-
"crcmod": ("https://crcmod.sourceforge.net/", None),
67+
"fastcrc": ("https://fastcrc.readthedocs.io/en/latest/", None),
6868
}
6969

7070
# -- Options for HTML output -------------------------------------------------
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
cfdp @ git+https://gitlab.com/librecube/lib/python-cfdp.git
2+
# Install local cfdp-py interactively
3+
-e ../..

justfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Run with `just all`
2-
all: fmt check test
2+
all: fmt check coverage
3+
4+
setup:
5+
uv venv
6+
7+
install:
8+
uv pip install -e ".[test]"
39

410
fmt:
511
ruff format
@@ -9,3 +15,7 @@ check:
915

1016
test:
1117
pytest
18+
19+
coverage:
20+
coverage run -m pytest
21+
coverage report

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ classifiers = [
2727
"Topic :: Scientific/Engineering"
2828
]
2929
dependencies = [
30-
"spacepackets>=0.26.0, <=0.28",
31-
"crcmod~=1.7",
30+
"spacepackets>=0.30,<0.32",
31+
"fastcrc~=0.3",
3232
"deprecation~=2.1",
3333
]
3434

3535
[project.optional-dependencies]
3636
test = [
37-
"pyfakefs~=5.2"
37+
"pyfakefs~=5.2",
38+
"pytest",
39+
"coverage"
3840
]
3941
lint = ["ruff"]
4042

release-checklist.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ The steps shown here are for Ubuntu/MacOS.
1111
2. Bump version inside the `pyproject.toml` file.
1212
3. Update `CHANGELOG.md`: Convert `unreleased` section into version section
1313
with date and new `unreleased`section.
14-
4. Run tests with `pytest .`
15-
5. Run auto-formatter with `ruff format .`
16-
6. Run linter with `ruff check .`
14+
4. Run tests with `pytest`
15+
5. Run auto-formatter with `ruff format`
16+
6. Run linter with `ruff check`
1717
7. Wait for CI/CD results. This also runs the tests on different operating systems
1818

1919
# Release
2020

21-
1. Delete existing distributions: `rm dist/*`
22-
2. Build the package. Requires the `build` package: `python3 -m build`
23-
3. Upload the source and build distribution: `python3 -m twine upload dist/*`. You might require
24-
a PyPI upload token to do this.
21+
1. Build the package using `uv build`
22+
2. Upload to package to PyPi using `uv publish`. You might also need to authenticate, for example
23+
by passing `--token <your token>` to the command.
2524

2625
# Post-Release
2726

src/cfdppy/filestore.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import os
88
import platform
99
import shutil
10+
import struct
1011
import subprocess
1112
from typing import TYPE_CHECKING, BinaryIO
1213

13-
from crcmod.predefined import PredefinedCrc
14+
import fastcrc
1415
from spacepackets.cfdp.defs import NULL_CHECKSUM_U32, ChecksumType
1516
from spacepackets.cfdp.tlv import FilestoreResponseStatusCode
1617

@@ -351,9 +352,12 @@ def checksum_type_to_crcmod_str(self, checksum_type: ChecksumType) -> str | None
351352
return "crc32c"
352353
raise ChecksumNotImplemented(checksum_type)
353354

355+
"""
356+
354357
def _generate_crc_calculator(self, checksum_type: ChecksumType) -> PredefinedCrc:
355358
self._verify_checksum(checksum_type)
356359
return PredefinedCrc(self.checksum_type_to_crcmod_str(checksum_type))
360+
"""
357361

358362
def calculate_checksum(
359363
self,
@@ -370,16 +374,26 @@ def calculate_checksum(
370374
return calc_modular_checksum(file_path)
371375
if segment_len == 0:
372376
raise ValueError("segment length can not be 0")
373-
crc_obj = self._generate_crc_calculator(checksum_type)
377+
func = None
378+
if checksum_type == ChecksumType.CRC_32:
379+
func = fastcrc.crc32.iso_hdlc
380+
elif checksum_type == ChecksumType.CRC_32C:
381+
func = fastcrc.crc32.iscsi
382+
else:
383+
raise ChecksumNotImplemented(checksum_type)
384+
current = func(b"")
374385
current_offset = 0
375386
# Calculate the file CRC
376387
with open(file_path, "rb") as file:
377388
while current_offset < size_to_verify:
378389
read_len = min(segment_len, size_to_verify - current_offset)
379390
if read_len > 0:
380-
crc_obj.update(self.read_from_opened_file(file, current_offset, read_len))
391+
current = func(
392+
self.read_from_opened_file(file, current_offset, read_len), current
393+
)
381394
current_offset += read_len
382-
return crc_obj.digest()
395+
assert current is not None
396+
return struct.pack("!I", current)
383397

384398

385399
HostFilestore = NativeFilestore

src/cfdppy/restricted_filestore.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,14 @@ def calculate_checksum(
133133

134134
def verify_checksum(
135135
self,
136-
checksum: bytes,
136+
checksum: int | bytes,
137137
checksum_type: ChecksumType,
138138
file_path: Path,
139139
size_to_verify: int,
140140
segment_len: int = 4096,
141141
) -> bool:
142+
if isinstance(checksum, int):
143+
checksum = checksum.to_bytes(4, "big")
142144
"""Verify checksum of file."""
143145
return super().verify_checksum(
144146
checksum=checksum,

tests/test_dest_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _insert_file_segment(
224224
)
225225
return fsm_res
226226

227-
def _generic_insert_eof_pdu(self, file_size: int, checksum: bytes) -> FsmResult:
227+
def _generic_insert_eof_pdu(self, file_size: int, checksum: int | bytes) -> FsmResult:
228228
eof_pdu = EofPdu(file_size=file_size, file_checksum=checksum, pdu_conf=self.src_pdu_conf)
229229
fsm_res = self.dest_handler.state_machine(eof_pdu)
230230
if self.expected_mode == TransmissionMode.UNACKNOWLEDGED:

0 commit comments

Comments
 (0)