Browse Source

Read version from source code; add --version; try protect my email from spambot

Matthew Wang 11 years ago
parent
commit
4f63013531
5 changed files with 35 additions and 16 deletions
  1. 5
    0
      CHANGES
  2. 1
    1
      LICENSE
  3. 1
    0
      README.rst
  4. 16
    10
      setup.py
  5. 12
    5
      src/cdiff.py

+ 5
- 0
CHANGES View File

@@ -2,6 +2,11 @@
2 2
 Change log
3 3
 ==========
4 4
 
5
+Version 0.1 (2013-02-05)
6
+
7
+    - New --version option
8
+    - setup.py now read version from source code
9
+
5 10
 Version 0.0.4 (2013-02-04)
6 11
 
7 12
   - Add CHANGES for history track and better versioning

+ 1
- 1
LICENSE View File

@@ -1,6 +1,6 @@
1 1
 Software License Agreement (BSD-3 License)
2 2
 
3
-Copyright (c) 2013, Matthew Wang <mattwyl@gmail.com>
3
+Copyright (c) 2013, Matthew Wang <mattwyl(@)gmail(.)com>
4 4
 All rights reserved.
5 5
 
6 6
 Redistribution and use in source and binary forms, with or without modification,

+ 1
- 0
README.rst View File

@@ -87,6 +87,7 @@ Pipe in a diff:
87 87
     git log -p -2 | cdiff -s
88 88
     git show 15bfa56 | cdiff -s
89 89
     svn diff -r PREV | cdiff -s
90
+    diff -u foo foo.new | cdiff -s
90 91
 
91 92
 Redirect output to another patch file is safe:
92 93
 

+ 16
- 10
setup.py View File

@@ -10,23 +10,29 @@ if os.path.exists(link_name):
10 10
     os.unlink(link_name)
11 11
 os.symlink('src/cdiff.py', link_name)
12 12
 
13
-with open('CHANGES') as changes:
14
-    for change in changes:
15
-        if change.startswith('Version '):
16
-            version = change.split()[1]
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)
17 21
             break
18
-    changes.seek(0)
19
-    with open('README.rst') as doc:
20
-        long_description = doc.read() + changes.read()
22
+
23
+with open('README.rst') as doc:
24
+    long_description = doc.read()
25
+with open('CHANGES') as changes:
26
+    long_description += changes.read()
21 27
 
22 28
 setup(
23 29
     name = 'cdiff',
24
-    version = version,
30
+    version = __version__,
25 31
     author = 'Matthew Wang',
26
-    author_email = 'mattwyl@gmail.com',
32
+    author_email = 'mattwyl(@)gmail(.)com',
27 33
     license = 'BSD-3',
28 34
     description = ('Term based tool to view colored, incremental diff in '
29
-                   'unified format or side ' 'by side with auto pager'),
35
+                   'unified format or side by side with auto pager'),
30 36
     long_description = long_description,
31 37
     keywords = 'colored incremental side-by-side diff',
32 38
     url = 'https://github.com/ymattw/cdiff',

+ 12
- 5
src/cdiff.py View File

@@ -2,10 +2,12 @@
2 2
 # -*- coding: utf-8 -*-
3 3
 
4 4
 """
5
-View colored, incremental diff in unified format or in side by side mode with
6
-auto pager.  Requires Python (>= 2.5.0) and less.
5
+Term based tool to view colored, incremental diff in unified format or side by
6
+side with auto pager.  Requires Python (>= 2.5.0) and less.
7 7
 
8
-See demo at homepage: https://github.com/ymattw/cdiff
8
+AUTHOR  : Matthew Wang <mattwyl(@)gmail(.)com>
9
+LICENSE : BSD-3
10
+HOMEPAGE: https://github.com/ymattw/cdiff
9 11
 """
10 12
 
11 13
 import sys
@@ -22,6 +24,10 @@ import errno
22 24
 import difflib
23 25
 
24 26
 
27
+# REMEMBER UPDATE ``CHANGES``
28
+__version__ = '0.1'
29
+
30
+
25 31
 COLORS = {
26 32
     'reset'         : '\x1b[0m',
27 33
     'underline'     : '\x1b[4m',
@@ -519,14 +525,15 @@ def main():
519 525
 
520 526
     supported_vcs = [check[0] for check, _ in REVISION_CONTROL]
521 527
 
522
-    usage = '%s [options] [diff]' % os.path.basename(sys.argv[0])
528
+    usage = '%prog [options] [diff]'
523 529
     description= ('View colored, incremental diff in unified format or '
524 530
                   'side by side with auto pager.  Read diff from diff '
525 531
                   '(patch) file if given, or stdin if redirected, or '
526 532
                   'diff produced by revision tool if in a %s workspace') \
527 533
             % '/'.join(supported_vcs)
528 534
 
529
-    parser = optparse.OptionParser(usage=usage, description=description)
535
+    parser = optparse.OptionParser(usage=usage, description=description,
536
+            version='%%prog %s' % __version__)
530 537
     parser.add_option('-s', '--side-by-side', action='store_true',
531 538
             help=('show in side-by-side mode'))
532 539
     parser.add_option('-w', '--width', type='int', default=80, metavar='N',