Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.
Merged
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
76 changes: 6 additions & 70 deletions compatibility_lib/compatibility_lib/dependency_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@

from compatibility_lib import compatibility_checker
from compatibility_lib import compatibility_store
from compatibility_lib import configs
from compatibility_lib import utils

from datetime import datetime


DATETIME_FORMAT = "%Y-%m-%d"
DEFAULT_GRACE_PERIOD_IN_DAYS = 183 # applies to any version updates
MAJOR_GRACE_PERIOD_IN_DAYS = 30 # applies to major version updates only
ALLOWED_MINOR_DIFF = 3
Expand Down Expand Up @@ -90,57 +86,9 @@ class DependencyHighlighter(object):

def __init__(self, py_version='3'):
self.py_version = py_version
self._store = compatibility_store.CompatibilityStore()
self._checker = compatibility_checker.CompatibilityChecker()

def _get_from_bigquery(self, package_name):
"""Gets the package dependency info from bigquery

Args:
package_name: the name of the package to query
Returns:
a dict mapping from dependency package name (string) to
the info (dict)
"""
if package_name in configs.PKG_LIST:
depinfo = self._store.get_dependency_info(package_name)
return depinfo
else:
return None

def _get_from_endpoint(self, package_name):
"""Gets the package dependency info from the compatibility checker endpoint

Args:
package_name: the name of the package to query (string)
Returns:
a dict mapping from dependency package name (string) to
the info (dict)
"""
_result = self._checker.get_self_compatibility(self.py_version, [package_name])
result = [item for item in _result]
depinfo = result[0][0].get('dependency_info')

fields = ('installed_version_time', 'current_time', 'latest_version_time')
for pkgname in depinfo.keys():
for field in fields:
depinfo[pkgname][field] = _parse_datetime(depinfo[pkgname][field])

return depinfo

def _get_dependency_info(self, package_name):
"""Gets the package dependency info

Args:
package_name: the name of the package to query (string)
Returns:
a dict mapping from dependency package name (string) to
the info (dict)
"""
depinfo = self._get_from_bigquery(package_name)
if depinfo is None:
depinfo = self._get_from_endpoint(package_name)
return depinfo
self._store = utils.store
self._checker = utils.checker
self._dependency_info_getter = utils.DependencyInfo(py_version)

def _get_update_priority(self, install, latest, elapsed_time):
"""Returns the update priority level for an outdated dependency
Expand Down Expand Up @@ -188,7 +136,8 @@ def check_package(self, package_name):
Returns:
a list of outdated dependencies
"""
dependency_info = self._get_dependency_info(package_name)
dependency_info = self._dependency_info_getter.get_dependency_info(
package_name)
outdated_dependencies = []
for name, info in dependency_info.items():
priority = Priority()
Expand Down Expand Up @@ -252,16 +201,3 @@ def _sanitize_release_tag(release):
'patch': int(segments[2])
}
return release_info


def _parse_datetime(date_string):
"""Converts a date string into a datetime obj

Args:
date_string: a date as a string
Returns:
the date as a datetime obj
"""
date_string = date_string.replace('T', ' ')
short_date = date_string.split(' ')[0]
return datetime.strptime(short_date, DATETIME_FORMAT)
77 changes: 77 additions & 0 deletions compatibility_lib/compatibility_lib/deprecated_dep_finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.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.

import logging

from compatibility_lib import utils

DEPRECATED_STATUS = "Development Status :: 7 - Inactive"


class DeprecatedDepFinder(object):
"""A tool for finding if there are deprecated pacakges in the deps.

This tool looks at the development status field in the package info from
PyPI JSON API, and if the status if 'Development Status :: 7 - Inactive',
the package is deprecated.
"""

def __init__(self, py_version=None):
if py_version is None:
py_version = '3'

self.py_version = py_version
self._dependency_info_getter = utils.DependencyInfo(py_version)

def _get_development_status_from_pypi(self, package_name):
"""Get the development status for a package.

All kinds of development statuses:

Development Status :: 1 - Planning
Development Status :: 2 - Pre-Alpha
Development Status :: 3 - Alpha
Development Status :: 4 - Beta
Development Status :: 5 - Production/Stable
Development Status :: 6 - Mature
Development Status :: 7 - Inactive

Args:
package_name: the package needs to be checked.

Returns:
The development status of the package.
"""
pkg_info = utils.call_pypi_json_api(package_name=package_name)

try:
development_status = pkg_info['info']['classifiers'][0]
except (KeyError, IndexError):
logging.warning("No development status available.")
development_status = None

return development_status

def get_deprecated_deps(self, package_name):
dependency_info = self._dependency_info_getter.get_dependency_info(
package_name)
deprecated_deps = []

for dep_name in dependency_info:
development_status = self._get_development_status_from_pypi(
dep_name)
if development_status == DEPRECATED_STATUS:
deprecated_deps.append(dep_name)

return deprecated_deps
29 changes: 29 additions & 0 deletions compatibility_lib/compatibility_lib/fake_compatibility_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,32 @@ def save_compatibility_statuses(
for cr in compatibility_statuses:
self._packages_to_compatibility_result.setdefault(
frozenset(cr.packages), []).append(cr)

def get_dependency_info(self, package_name):
dep_info = {
"dep1": {
"installed_version": '0.1.0',
"installed_version_time": "2017-02-01 19:15:09+00:00",
"latest_version": "0.2.8.2",
"latest_version_time": "2018-06-22 22:12:44+00:00",
"is_latest": "false",
"current_time": "2018-08-16 01:08:59.193692+00:00"
},
"dep2": {
"installed_version": "1.0.2",
"installed_version_time": "2016-04-25 22:22:05+00:00",
"latest_version": "1.0.2",
"latest_version_time": "2016-04-25 22:22:05+00:00",
"is_latest": "true",
"current_time": "2018-08-16 01:08:59.490506+00:00"
},
"dep3": {
"installed_version": "0.16.0",
"installed_version_time": "2016-10-27 20:07:22+00:00",
"latest_version": "0.16.0",
"latest_version_time": "2016-10-27 20:07:22+00:00",
"is_latest": "true",
"current_time": "2018-08-16 01:08:59.554068+00:00"
},
}
return dep_info
Loading