Skip to content

Commit a57f80a

Browse files
Skip missing upload timestamps when finding PyPI release dates
Signed-off-by: Ali Zulfiqar <codewithfourtix@gmail.com>
1 parent 27c4fc9 commit a57f80a

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/fetchcode/package_versions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,9 @@ def get_pypi_latest_date(downloads):
499499
latest_date = None
500500
for download in downloads:
501501
upload_time = download.get("upload_time_iso_8601")
502-
if upload_time:
503-
current_date = dateparser.parse(upload_time)
502+
if not upload_time:
503+
continue
504+
current_date = dateparser.parse(upload_time)
504505
if not latest_date:
505506
latest_date = current_date
506507
else:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# fetchcode is a free software tool from nexB Inc. and others.
2+
# Visit https://github.com/aboutcode-org/fetchcode for support and download.
3+
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# http://nexb.com and http://aboutcode.org
6+
7+
# This software is licensed under the Apache License version 2.0.
8+
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at:
11+
# http://apache.org/licenses/LICENSE-2.0
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
from fetchcode.package_versions import get_pypi_latest_date
18+
19+
20+
def test_pypi_latest_date_skips_missing_upload_times():
21+
assert get_pypi_latest_date([{}, {"upload_time_iso_8601": None}]) is None
22+
result = get_pypi_latest_date(
23+
[
24+
{},
25+
{"upload_time_iso_8601": "2024-01-02T00:00:00Z"},
26+
{},
27+
{"upload_time_iso_8601": "2024-01-01T00:00:00Z"},
28+
]
29+
)
30+
assert result.isoformat() == "2024-01-02T00:00:00+00:00"

0 commit comments

Comments
 (0)