From 421645dae1c32699d091750a97e73b73bc0780ce Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Mon, 11 Mar 2013 13:08:01 +0100 Subject: [PATCH] New, minimalistic setup.py script and restructuring --- ChangeLog | 5 + MANIFEST.in | 4 +- convert-to-python3.sh | 2 +- setup.py | 107 +++++++-------------- urlwatch.1 => share/man/man1/urlwatch.1 | 0 .../urlwatch/examples}/hooks.py.example | 0 .../urlwatch/examples}/urls.txt.example | 0 urlwatch | 22 +++-- 8 files changed, 56 insertions(+), 84 deletions(-) rewrite setup.py (97%) rename urlwatch.1 => share/man/man1/urlwatch.1 (100%) rename {examples => share/urlwatch/examples}/hooks.py.example (100%) rename {examples => share/urlwatch/examples}/urls.txt.example (100%) diff --git a/ChangeLog b/ChangeLog index eaaa712..13b5071 100644 --- a/ChangeLog +++ b/ChangeLog @@ -124,3 +124,8 @@ * Added basic support for email delivery, using internal SMTP lib. (see options --mailto, --mailfrom and --smtp) +2013-03-11 Thomas Perl + * Minimalistic, automatic setup.py script (based on jabberbot) + * Move files around ({examples,urlwatch.1} -> share/...) + * Update Python 3 migration script and MANIFEST.in with new paths + diff --git a/MANIFEST.in b/MANIFEST.in index b7b4d0e..4024400 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include ChangeLog COPYING urlwatch.1 -recursive-include examples * +include ChangeLog COPYING +recursive-include share * include convert-to-python3.sh diff --git a/convert-to-python3.sh b/convert-to-python3.sh index 1ac8be6..86568ab 100755 --- a/convert-to-python3.sh +++ b/convert-to-python3.sh @@ -1,7 +1,7 @@ #!/bin/sh # Convert urlwatch sources to Python 3.x compatible format -SOURCES="urlwatch lib/urlwatch/*.py examples/hooks.py.example setup.py" +SOURCES="urlwatch lib/urlwatch/*.py share/urlwatch/examples/hooks.py.example setup.py" 2to3 -w $SOURCES diff --git a/setup.py b/setup.py dissimilarity index 97% index b19e953..03aab2c 100644 --- a/setup.py +++ b/setup.py @@ -1,71 +1,36 @@ -#!/usr/bin/python -# Generic setup.py file (for urlwatch) -# -# Copyright (c) 2008-2011 Thomas Perl -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -from distutils.core import setup - -import os -import os.path -import glob -import imp - -# name of our package -package = 'urlwatch' - -# name of the main script -script = 'urlwatch' - -# get program info from urlwatch module -s = imp.load_source('s', script) -# remove compiled file created by imp.load_source -os.unlink(script+'c') - -# s.__author__ has the format "Author Name " -author = s.__author__[:s.__author__.index('<')-1] -author_email = s.__author__[s.__author__.index('<')+1:s.__author__.rindex('>')] - -setup( - name = s.pkgname, - description = s.__doc__, - version = s.__version__, - author = author, - author_email = author_email, - url = s.__homepage__, - scripts = [script], - package_dir = {'': 'lib'}, - packages = [s.pkgname], - data_files = [ - # Example files - (os.path.join('share', package, 'examples'), - glob.glob(os.path.join('examples', '*'))), - # Manual page - (os.path.join('share', 'man', 'man1'), - ['urlwatch.1']), - ], -) - +#!/usr/bin/python +# -*- coding: utf-8 -*- +# Minimalistic, automatic setup.py file for Python modules +# Copyright (c) 2008-2013 Thomas Perl + +PACKAGE_NAME = 'urlwatch' + +# Assumptions: +# 1. Package name equals main script file name (and only one script) +# 2. Main script contains docstring + dunder-{author, license, url, version} +# 3. Data files are in "share/", will be installed in $(PREFIX)/share +# 4. Packages are in "lib/", no modules + +from distutils.core import setup + +import os +import re + +main_py = open(PACKAGE_NAME).read() +m = dict(re.findall("\n__([a-z]+)__ = '([^']+)'", main_py)) +docs = re.findall('"""(.*?)"""', main_py, re.DOTALL) + +m['name'] = PACKAGE_NAME +m['author'], m['author_email'] = re.match(r'(.*) <(.*)>', m['author']).groups() +m['description'], m['long_description'] = docs[0].strip().split('\n\n', 1) +m['download_url'] = m['url'] + PACKAGE_NAME + '-' + m['version'] + '.tar.gz' + +m['scripts'] = [PACKAGE_NAME] +m['package_dir'] = {'': 'lib'} +m['packages'] = ['.'.join(dirname.split(os.sep)[1:]) + for dirname, _, files in os.walk('lib') if '__init__.py' in files] +m['data_files'] = [(dirname, [os.path.join(dirname, file) for file in files]) + for dirname, _, files in os.walk('share')] + +setup(**m) + diff --git a/urlwatch.1 b/share/man/man1/urlwatch.1 similarity index 100% rename from urlwatch.1 rename to share/man/man1/urlwatch.1 diff --git a/examples/hooks.py.example b/share/urlwatch/examples/hooks.py.example similarity index 100% rename from examples/hooks.py.example rename to share/urlwatch/examples/hooks.py.example diff --git a/examples/urls.txt.example b/share/urlwatch/examples/urls.txt.example similarity index 100% rename from examples/urls.txt.example rename to share/urlwatch/examples/urls.txt.example diff --git a/urlwatch b/urlwatch index 3d441d5..6c696e2 100755 --- a/urlwatch +++ b/urlwatch @@ -29,14 +29,19 @@ # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # -"""Watch web pages and arbitrary URLs for changes""" +"""Watch web pages and arbitrary URLs for changes + +This script is intended to help you watch URLs and get notified (via email or +in your terminal) of any changes. The change notification will include the URL +that has changed and a unified diff of what has changed. +""" pkgname = 'urlwatch' +COPYRIGHT = 'Copyright 2008-2013 Thomas Perl' __author__ = 'Thomas Perl ' -__copyright__ = 'Copyright 2008-2011 Thomas Perl' __license__ = 'BSD' -__homepage__ = 'http://thp.io/2008/urlwatch/' +__url__ = 'http://thp.io/2008/urlwatch/' __version__ = '1.15' user_agent = '%s/%s (+http://thp.io/2008/urlwatch/info.html)' % (pkgname, __version__) @@ -59,14 +64,11 @@ hooks_py = os.path.join(scripts_dir, 'hooks.py') # Check if we are installed in the system already (prefix, bindir) = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0]))) -if bindir == 'bin': - # Assume we are installed in system - examples_dir = os.path.join(prefix, 'share', pkgname, 'examples') -else: +if bindir != 'bin': # Assume we are not yet installed - examples_dir = os.path.join(prefix, bindir, 'examples') - sys.path.append(os.path.join(prefix, bindir, 'lib')) + sys.path.insert(0, os.path.join(prefix, bindir, 'lib')) +examples_dir = os.path.join(prefix, 'share', pkgname, 'examples') urls_txt_example = os.path.join(examples_dir, 'urls.txt.example') hooks_py_example = os.path.join(examples_dir, 'hooks.py.example') @@ -369,7 +371,7 @@ if __name__ == '__main__': log.info('printing details with %d items' % len(details)) print '\n'.join(details) print '-- ' - print '%s %s, %s' % (pkgname, __version__, __copyright__) + print '%s %s, %s' % (pkgname, __version__, COPYRIGHT) print 'Website: %s' % (__homepage__,) print 'watched %d URLs in %d seconds\n' % (count, (end-start).seconds) -- 2.11.4.GIT