2017-06-21 20:18:22 +03:00
|
|
|
#!/usr/bin/env python3
|
2016-09-18 12:59:12 +03:00
|
|
|
"""A setuptools based setup module.
|
|
|
|
|
|
|
|
See:
|
|
|
|
https://packaging.python.org/en/latest/distributing.html
|
|
|
|
https://github.com/pypa/sampleproject
|
2017-06-21 12:27:22 +03:00
|
|
|
|
|
|
|
Extra supported commands are:
|
|
|
|
* gen_tl, to generate the classes required for Telethon to run
|
|
|
|
* clean_tl, to clean these generated classes
|
2017-09-18 15:03:06 +03:00
|
|
|
* pypi, to generate sdist, bdist_wheel, and push to PyPi
|
2016-09-18 12:59:12 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
# To use a consistent encoding
|
|
|
|
from codecs import open
|
2017-06-21 12:27:22 +03:00
|
|
|
from sys import argv
|
2017-09-29 13:38:53 +03:00
|
|
|
import os
|
2017-10-28 13:21:07 +03:00
|
|
|
import re
|
2016-09-18 12:59:12 +03:00
|
|
|
|
2016-11-30 00:29:42 +03:00
|
|
|
# Always prefer setuptools over distutils
|
|
|
|
from setuptools import find_packages, setup
|
|
|
|
|
2017-06-21 12:27:22 +03:00
|
|
|
|
2017-09-29 13:38:53 +03:00
|
|
|
class TempWorkDir:
|
|
|
|
"""Switches the working directory to be the one on which this file lives,
|
|
|
|
while within the 'with' block.
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
self.original = None
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
self.original = os.path.abspath(os.path.curdir)
|
|
|
|
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, *args):
|
|
|
|
os.chdir(self.original)
|
|
|
|
|
|
|
|
|
2017-10-20 18:29:45 +03:00
|
|
|
ERROR_LIST = 'telethon/errors/rpc_error_list.py'
|
|
|
|
ERRORS_JSON = 'telethon_generator/errors.json'
|
|
|
|
ERRORS_DESC = 'telethon_generator/error_descriptions'
|
|
|
|
SCHEME_TL = 'telethon_generator/scheme.tl'
|
2017-10-20 18:32:30 +03:00
|
|
|
GENERATOR_DIR = 'telethon/tl'
|
2017-10-20 18:29:45 +03:00
|
|
|
IMPORT_DEPTH = 2
|
|
|
|
|
|
|
|
|
2017-09-29 13:40:03 +03:00
|
|
|
def gen_tl():
|
|
|
|
from telethon_generator.tl_generator import TLGenerator
|
2017-10-20 18:29:45 +03:00
|
|
|
from telethon_generator.error_generator import generate_code
|
2017-10-20 18:32:30 +03:00
|
|
|
generator = TLGenerator(GENERATOR_DIR)
|
2017-09-29 13:40:03 +03:00
|
|
|
if generator.tlobjects_exist():
|
|
|
|
print('Detected previous TLObjects. Cleaning...')
|
|
|
|
generator.clean_tlobjects()
|
|
|
|
|
|
|
|
print('Generating TLObjects...')
|
2017-10-20 18:29:45 +03:00
|
|
|
generator.generate_tlobjects(SCHEME_TL, import_depth=IMPORT_DEPTH)
|
|
|
|
print('Generating errors...')
|
|
|
|
generate_code(ERROR_LIST, json_file=ERRORS_JSON, errors_desc=ERRORS_DESC)
|
2017-09-29 13:40:03 +03:00
|
|
|
print('Done.')
|
|
|
|
|
|
|
|
|
2017-09-29 13:38:53 +03:00
|
|
|
def main():
|
2017-06-21 12:27:22 +03:00
|
|
|
if len(argv) >= 2 and argv[1] == 'gen_tl':
|
2017-09-29 13:40:03 +03:00
|
|
|
gen_tl()
|
2017-06-21 12:27:22 +03:00
|
|
|
|
|
|
|
elif len(argv) >= 2 and argv[1] == 'clean_tl':
|
2017-07-04 12:02:32 +03:00
|
|
|
from telethon_generator.tl_generator import TLGenerator
|
2017-06-21 12:27:22 +03:00
|
|
|
print('Cleaning...')
|
2017-10-20 18:32:30 +03:00
|
|
|
TLGenerator(GENERATOR_DIR).clean_tlobjects()
|
2017-06-21 12:27:22 +03:00
|
|
|
print('Done.')
|
|
|
|
|
2017-09-18 15:03:06 +03:00
|
|
|
elif len(argv) >= 2 and argv[1] == 'pypi':
|
2017-11-29 14:34:15 +03:00
|
|
|
# (Re)generate the code to make sure we don't push without it
|
|
|
|
gen_tl()
|
|
|
|
|
|
|
|
# Try importing the telethon module to assert it has no errors
|
|
|
|
try:
|
|
|
|
import telethon
|
|
|
|
except:
|
|
|
|
print('Packaging for PyPi aborted, importing the module failed.')
|
|
|
|
return
|
|
|
|
|
2017-09-19 11:16:41 +03:00
|
|
|
# Need python3.5 or higher, but Telethon is supposed to support 3.x
|
|
|
|
# Place it here since noone should be running ./setup.py pypi anyway
|
|
|
|
from subprocess import run
|
|
|
|
from shutil import rmtree
|
|
|
|
|
2017-09-18 15:03:06 +03:00
|
|
|
for x in ('build', 'dist', 'Telethon.egg-info'):
|
|
|
|
rmtree(x, ignore_errors=True)
|
|
|
|
run('python3 setup.py sdist', shell=True)
|
|
|
|
run('python3 setup.py bdist_wheel', shell=True)
|
|
|
|
run('twine upload dist/*', shell=True)
|
|
|
|
for x in ('build', 'dist', 'Telethon.egg-info'):
|
|
|
|
rmtree(x, ignore_errors=True)
|
|
|
|
|
2017-10-22 14:57:02 +03:00
|
|
|
elif len(argv) >= 2 and argv[1] == 'fetch_errors':
|
2017-10-20 18:29:45 +03:00
|
|
|
from telethon_generator.error_generator import fetch_errors
|
|
|
|
fetch_errors(ERRORS_JSON)
|
|
|
|
|
2017-06-21 12:27:22 +03:00
|
|
|
else:
|
|
|
|
# Get the long description from the README file
|
2017-09-29 13:38:53 +03:00
|
|
|
with open('README.rst', encoding='utf-8') as f:
|
2017-06-21 12:27:22 +03:00
|
|
|
long_description = f.read()
|
|
|
|
|
2017-10-28 13:21:07 +03:00
|
|
|
with open('telethon/version.py', encoding='utf-8') as f:
|
|
|
|
version = re.search(r"^__version__\s+=\s+'(.*)'$",
|
|
|
|
f.read(), flags=re.MULTILINE).group(1)
|
2017-06-21 12:27:22 +03:00
|
|
|
setup(
|
|
|
|
name='Telethon',
|
2017-09-29 13:40:03 +03:00
|
|
|
version=version,
|
2017-06-21 12:27:22 +03:00
|
|
|
description="Full-featured Telegram client library for Python 3",
|
|
|
|
long_description=long_description,
|
|
|
|
|
|
|
|
url='https://github.com/LonamiWebs/Telethon',
|
|
|
|
download_url='https://github.com/LonamiWebs/Telethon/releases',
|
|
|
|
|
|
|
|
author='Lonami Exo',
|
|
|
|
author_email='totufals@hotmail.com',
|
|
|
|
|
|
|
|
license='MIT',
|
|
|
|
|
|
|
|
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
|
|
|
|
classifiers=[
|
|
|
|
# 3 - Alpha
|
|
|
|
# 4 - Beta
|
|
|
|
# 5 - Production/Stable
|
|
|
|
'Development Status :: 3 - Alpha',
|
|
|
|
|
|
|
|
'Intended Audience :: Developers',
|
|
|
|
'Topic :: Communications :: Chat',
|
|
|
|
|
|
|
|
'License :: OSI Approved :: MIT License',
|
|
|
|
|
|
|
|
'Programming Language :: Python :: 3',
|
|
|
|
'Programming Language :: Python :: 3.3',
|
|
|
|
'Programming Language :: Python :: 3.4',
|
|
|
|
'Programming Language :: Python :: 3.5',
|
|
|
|
'Programming Language :: Python :: 3.6'
|
|
|
|
],
|
|
|
|
keywords='telegram api chat client library messaging mtproto',
|
|
|
|
packages=find_packages(exclude=[
|
|
|
|
'telethon_generator', 'telethon_tests', 'run_tests.py',
|
|
|
|
'try_telethon.py'
|
|
|
|
]),
|
2017-08-24 19:39:38 +03:00
|
|
|
install_requires=['pyaes', 'rsa']
|
2017-06-21 12:27:22 +03:00
|
|
|
)
|
2017-09-29 13:38:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
with TempWorkDir(): # Could just use a try/finally but this is + reusable
|
|
|
|
main()
|