Browse Source

Fix issue #8 version awfullness

Matthew Wang 11 years ago
parent
commit
4bcbeff43d
5 changed files with 35 additions and 37 deletions
  1. 1
    0
      .gitignore
  2. 6
    2
      CHANGES
  3. 4
    4
      README.rst
  4. 14
    10
      cdiff.py
  5. 10
    21
      setup.py

+ 1
- 0
.gitignore View File

@@ -5,3 +5,4 @@
5 5
 /build/
6 6
 /cdiff.egg-info/
7 7
 /dist/
8
+/__pycache__/

+ 6
- 2
CHANGES View File

@@ -2,10 +2,14 @@
2 2
 Change log
3 3
 ==========
4 4
 
5
+Version 0.2 (2013-02-06)
6
+
7
+  - Move cdiff.py to top dir for better meta info management
8
+
5 9
 Version 0.1 (2013-02-05)
6 10
 
7
-    - New --version option
8
-    - setup.py now read version from source code
11
+  - New --version option
12
+  - setup.py now read version from source code
9 13
 
10 14
 Version 0.0.4 (2013-02-04)
11 15
 

+ 4
- 4
README.rst View File

@@ -43,13 +43,13 @@ Download directly
43 43
 
44 44
 Both ``pip`` and ``setup.py`` installs cdiff to system wide directory, if you
45 45
 want a minimal tool without the boring external dependencies (like me), just
46
-save `src/cdiff.py <https://raw.github.com/ymattw/cdiff/master/src/cdiff.py>`_
47
-to whatever directory which is in your ``$PATH``, for example, ``$HOME/bin`` is
48
-in my ``$PATH``, so I save the script there and name as ``cdiff``.
46
+save `cdiff.py <https://raw.github.com/ymattw/cdiff/master/cdiff.py>`_ to
47
+whatever directory which is in your ``$PATH``, for example, ``$HOME/bin`` is in
48
+my ``$PATH``, so I save the script there and name as ``cdiff``.
49 49
 
50 50
 .. code:: sh
51 51
 
52
-    curl -ksS https://raw.github.com/ymattw/cdiff/master/src/cdiff.py > ~/bin/cdiff
52
+    curl -ksS https://raw.github.com/ymattw/cdiff/master/cdiff.py > ~/bin/cdiff
53 53
     chmod +x ~/bin/cdiff
54 54
 
55 55
 Usage

src/cdiff.py → cdiff.py View File

@@ -3,14 +3,21 @@
3 3
 
4 4
 """
5 5
 Term based tool to view **colored**, **incremental** diff in *git/svn/hg*
6
-workspace, or diff from given file or stdin, with **side by side** and **auto
7
-pager** support.  Requires python (>= 2.5.0) and ``less``.
8
-
9
-AUTHOR  : Matthew Wang <mattwyl(@)gmail(.)com>
10
-LICENSE : BSD-3
11
-HOMEPAGE: https://github.com/ymattw/cdiff
6
+workspace, given file or stdin, with **side by side** and **auto pager**
7
+support.  Requires python (>= 2.5.0) and ``less``.
12 8
 """
13 9
 
10
+META_INFO = {
11
+    'version'     : '0.2',
12
+    'license'     : 'BSD-3',
13
+    'author'      : 'Matthew Wang',
14
+    'email'       : 'mattwyl(@)gmail(.)com',
15
+    'url'         : 'https://github.com/ymattw/cdiff',
16
+    'keywords'    : 'colored incremental side-by-side diff',
17
+    'description' : ('View colored, incremental diff in workspace, given file '
18
+                     'or from stdin, with side by side and auto pager support')
19
+}
20
+
14 21
 import sys
15 22
 
16 23
 if sys.hexversion < 0x02050000:
@@ -25,9 +32,6 @@ import errno
25 32
 import difflib
26 33
 
27 34
 
28
-# REMEMBER UPDATE ``CHANGES``
29
-__version__ = '0.1'
30
-
31 35
 
32 36
 COLORS = {
33 37
     'reset'         : '\x1b[0m',
@@ -566,7 +570,7 @@ def main():
566 570
                   'pager support') % '/'.join(supported_vcs)
567 571
 
568 572
     parser = optparse.OptionParser(usage=usage, description=description,
569
-            version='%%prog %s' % __version__)
573
+            version='%%prog %s' % META_INFO['version'])
570 574
     parser.add_option('-s', '--side-by-side', action='store_true',
571 575
             help=('show in side-by-side mode'))
572 576
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',

+ 10
- 21
setup.py View File

@@ -3,22 +3,13 @@
3 3
 from __future__ import with_statement
4 4
 from distutils.core import setup
5 5
 import os
6
+from cdiff import META_INFO as _meta
6 7
 
7 8
 # Create symlink so that to use 'scripts' w/o '.py'
8 9
 link_name = 'cdiff'
9 10
 if os.path.exists(link_name):
10 11
     os.unlink(link_name)
11
-os.symlink('src/cdiff.py', link_name)
12
-
13
-# This awfulness is all in aid of grabbing the version number out
14
-# of the source code, rather than having to repeat it here.  Basically,
15
-# we parse out firt line starts with "__version__" and execute it
16
-#
17
-with open('cdiff') as script:
18
-    for line in script:
19
-        if line.startswith('__version__ = '):
20
-            exec(line)
21
-            break
12
+os.symlink('cdiff.py', link_name)
22 13
 
23 14
 with open('README.rst') as doc:
24 15
     long_description = doc.read()
@@ -27,15 +18,14 @@ with open('CHANGES') as changes:
27 18
 
28 19
 setup(
29 20
     name = 'cdiff',
30
-    version = __version__,
31
-    author = 'Matthew Wang',
32
-    author_email = 'mattwyl(@)gmail(.)com',
33
-    license = 'BSD-3',
34
-    description = ('View colored, incremental diff in workspace, or given '
35
-                   'file from stdin, with side by side and auto pager support'),
21
+    version = _meta['version'],
22
+    author = _meta['author'],
23
+    author_email = _meta['email'],
24
+    license = _meta['license'],
25
+    description = _meta['description'],
36 26
     long_description = long_description,
37
-    keywords = 'colored incremental side-by-side diff',
38
-    url = 'https://github.com/ymattw/cdiff',
27
+    keywords = _meta['keywords'],
28
+    url = _meta['url'],
39 29
     classifiers = [
40 30
         'Development Status :: 4 - Beta',
41 31
         'Topic :: Utilities',
@@ -47,8 +37,7 @@ setup(
47 37
         'Operating System :: Unix',
48 38
         'Programming Language :: Python',
49 39
     ],
50
-    package_dir = {'': 'src'},
51
-    packages = [''],
40
+    packages = [],
52 41
     py_modules = ['cdiff'],
53 42
     scripts = [link_name],
54 43
 )