diff --git a/setup.py b/setup.py index f80dfec9..65f82aed 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,34 @@ -'''tldextract setup.py''' +"""`tldextract` accurately separates the gTLD or ccTLD (generic or country code +top-level domain) from the registered domain and subdomains of a URL. + + >>> import tldextract + >>> tldextract.extract('http://forums.news.cnn.com/') + ExtractResult(subdomain='forums.news', domain='cnn', suffix='com') + >>> tldextract.extract('http://forums.bbc.co.uk/') # United Kingdom + ExtractResult(subdomain='forums', domain='bbc', suffix='co.uk') + >>> tldextract.extract('http://www.worldbank.org.kg/') # Kyrgyzstan + ExtractResult(subdomain='www', domain='worldbank', suffix='org.kg') + +`ExtractResult` is a namedtuple, so it's simple to access the parts you want. + + >>> ext = tldextract.extract('http://forums.bbc.co.uk') + >>> (ext.subdomain, ext.domain, ext.suffix) + ('forums', 'bbc', 'co.uk') + >>> # rejoin subdomain and domain + >>> '.'.join(ext[:2]) + 'forums.bbc' + >>> # a common alias + >>> ext.registered_domain + 'bbc.co.uk' +""" import re import sys from setuptools import setup -import tldextract # I don't want to learn reStructuredText right now, so strip Markdown links # that make pip barf. -LONG_DESCRIPTION_MD = tldextract.tldextract.__doc__ +LONG_DESCRIPTION_MD = __doc__ LONG_DESCRIPTION = re.sub(r'(?s)\[(.*?)\]\((http.*?)\)', r'\1', LONG_DESCRIPTION_MD) INSTALL_REQUIRES = ["setuptools"] @@ -16,7 +37,7 @@ setup( name="tldextract", - version=tldextract.__version__, + version="1.7.2", author="John Kurkowski", author_email="john.kurkowski@gmail.com", description=("Accurately separate the TLD from the registered domain and" diff --git a/tldextract/__init__.py b/tldextract/__init__.py index 80113b0f..a74f1389 100644 --- a/tldextract/__init__.py +++ b/tldextract/__init__.py @@ -1,5 +1,10 @@ """Export tldextract's public interface.""" +import pkg_resources + from .tldextract import extract, TLDExtract -__version__ = "1.7.2" +try: + __version__ = pkg_resources.get_distribution('tldextract').version # pylint: disable=no-member +except pkg_resources.DistributionNotFound as _: + __version__ = '(local)' diff --git a/tldextract/tldextract.py b/tldextract/tldextract.py index 90605c22..c3626992 100644 --- a/tldextract/tldextract.py +++ b/tldextract/tldextract.py @@ -435,12 +435,15 @@ def main(): logging.basicConfig() - distribution = pkg_resources.get_distribution('tldextract') + try: + __version__ = pkg_resources.get_distribution('tldextract').version # pylint: disable=no-member + except pkg_resources.DistributionNotFound as _: + __version__ = '(local)' parser = argparse.ArgumentParser( description='Parse hostname from a url or fqdn') - parser.add_argument('--version', action='version', version='%(prog)s ' + distribution.version) # pylint: disable=no-member + parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) # pylint: disable=no-member parser.add_argument('input', metavar='fqdn|url', type=unicode, nargs='*', help='fqdn or url')