From dccaae4e9c9d9e965e531249449302a80e65d5b2 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Wed, 2 May 2018 13:45:47 +0300 Subject: [PATCH] Update `setup.py`. Remove versions util. --- aiogram/__init__.py | 24 ++----- aiogram/utils/versions.py | 140 -------------------------------------- dev_requirements.txt | 1 + docs/source/conf.py | 2 +- setup.py | 45 +++++++----- 5 files changed, 36 insertions(+), 176 deletions(-) delete mode 100644 aiogram/utils/versions.py diff --git a/aiogram/__init__.py b/aiogram/__init__.py index 92ab5aa9..3fcd215c 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -1,27 +1,13 @@ -import warnings +import asyncio -try: - from .bot import Bot -except ImportError as e: - if e.name == 'aiohttp': - warnings.warn('Dependencies are not installed!', - category=ImportWarning) - else: - raise - -from .utils.versions import Stage, Version +from .bot import Bot try: import uvloop except ImportError: - pass + uvloop = None else: - import asyncio - asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) -VERSION = Version(1, 3, 1, stage=Stage.DEV, build=0) -API_VERSION = Version(3, 6) - -__version__ = VERSION.version -__api_version__ = API_VERSION.version +__version__ = '1.3.1.dev1' +__api_version__ = '3.6' diff --git a/aiogram/utils/versions.py b/aiogram/utils/versions.py deleted file mode 100644 index 1102a2e9..00000000 --- a/aiogram/utils/versions.py +++ /dev/null @@ -1,140 +0,0 @@ -import datetime -import os -import subprocess - -from .helper import Helper, HelperMode, Item - - -# Based on https://github.com/django/django/blob/master/django/utils/version.py - - -class Version: - def __init__(self, major=0, minor=0, - maintenance=0, stage='final', build=0): - self.__raw_version = None - self.__version = None - - self.version = (major, minor, maintenance, stage, build) - - @property - def version(self): - if self.__version is None: - self.__version = self.get_version() - return self.__version - - @version.setter - def version(self, version): - if not isinstance(version, (tuple, list)): - raise TypeError(f"`version` must be an instance of tuple/list, not {type(version)}") - self.__raw_version = version - self.__version = None - - @property - def major(self): - return self.__raw_version[0] - - @property - def minor(self): - return self.__raw_version[1] - - @property - def maintenance(self): - return self.__raw_version[2] - - @property - def stage(self): - return self.__raw_version[3] - - @property - def build(self): - return self.__raw_version[4] - - @property - def raw_version(self): - return self.raw_version - - @property - def pypi_development_status(self): - if self.stage == Stage.DEV: - status = '2 - Pre-Alpha' - elif self.stage == Stage.ALPHA: - status = '3 - Alpha' - elif self.stage == Stage.BETA: - status = '4 - Beta' - elif self.stage == Stage.FINAL: - status = '5 - Production/Stable' - else: - status = '1 - Planning' - return f"Development Status :: {status}" - - def get_version(self): - """ - Returns a PEP 440-compliant version number from VERSION. - :param: - :return: - """ - version = self.__raw_version - - # Now build the two parts of the version number: - # app = X.Y[.Z] - # sub = .devN - for pre-alpha releases - # | {a|b|rc}N - for alpha, beta, and rc releases - - main = self.get_main_version() - - sub = '' - if version[3] == Stage.DEV and version[4] == 0: - git_changeset = self.get_git_changeset() - if git_changeset: - sub = '.dev{0}'.format(git_changeset) - elif version[3] != Stage.FINAL: - mapping = {Stage.ALPHA: 'a', Stage.BETA: 'b', - Stage.RC: 'rc', Stage.DEV: 'dev'} - sub = mapping[version[3]] + str(version[4]) - - return str(main + sub) - - def get_main_version(self): - """ - Returns app version (X.Y[.Z]) from VERSION. - :param: - :return: - """ - version = self.__raw_version - parts = 2 if version[2] == 0 else 3 - return '.'.join(str(x) for x in version[:parts]) - - def get_git_changeset(self): - """Return a numeric identifier of the latest git changeset. - The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. - This value isn't guaranteed to be unique, but collisions are very unlikely, - so it's sufficient for generating the development version numbers. - """ - repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - git_log = subprocess.Popen( - 'git log --pretty=format:%ct --quiet -1 HEAD', - stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=True, cwd=repo_dir, universal_newlines=True, - ) - timestamp = git_log.communicate()[0] - try: - timestamp = datetime.datetime.utcfromtimestamp(int(timestamp)) - except ValueError: - return None - return timestamp.strftime('%Y%m%d%H%M%S') - - def __str__(self): - return self.version - - def __repr__(self): - return '' - - -class Stage(Helper): - mode = HelperMode.lowercase - - FINAL = Item() - ALPHA = Item() - BETA = Item() - RC = Item() - DEV = Item() diff --git a/dev_requirements.txt b/dev_requirements.txt index ba4f32bf..7f6f9b19 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -13,3 +13,4 @@ sphinx-rtd-theme>=0.3.0 aresponses>=1.0.0 tox>=3.0.0 aiosocksy>=0.1 +click>=6.7 diff --git a/docs/source/conf.py b/docs/source/conf.py index e321ec91..156643ea 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -61,7 +61,7 @@ author = 'Illemius / Alex Root Junior' # built documents. # # The short X.Y version. -version = '{0}.{1}'.format(aiogram.VERSION.major, aiogram.VERSION.minor) +version = aiogram.__version__ # The full version, including alpha/beta/rc tags. release = aiogram.__version__ diff --git a/setup.py b/setup.py index 0d267897..6b24e39c 100755 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 - +import pathlib +import re import sys -from warnings import warn from setuptools import find_packages, setup @@ -10,12 +10,25 @@ try: except ImportError: # pip >= 10.0.0 from pip._internal.req import parse_requirements -from aiogram import Stage, VERSION +WORK_DIR = pathlib.Path(__file__).parent +# Check python version MINIMAL_PY_VERSION = (3, 6) - if sys.version_info < MINIMAL_PY_VERSION: - warn('aiogram works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION)), RuntimeWarning)) + raise RuntimeError('aiogram works only with Python {}+'.format('.'.join(map(str, MINIMAL_PY_VERSION)))) + + +def get_version(): + """ + Read version + + :return: str + """ + txt = (WORK_DIR / 'aiogram' / '__init__.py').read_text('utf-8') + try: + return re.findall(r"^__version__ = '([^']+)'\r?$", txt, re.M)[0] + except IndexError: + raise RuntimeError('Unable to determine version.') def get_description(): @@ -29,35 +42,35 @@ def get_description(): return f.read() -def get_requirements(): +def get_requirements(filename=None): """ Read requirements from 'requirements txt' :return: requirements :rtype: list """ - filename = 'requirements.txt' - if VERSION.stage == Stage.DEV: - filename = 'dev_' + filename + if filename is None: + filename = 'requirements.txt' - install_reqs = parse_requirements(filename, session='hack') + file = WORK_DIR / filename + + install_reqs = parse_requirements(str(file), session='hack') return [str(ir.req) for ir in install_reqs] -install_requires = get_requirements() - setup( name='aiogram', - version=VERSION.version, + version=get_version(), packages=find_packages(exclude=('tests', 'tests.*', 'examples.*', 'docs',)), url='https://github.com/aiogram/aiogram', license='MIT', author='Alex Root Junior', - author_email='jroot.junior@gmail.com', + requires_python='>=3.6', + author_email='aiogram@illemius.xyz', description='Is a pretty simple and fully asynchronous library for Telegram Bot API', long_description=get_description(), classifiers=[ - VERSION.pypi_development_status, # Automated change classifier by build stage + 'Development Status :: 5 - Production/Stable' 'Environment :: Console', 'Framework :: AsyncIO', 'Intended Audience :: Developers', @@ -66,5 +79,5 @@ setup( 'Programming Language :: Python :: 3.6', 'Topic :: Software Development :: Libraries :: Application Frameworks', ], - install_requires=install_requires + install_requires=get_requirements() )