From 867333db87cbc67529dfc49b46afd97dae138f5a Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Mon, 4 Jul 2016 13:16:42 +0200 Subject: [PATCH] move version check to setup.py --- pirate/pirate.py | 5 ---- setup.py | 57 +++++++++++++++++++++++++------------------ tests/test_version.py | 13 ++++++---- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/pirate/pirate.py b/pirate/pirate.py index c0052ef..87899ac 100755 --- a/pirate/pirate.py +++ b/pirate/pirate.py @@ -1,9 +1,4 @@ import sys -from distutils.version import LooseVersion -if LooseVersion(sys.version) < LooseVersion("3.4.0"): - print("At least python 3.4.0 required. Your version is "+sys.version) - sys.exit(1) - import re import os import argparse diff --git a/setup.py b/setup.py index 170db9d..269598f 100755 --- a/setup.py +++ b/setup.py @@ -1,27 +1,36 @@ #!/usr/bin/env python3 from setuptools import setup, find_packages +from distutils.version import LooseVersion +import sys -setup(name='pirate-get', - version='0.2.8', - description='A command line interface for The Pirate Bay', - url='https://github.com/vikstrous/pirate-get', - author='vikstrous', - author_email='me@viktorstanchev.com', - license='AGPL', - packages=find_packages(), - package_data={'': ["data/*.json"]}, - entry_points={ - 'console_scripts': ['pirate-get = pirate.pirate:main'] - }, - install_requires=['colorama>=0.3.3', 'beautifulsoup4>=4.4.1', 'veryprettytable>=0.8.1'], - keywords=['torrent', 'magnet', 'download', 'tpb', 'client'], - classifiers=[ - 'Topic :: Utilities', - 'Topic :: Terminals', - 'Topic :: System :: Networking', - 'Programming Language :: Python :: 3 :: Only', - 'Programming Language :: Python :: 3.4', - 'License :: OSI Approved :: GNU General Public License (GPL)', - ], - test_suite='tests', -) +if LooseVersion(sys.version) < LooseVersion("3.4.0"): + print("pirate-get requires at least python 3.4.0." + " Your version is %s." % sys.version.split()[0]) + sys.exit(1) + +if __name__ == '__main__': + setup(name='pirate-get', + version='0.2.8', + description='A command line interface for The Pirate Bay', + url='https://github.com/vikstrous/pirate-get', + author='vikstrous', + author_email='me@viktorstanchev.com', + license='AGPL', + packages=find_packages(), + package_data={'': ["data/*.json"]}, + entry_points={ + 'console_scripts': ['pirate-get = pirate.pirate:main'] + }, + install_requires=['colorama>=0.3.3', + 'beautifulsoup4>=4.4.1', + 'veryprettytable>=0.8.1'], + keywords=['torrent', 'magnet', 'download', 'tpb', 'client'], + classifiers=[ + 'Topic :: Utilities', + 'Topic :: Terminals', + 'Topic :: System :: Networking', + 'Programming Language :: Python :: 3 :: Only', + 'Programming Language :: Python :: 3.4', + 'License :: OSI Approved :: GNU General Public License (GPL)', + ], + test_suite='tests') diff --git a/tests/test_version.py b/tests/test_version.py index 8894e8d..6820887 100755 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,37 +1,40 @@ #!/usr/bin/env python3 import sys +import os.path import unittest import importlib from unittest import mock from unittest.mock import patch, call, MagicMock -import pirate.pirate +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +import setup class TestPirate(unittest.TestCase): @patch('sys.exit') def test_unsupported(self, mock_exit): sys.version = '3.2.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' - importlib.reload(pirate.pirate) + importlib.reload(setup) mock_exit.assert_called_once_with(1) @patch('sys.exit') def test_unsupported2(self, mock_exit): sys.version = '2.5.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' - importlib.reload(pirate.pirate) + importlib.reload(setup) mock_exit.assert_called_once_with(1) @patch('sys.exit') def test_supported(self, mock_exit): sys.version = '3.5.1 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' - importlib.reload(pirate.pirate) + importlib.reload(setup) mock_exit.assert_not_called() @patch('sys.exit') def test_supported_exact(self, mock_exit): sys.version = '3.4.0 (default, dec 7 2015, 12:58:09) \n[gcc 5.2.0]' - importlib.reload(pirate.pirate) + importlib.reload(setup) mock_exit.assert_not_called() if __name__ == '__main__':