Skip to content

Instantly share code, notes, and snippets.

@mariocesar
Last active August 29, 2015 14:15
Show Gist options
  • Save mariocesar/c73d09478b8f112e6358 to your computer and use it in GitHub Desktop.
Save mariocesar/c73d09478b8f112e6358 to your computer and use it in GitHub Desktop.
Setup.py util to get common description variables like version, author, etc from packages without importing the modules. (To avoid circular imports and related errors)
__version__ = "0.1"
__author__ = "mariocesar"
def get_module_meta(module_path):
import re
with open(module_path) as cakebet_meta:
meta = cakebet_meta.read()
return dict(re.findall('(?P<key>__.+__)\s=\s["\' ](?P<value>.+)["\' ]', meta))
from utils import setup_utils
meta = setup_utils.get_module_meta('setup_utils.py')
assert '__version__' in meta
assert '__author__' in meta
assert meta['__author__'] == 'mariocesar'
assert meta['__version__'] == '0.1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment