diff options
author | Adam Chainz <me@adamj.eu> | 2016-09-28 21:12:32 +0100 |
---|---|---|
committer | Stefan Wójcik <wojcikstefan@gmail.com> | 2016-09-28 16:12:32 -0400 |
commit | 7799be4a1cd2d68f70293a515bba1392b989531b (patch) | |
tree | 05aedb0ac342c0d36e4ff2aeec9154d3b7086970 /setup.py | |
parent | 9e6ee2f9f0977a3375e65b417543c50450a1db1b (diff) | |
download | python-mimeparse-7799be4a1cd2d68f70293a515bba1392b989531b.tar.gz |
setup.py + README tidying (#22)
* Convert `README.md` to `README.rst` since rst is all that PyPI supports
* Tidy up README so all functions are explained with their own headers
* Use context managers for opening files in `setup.py`
* Don't import the code in `setup.py`, which doesn't work on some platforms before it's installed. Instead use parsing of the file to find the version.
Diffstat (limited to 'setup.py')
-rwxr-xr-x | setup.py | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -2,25 +2,37 @@ import os import codecs -import mimeparse +import re from setuptools import setup +def get_version(filename): + """ + Return package version as listed in `__version__` in 'filename'. + """ + with open(filename) as fp: + contents = fp.read() + return re.search("__version__ = ['\"]([^'\"]+)['\"]", contents).group(1) + +version = get_version('mimeparse.py') + + def read(fname): path = os.path.join(os.path.dirname(__file__), fname) - return codecs.open(path, encoding='utf-8').read() + with codecs.open(path, encoding='utf-8') as fp: + return fp.read() setup( name="python-mimeparse", py_modules=["mimeparse"], - version=mimeparse.__version__, + version=version, description=("A module provides basic functions for parsing mime-type " "names and matching them against a list of media-ranges."), author="DB Tsai", author_email="dbtsai@dbtsai.com", url="https://github.com/dbtsai/python-mimeparse", download_url=("https://github.com/dbtsai/python-mimeparse/tarball/" + - mimeparse.__version__), + version), keywords=["mime-type"], classifiers=[ "Programming Language :: Python", @@ -32,5 +44,5 @@ setup( "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules", ], - long_description=read('README.md') + long_description=read('README.rst') ) |