From f86e0df198d6ee53421e9c1dadc46dc805f53370 Mon Sep 17 00:00:00 2001 From: Darcy Mason Date: Tue, 15 Aug 2023 15:43:46 -0400 Subject: [PATCH] Fix codify rel path (#1867) * cherry-picked from main branch of 3.0 dev --- doc/release_notes/index.rst | 1 + doc/release_notes/v2.4.3.rst | 7 +++++++ pydicom/cli/main.py | 3 ++- pydicom/tests/test_util.py | 7 +++++++ pyproject.toml | 2 +- 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 doc/release_notes/v2.4.3.rst diff --git a/doc/release_notes/index.rst b/doc/release_notes/index.rst index f969497a7e..678a929343 100644 --- a/doc/release_notes/index.rst +++ b/doc/release_notes/index.rst @@ -2,6 +2,7 @@ Release notes ============= +.. include:: v2.4.3.rst .. include:: v2.4.0.rst .. include:: v2.3.0.rst .. include:: v2.2.0.rst diff --git a/doc/release_notes/v2.4.3.rst b/doc/release_notes/v2.4.3.rst new file mode 100644 index 0000000000..0f5836730e --- /dev/null +++ b/doc/release_notes/v2.4.3.rst @@ -0,0 +1,7 @@ +Version 2.4.3 +============== + +Fixes +----- + +* Fixed pydicom codify error when relative path did not exist \ No newline at end of file diff --git a/pydicom/cli/main.py b/pydicom/cli/main.py index a97ecd4d95..9df02f59d4 100644 --- a/pydicom/cli/main.py +++ b/pydicom/cli/main.py @@ -137,7 +137,8 @@ def filespec_parser(filespec: str) -> List[Tuple[Dataset, Any]]: if not pydicom_filename: try: char_filenames = get_charset_files(filename) - pydicom_filename = char_filenames[0] + if char_filenames: + pydicom_filename = char_filenames[0] except NotImplementedError: # will get this if absolute path passed pass diff --git a/pydicom/tests/test_util.py b/pydicom/tests/test_util.py index f5ecfbfbde..736ca1d2cb 100644 --- a/pydicom/tests/test_util.py +++ b/pydicom/tests/test_util.py @@ -171,6 +171,13 @@ def test_code_file(self, capsys): out, err = capsys.readouterr() assert r"c:\temp\testout.dcm" in out + def test_code_relative_filename(self, capsys): + """Test utils.codify.code_file with a relative path that doesn't exist""" + # regression test for #1865 + args = ["XXxUN_sequenceXX.dcm"] # file that doesn't exist + with pytest.raises(SystemExit): + codify_main(100, args) + def test_code_dataelem_at(self): """Test utils.codify.code_dataelem""" elem = DataElement(0x00000901, 'AT', (0x1234, 0x5678)) diff --git a/pyproject.toml b/pyproject.toml index 36cd391164..f8dc6ee8d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ license = {text = "MIT"} name = "pydicom" readme = "README.md" requires-python = ">=3.7" -version = "2.4.2" +version = "2.4.3" [project.optional-dependencies]