File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ class CondaPackage(TypedDict):
34
34
Internal package for unifying Conda package definitions to.
35
35
"""
36
36
base_url : str
37
- build_number : int
37
+ build_number : Optional [ int ]
38
38
build_string : str
39
39
channel : str
40
40
dist_name : str
@@ -96,13 +96,20 @@ def parse_conda_list_str_to_conda_package(conda_list_str: str) -> Optional[Conda
96
96
pos = build_number_with_opt_string .find ('.' )
97
97
build_number_with_opt_string = build_number_with_opt_string [0 :pos ]
98
98
99
+ build_string : str
100
+ build_number : Optional [int ]
101
+
99
102
if '_' in build_number_with_opt_string :
100
103
bnbs_parts = build_number_with_opt_string .split ('_' )
101
- if len (bnbs_parts ) == 2 :
102
- build_number = int (bnbs_parts .pop ())
104
+ # Build number will be the last part - check if it's an integer
105
+ # Updated logic given https://github.com/CycloneDX/cyclonedx-python-lib/issues/65
106
+ candidate_build_number : str = bnbs_parts .pop ()
107
+ if candidate_build_number .isdigit ():
108
+ build_number = int (candidate_build_number )
103
109
build_string = build_number_with_opt_string
104
110
else :
105
- raise ValueError (f'Unexpected build version string for Conda Package: { conda_list_str } ' )
111
+ build_number = None
112
+ build_string = build_number_with_opt_string
106
113
else :
107
114
build_string = ''
108
115
build_number = int (build_number_with_opt_string )
Original file line number Diff line number Diff line change @@ -107,3 +107,20 @@ def test_parse_conda_list_str_with_hash_3(self) -> None:
107
107
self .assertEqual (cp ['platform' ], 'noarch' )
108
108
self .assertEqual (cp ['version' ], '2.10' )
109
109
self .assertEqual (cp ['md5_hash' ], '153ff132f593ea80aae2eea61a629c92' )
110
+
111
+ def test_parse_conda_list_str_with_hash_4 (self ) -> None :
112
+ cp : CondaPackage = parse_conda_list_str_to_conda_package (
113
+ conda_list_str = 'https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2'
114
+ '#d7c89558ba9fa0495403155b64376d81'
115
+ )
116
+
117
+ self .assertIsInstance (cp , dict )
118
+ self .assertEqual (cp ['base_url' ], 'https://conda.anaconda.org/conda-forge' )
119
+ self .assertIsNone (cp ['build_number' ])
120
+ self .assertEqual (cp ['build_string' ], 'conda_forge' )
121
+ self .assertEqual (cp ['channel' ], 'conda-forge' )
122
+ self .assertEqual (cp ['dist_name' ], '_libgcc_mutex-0.1-conda_forge' )
123
+ self .assertEqual (cp ['name' ], '_libgcc_mutex' )
124
+ self .assertEqual (cp ['platform' ], 'linux-64' )
125
+ self .assertEqual (cp ['version' ], '0.1' )
126
+ self .assertEqual (cp ['md5_hash' ], 'd7c89558ba9fa0495403155b64376d81' )
You can’t perform that action at this time.
0 commit comments