Skip to content

Commit

Permalink
Merge pull request #8 from jantman/fix-build
Browse files Browse the repository at this point in the history
Bug fix, Python version deprecations, build fixes, version 1.0.0
  • Loading branch information
jantman committed Oct 27, 2019
2 parents 773dd9c + 77f9b7b commit dcaa53c
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 62 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ exclude_lines =
if sys.version_info.+
raise NotImplementedError
except ImportError:
except \(ImportError, KeyError\):
.*# nocoverage.*
22 changes: 9 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@ cache: pip

matrix:
include:
- python: "2.7"
env: TOXENV=py27-acceptance
- python: "3.3"
env: TOXENV=py33-acceptance
- python: "3.4"
env: TOXENV=py34-acceptance
- python: "3.5"
env: TOXENV=py35-acceptance
- python: "3.6"
env: TOXENV=py36-acceptance
- python: "2.7"
env: TOXENV=py27-unit
- python: "3.3"
env: TOXENV=py33-unit
- python: "3.4"
env: TOXENV=py34-unit
- python: "3.7"
env: TOXENV=py37-acceptance
- python: "3.8"
env: TOXENV=py38-acceptance
- python: "3.5"
env: TOXENV=py35-unit
- python: "3.6"
env: TOXENV=py36-unit
- python: "2.7"
- python: "3.7"
env: TOXENV=py37-unit
- python: "3.8"
env: TOXENV=py38-unit
- python: "3.7"
env: TOXENV=docs

install:
Expand Down
15 changes: 15 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Changelog
=========

1.0.0 (2019-10-27)
------------------

**Important:** in keeping with the scheduled end-of-life of various Python versions, versionfinder now only officially supports Python 3.5 or greater. A DeprecationWarning will be generated when run with versions before 3.5, and they are no longer tested.

* Fix `Issue #7 <https://github.com/jantman/versionfinder/issues/7>`_ where certain new versions of pip throw an AttributeError on import if running in Lambda (or other environments where ``sys.stdin`` is ``None``).
* Stop testing Python 3.3 and drop official support for it.
* Stop testing Python 2.7 and 3.4.
* Add DeprecationWarnings for any Python version < 3.5.
* Multiple pip10 fixes.
* Test fixes:

* Always install latest versions of ``coverage`` and ``pytest``.
* Switch docs build to py37
* Begin testing under py37 and py38

0.1.3 (2018-03-18)
------------------
Expand Down
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ tag or commit from a git repo, or has local changes not committed to git.
Requirements
------------

* Python 2.7, or Python 3.3+. Python 3.0-3.2 is not supported. Python 2.6 should
function, but will not return detailed git information and is not tested.
* Python 2.7, or Python 3.4+. Python 3.0-3.2 is not supported. Python 3.3 was supported
but is no longer tested. Python 2.6 might function, but will not return detailed
git information and is not tested.

Usage
-----
Expand Down Expand Up @@ -164,7 +165,7 @@ Guidelines
Testing
-------

Testing is done via `pytest <http://pytest.org/latest/>`_, driven by `tox <https://tox.readthedocs.org/>`_.
Testing is done via `pytest <https://docs.pytest.org/en/latest/>`_, driven by `tox <https://tox.readthedocs.org/>`_.

* testing is as simple as:

Expand Down
7 changes: 3 additions & 4 deletions docs/source/versionfinder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ versionfinder package
=====================

.. automodule:: versionfinder
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:

Submodules
----------
Expand All @@ -14,4 +14,3 @@ Submodules
versionfinder.version
versionfinder.versionfinder
versionfinder.versioninfo

6 changes: 3 additions & 3 deletions docs/source/versionfinder.version.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ versionfinder.version module
============================

.. automodule:: versionfinder.version
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/versionfinder.versionfinder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ versionfinder.versionfinder module
==================================

.. automodule:: versionfinder.versionfinder
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions docs/source/versionfinder.versioninfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ versionfinder.versioninfo module
================================

.. automodule:: versionfinder.versioninfo
:members:
:undoc-members:
:show-inheritance:
:members:
:undoc-members:
:show-inheritance:
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@
long_description = fh.read()

classifiers = [
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
Expand Down
10 changes: 4 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[tox]
envlist = {py27,py33,py34,py35,py36}-{unit,acceptance},docs
envlist = {py35,py36,py37,py38}-{unit,acceptance},docs

[testenv]
deps =
cov-core
execnet
pep8
py
py33: pytest<3.3.0
{py27,py34,py35,py36}-{unit,acceptance}: pytest>=3.3.0
pytest
pytest-cache
pytest-cov
pytest-pep8
Expand All @@ -19,8 +18,7 @@ deps =
requests
virtualenv
backoff
py36: coverage
{py27,py33,py34,py35}-{unit,acceptance}: coverage==3.7.1
coverage

passenv=TRAVIS*
setenv =
Expand Down Expand Up @@ -52,7 +50,7 @@ deps =
pygments
sphinx
sphinx_rtd_theme
basepython = python2.7
basepython = python3.7
commands =
python --version
virtualenv --version
Expand Down
2 changes: 1 addition & 1 deletion versionfinder/tests/test_acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _set_git_config(self, set_in_travis=False):
'config',
'user.email'
]).strip()
except subprocess.CalledProcessError as ex:
except subprocess.CalledProcessError:
res = None
if res != '' and res is not None:
print("Got git config user.email as %s" % res)
Expand Down
16 changes: 8 additions & 8 deletions versionfinder/tests/test_versionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,9 @@ def test_find(self):
req='foo==4.5.6'
)

with patch('%s.pip.get_installed_distributions' % pbm
with patch('%s.get_installed_distributions' % pbm
) as mock_pgid:
with patch('%s.pip.FrozenRequirement.from_dist' % pbm
with patch('%s.FrozenRequirement.from_dist' % pbm
) as mock_from_dist:
with patch('%s._dist_version_url' % pb) as mock_dist_vu:
mock_pgid.return_value = installed_dists
Expand All @@ -734,9 +734,9 @@ def test_no_dist(self):
req='awslimitchecker==0.1.0'
)

with patch('%s.pip.get_installed_distributions' % pbm
with patch('%s.get_installed_distributions' % pbm
) as mock_pgid:
with patch('%s.pip.FrozenRequirement.from_dist' % pbm
with patch('%s.FrozenRequirement.from_dist' % pbm
) as mock_from_dist:
with patch('%s._dist_version_url' % pb) as mock_dist_vu:
mock_pgid.return_value = installed_dists
Expand All @@ -760,9 +760,9 @@ def test_req_https(self):
req=req_str
)

with patch('%s.pip.get_installed_distributions' % pbm
with patch('%s.get_installed_distributions' % pbm
) as mock_pgid:
with patch('%s.pip.FrozenRequirement.from_dist' % pbm
with patch('%s.FrozenRequirement.from_dist' % pbm
) as mock_from_dist:
with patch('%s._dist_version_url' % pb) as mock_dist_vu:
mock_pgid.return_value = installed_dists
Expand All @@ -787,9 +787,9 @@ def test_req_git(self):
req=req_str
)

with patch('%s.pip.get_installed_distributions' % pbm
with patch('%s.get_installed_distributions' % pbm
) as mock_pgid:
with patch('%s.pip.FrozenRequirement.from_dist' % pbm
with patch('%s.FrozenRequirement.from_dist' % pbm
) as mock_from_dist:
with patch('%s._dist_version_url' % pb) as mock_dist_vu:
mock_pgid.return_value = installed_dists
Expand Down
2 changes: 1 addition & 1 deletion versionfinder/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
##################################################################################
"""

VERSION = '0.1.3'
VERSION = '1.0.0'
PROJECT_URL = 'https://github.com/jantman/versionfinder'
64 changes: 54 additions & 10 deletions versionfinder/versionfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,44 @@
################################################################################
"""

import sys
import os
import logging
import inspect
from contextlib import contextmanager
import warnings

from .versioninfo import VersionInfo

# Note: we catch all exceptions here because of
# https://github.com/jantman/versionfinder/issues/7 - some pip versions
# throw an import-time AttributeError when running in Lambda, or other
# environments where sys.stdin is None. Per that issue, the right thing to
# do is never fail if pip can't be imported.
# This was fixed in https://github.com/pypa/pip/pull/7118 / pip 19.3
try:
import pip._internal as pip
except (ImportError, KeyError):
from pip._internal.operations.freeze import FrozenRequirement
except Exception: # nocoverage
try:
import pip
except (ImportError, KeyError):
# this is used within try blocks; NBD if they fail
pass
from pip._internal import FrozenRequirement
except Exception:
try:
from pip import FrozenRequirement
except Exception:
# this is used within try blocks; NBD if they fail
pass

try:
from pip._internal.utils.misc import get_installed_distributions
except Exception: # nocoverage
try:
from pip._internal import get_installed_distributions
except Exception:
try:
from pip import get_installed_distributions
except Exception:
# this is used within try blocks; NBD if they fail
pass

try:
import pkg_resources
Expand All @@ -61,12 +84,16 @@

try:
from git import Repo
except Exception:
except Exception: # nocoverage
# this is used within try blocks; NBD if they fail
pass

logger = logging.getLogger(__name__)

warnings.filterwarnings(
action="always", category=DeprecationWarning, module=__name__
)


class VersionFinder(object):

Expand Down Expand Up @@ -120,6 +147,17 @@ def __init__(self, package_name, package_file=None, log=False,
logger.debug('package_dir: %s' % self.package_dir)
self._pip_locations = []
self._pkg_resources_locations = []
if (
sys.version_info[0] < 3 or
sys.version_info[0] == 3 and sys.version_info[1] < 5
): # nocoverage
warnings.warn(
'The versionfinder package no longer supports Python %d.%d; '
'please switch to Python 3.5 or newer.' % (
sys.version_info[0], sys.version_info[1]
),
DeprecationWarning
)

def find_package_version(self):
"""
Expand Down Expand Up @@ -160,7 +198,10 @@ def find_package_version(self):
pip_info = self._find_pip_info()
except Exception:
# we NEVER want this to crash the program
logger.debug('Caught exception running _find_pip_info()')
logger.debug(
'Caught exception running _find_pip_info()',
exc_info=True
)
pip_info = {}
logger.debug("pip info: %s", pip_info)
for k, v in pip_info.items():
Expand Down Expand Up @@ -234,7 +275,7 @@ def _find_pip_info(self):
dist = None
dist_name = self.package_name.replace('_', '-')
logger.debug('Checking for pip distribution named: %s', dist_name)
for d in pip.get_installed_distributions():
for d in get_installed_distributions():
if d.project_name == dist_name:
dist = d
if dist is None:
Expand All @@ -246,7 +287,10 @@ def _find_pip_info(self):
res['version'] = ver
res['url'] = url
# this is a bit of an ugly, lazy hack...
req = pip.FrozenRequirement.from_dist(dist, [])
try:
req = FrozenRequirement.from_dist(dist, [])
except TypeError: # nocoverage
req = FrozenRequirement.from_dist(dist)
logger.debug('pip FrozenRequirement: %s', req)
res['requirement'] = str(req.req)
return res
Expand Down

0 comments on commit dcaa53c

Please sign in to comment.