Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/fetchcode/package_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,9 @@ def get_pypi_latest_date(downloads):
latest_date = None
for download in downloads:
upload_time = download.get("upload_time_iso_8601")
if upload_time:
current_date = dateparser.parse(upload_time)
if not upload_time:
continue
current_date = dateparser.parse(upload_time)
if not latest_date:
latest_date = current_date
else:
Expand Down
30 changes: 30 additions & 0 deletions tests/test_pypi_missing_upload_dates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# fetchcode is a free software tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/fetchcode for support and download.

# Copyright (c) nexB Inc. and others. All rights reserved.
# http://nexb.com and http://aboutcode.org

# This software is licensed under the Apache License version 2.0.

# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at:
# http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from fetchcode.package_versions import get_pypi_latest_date


def test_pypi_latest_date_skips_missing_upload_times():
assert get_pypi_latest_date([{}, {"upload_time_iso_8601": None}]) is None
result = get_pypi_latest_date(
[
{},
{"upload_time_iso_8601": "2024-01-02T00:00:00Z"},
{},
{"upload_time_iso_8601": "2024-01-01T00:00:00Z"},
]
)
assert result.isoformat() == "2024-01-02T00:00:00+00:00"