Last active
August 29, 2015 14:18
-
-
Save utek/469c20aa85bcccf1109f to your computer and use it in GitHub Desktop.
Getting info from .py files without eval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from .ddd import ( | |
DDD | |
) | |
__version__ = "0.5.1" | |
__author__ = "Łukasz Bołdys" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import os | |
import ast | |
from setuptools import setup, find_packages | |
def get_info(filename): | |
info = {} | |
with open(filename) as _file: | |
data = ast.parse(_file.read()) | |
for node in data.body: | |
if type(node) != ast.Assign: | |
continue | |
if type(node.value) not in [ast.Str, ast.Num]: | |
continue | |
name = None | |
for target in node.targets: | |
name = target.id | |
if type(node.value) == ast.Str: | |
info[name] = node.value.s | |
elif type(node.value) == ast.Num: | |
info[name] = node.value.n | |
return info | |
file_with_packageinfo = "esmfiledecoder/__init__.py" | |
info = get_info(file_with_packageinfo) | |
here = os.path.abspath(os.path.dirname(__file__)) | |
# README = open(os.path.join(here, 'README.txt')).read() | |
# CHANGES = open(os.path.join(here, 'CHANGES.txt')).read() | |
requires = [ | |
] | |
setup(name='ESMFileDecoder', | |
version=info.get('__version__', '0.0.0'), | |
description='ESM (ddd) file decoder.', | |
# long_description=README + '\n\n' + CHANGES, | |
classifiers=[ | |
"Programming Language :: Python", | |
], | |
author=info.get('__author__', 'Łukasz Bołdys'), | |
author_email='[email protected]', | |
url='http://utek.pl', | |
keywords='file tachograph decoder', | |
packages=find_packages(), | |
include_package_data=True, | |
zip_safe=False, | |
test_suite='esmfiledecoder', | |
install_requires=requires, | |
entry_points="""\ | |
[console_scripts] | |
ddd = esmfiledecoder.scripts.analyze:main | |
""", | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment