Skip to content

Commit

Permalink
setup.py: remove coerce_file machinery
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraymer committed Apr 9, 2019
1 parent 30ad02f commit ec0bf2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
4 changes: 1 addition & 3 deletions qifqif/__init__.py
Expand Up @@ -20,9 +20,7 @@
from qifqif import tags, qifile, config
from qifqif.ui import set_completer, complete_matches, colorize_match
from qifqif.terminal import TERM

__version__ = '0.7.3'
__author__ = 'Fabrice Laporte <kraymer+qifqif@gmail.com>'
from qifqif._version import __version__

ENCODING = 'utf-8' if sys.stdin.encoding in (None, 'ascii') else sys.stdin.encoding

Expand Down
2 changes: 2 additions & 0 deletions qifqif/_version.py
@@ -0,0 +1,2 @@
__version__ = '0.7.3'
__author__ = 'Fabrice Laporte <kraymer+qifqif@gmail.com>'
39 changes: 4 additions & 35 deletions setup.py
Expand Up @@ -7,43 +7,12 @@
import sys
from setuptools import setup


def coerce_file(fn):
"""Coerce file content to something useful for setuptools.setup(), turn :
.py into mock object by extracting __special__ attributes values
.md into rst text. Remove images with "[nopypi" alt text and emojis
:url: https://github.com/Kraymer/setupgoon
"""
import ast, os, re, subprocess, tempfile, time # noqa
text = open(os.path.join(os.path.dirname(__file__), fn)).read()
if fn.endswith('.py'): # extract version, docstring etc out of python file
mock = type('mock', (object,), {})()
for attr in ('version', 'author', 'author_email', 'license', 'url'):
regex = r'^__%s__\s*=\s*[\'"]([^\'"]*)[\'"]$' % attr
m = re.search(regex, text, re.MULTILINE)
setattr(mock, attr, m.group(1) if m else None)
mock.docstring = ast.get_docstring(ast.parse(text))
if mock.version.endswith('dev'):
mock.version += str(int(time.time()))
return mock
if fn.endswith('md'): # convert md to rest on pypi package upload
text = '\n'.join([l for l in text.split('\n') if '[nopypi' not in l])
text = re.sub(r':\S+:', '', text) # no emojis
with tempfile.NamedTemporaryFile(mode='w+') as tmp:
tmp.write(text)
tmp.flush()
try:
text, stderr = subprocess.Popen(['pandoc', '-t', 'rst', tmp.name],
stdout=subprocess.PIPE).communicate()
except:
pass
return text.decode('utf-8')

exec(open('qifqif/_version.py').read())

setup(name='qifqif',
version=coerce_file('qifqif/__init__.py').version,
description=coerce_file('qifqif/__init__.py').docstring,
long_description=coerce_file('README.md'),
version=__version__,
description='Enrich your QIF files with categories',
long_description=open('README.md').read(),
author='Fabrice Laporte',
author_email='kraymer@gmail.com',
url='https://github.com/KraYmer/qifqif',
Expand Down

0 comments on commit ec0bf2e

Please sign in to comment.