From 76388392ba7a0d0560af323bb4df1f4b255c18b9 Mon Sep 17 00:00:00 2001 From: Matias Bordese Date: Tue, 26 Dec 2017 15:09:55 -0300 Subject: [PATCH] Minor updates preparing release. --- AUTHORS | 9 +++++-- HISTORY | 6 +++++ MANIFEST.in | 2 +- README.md => README.rst | 24 +++++++++++++----- setup.cfg | 3 +++ setup.py | 51 +++++++++++++++++++++++++++++---------- tests/__init__.py | 2 +- tests/test_hunks.py | 2 +- tests/test_parser.py | 2 +- tests/test_patchedfile.py | 2 +- unidiff/__init__.py | 6 ++--- unidiff/__version__.py | 24 ++++++++++++++++++ unidiff/constants.py | 2 +- unidiff/errors.py | 2 +- unidiff/patch.py | 17 ++++++++----- 15 files changed, 117 insertions(+), 37 deletions(-) rename README.md => README.rst (91%) create mode 100644 unidiff/__version__.py diff --git a/AUTHORS b/AUTHORS index ab660be..c33e9a1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -14,5 +14,10 @@ Contributors * Philipp Kewisch (`@kewisch`_) * Allan Lewis (`@allanlewis`_) * Andrew Lapidas (`@alapidas`_) - * Daniel Thompson (`@daniel-thompson`) - * Sebastian Kreft (`@sk-`) + * Daniel Thompson (`@daniel-thompson`_) + * Sebastian Kreft (`@sk-`_) + * Thomas Grainger (`@graingert`_) + * (`snake-scaly`_) + * Dan Callaghan (`@danc86`_) + * Max Bittker (`@MaxBittker`_) + * Volo Zyko (`@volo-zyko`_) diff --git a/HISTORY b/HISTORY index dd33c66..82d9a1f 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,12 @@ History ------- +0.5.5 - 2018-01-03 +------------------ + +* Updated PatchSet constructor to accept string data. +* Added support to parse extended patch info. + 0.5.4 - 2017-05-26 ------------------ diff --git a/MANIFEST.in b/MANIFEST.in index e9a7f14..5288389 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,4 +2,4 @@ include bin/* include tests/samples/* include HISTORY include LICENSE -include README.md +include README.rst diff --git a/README.md b/README.rst similarity index 91% rename from README.md rename to README.rst index cde448a..c92c813 100644 --- a/README.md +++ b/README.rst @@ -3,18 +3,22 @@ Unidiff Simple Python library to parse and interact with unified diff data. -[![Build Status](https://travis-ci.org/matiasb/python-unidiff.png?branch=master)](https://travis-ci.org/matiasb/python-unidiff) - +.. image:: https://travis-ci.org/matiasb/python-unidiff.svg?branch=master + :target: https://travis-ci.org/matiasb/python-unidiff Installing unidiff ------------------ +:: + $ pip install unidiff Quick start ----------- +:: + >>> import urllib2 >>> from unidiff import PatchSet >>> diff = urllib2.urlopen('https://github.com/matiasb/python-unidiff/pull/3.diff') @@ -41,11 +45,11 @@ Quick start >>> print patch[2] --- a/unidiff/utils.py +++ b/unidiff/utils.py - @@ -37,4 +37,3 @@ + @@ -37,4 +37,3 @@ # - deleted line # \ No newline case (ignore) RE_HUNK_BODY_LINE = re.compile(r'^([- \+\\])') - - + Load unified diff data by instantiating PatchSet with a file-like object as argument, or using PatchSet.from_filename class method to read diff from file. @@ -63,6 +67,8 @@ As a quick example of what can be done, check bin/unidiff file. Also, once installed, unidiff provides a command-line program that displays information from diff data (a file, or stdin). For example: +:: + $ git diff | unidiff Summary ------- @@ -77,6 +83,8 @@ Load a local diff file To instantiate PatchSet from a local file, you can use: +:: + >>> from unidiff import PatchSet >>> patch = PatchSet.from_filename('tests/samples/bzr.diff', encoding='utf-8') >>> patch @@ -84,6 +92,8 @@ To instantiate PatchSet from a local file, you can use: Notice the (optional) encoding parameter. If not specified, unicode input will be expected. Or alternatively: +:: + >>> import codecs >>> from unidiff import PatchSet >>> with codecs.open('tests/samples/bzr.diff', 'r', encoding='utf-8') as diff: @@ -94,6 +104,8 @@ Notice the (optional) encoding parameter. If not specified, unicode input will b Finally, you can also instantiate PatchSet passing any iterable (and encoding, if needed): +:: + >>> from unidiff import PatchSet >>> with open('tests/samples/bzr.diff', 'r') as diff: ... data = diff.readlines() @@ -106,5 +118,5 @@ Finally, you can also instantiate PatchSet passing any iterable (and encoding, i References ---------- - * http://en.wikipedia.org/wiki/Diff_utility - * http://www.artima.com/weblogs/viewpost.jsp?thread=164293 +* http://en.wikipedia.org/wiki/Diff_utility +* http://www.artima.com/weblogs/viewpost.jsp?thread=164293 diff --git a/setup.cfg b/setup.cfg index 3c6e79c..5c6311d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,5 @@ [bdist_wheel] universal=1 + +[metadata] +license_file = LICENSE diff --git a/setup.py b/setup.py index 54ca7b4..be1835b 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,47 @@ # -*- coding: utf-8 -*- # Author: Matías Bordese -from __future__ import unicode_literals +import codecs +import os -from setuptools import setup, find_packages +from setuptools import find_packages, setup + + +# metadata +NAME = 'unidiff' +DESCRIPTION = 'Unified diff parsing/metadata extraction library.' +KEYWORDS = ['unified', 'diff', 'parse', 'metadata'] +URL = 'http://github.com/matiasb/python-unidiff' +EMAIL = 'mbordese@gmail.com' +AUTHOR = 'Matias Bordese' +LICENSE = 'MIT' + +HERE = os.path.abspath(os.path.dirname(__file__)) + +# use README as the long-description +with codecs.open(os.path.join(HERE, 'README.rst'), "rb", "utf-8") as f: + long_description = f.read() + + +# load __version__.py module as a dictionary +about = {} +with open(os.path.join(HERE, 'unidiff/__version__.py')) as f: + exec(f.read(), about) -from unidiff import VERSION setup( - name='unidiff', - version=VERSION, - description="Unified diff parsing/metadata extraction library.", - keywords='unified diff parse metadata', - author='Matias Bordese', - author_email='mbordese@gmail.com', - url='http://github.com/matiasb/python-unidiff', - license='MIT', - packages=find_packages(exclude=['tests']), + name=NAME, + version=about['__version__'], + description=DESCRIPTION, + long_description=long_description, + keywords=KEYWORDS, + author=AUTHOR, + author_email=EMAIL, + url=URL, + packages=find_packages(exclude=('tests',)), scripts=['bin/unidiff'], + include_package_data=True, + license=LICENSE, classifiers=[ 'Intended Audience :: Developers', 'Development Status :: 4 - Beta', @@ -26,6 +50,7 @@ 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', ], - test_suite='tests', ) diff --git a/tests/__init__.py b/tests/__init__.py index 7cc600b..2a2c3ac 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/tests/test_hunks.py b/tests/test_hunks.py index 2edf2c2..c638297 100644 --- a/tests/test_hunks.py +++ b/tests/test_hunks.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/tests/test_parser.py b/tests/test_parser.py index cb49870..6e73b47 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/tests/test_patchedfile.py b/tests/test_patchedfile.py index 57717c4..cd1342a 100644 --- a/tests/test_patchedfile.py +++ b/tests/test_patchedfile.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/unidiff/__init__.py b/unidiff/__init__.py index 9c7d0dc..5f50cc2 100644 --- a/unidiff/__init__.py +++ b/unidiff/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -26,6 +26,7 @@ from __future__ import unicode_literals +from unidiff import __version__ from unidiff.patch import ( DEFAULT_ENCODING, LINE_TYPE_ADDED, @@ -37,5 +38,4 @@ UnidiffParseError, ) - -VERSION = '0.5.4' +VERSION = __version__.__version__ diff --git a/unidiff/__version__.py b/unidiff/__version__.py new file mode 100644 index 0000000..3506a40 --- /dev/null +++ b/unidiff/__version__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +# The MIT License (MIT) +# Copyright (c) 2014-2017 Matias Bordese +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +# OR OTHER DEALINGS IN THE SOFTWARE. + +__version__ = '0.5.5' diff --git a/unidiff/constants.py b/unidiff/constants.py index d5d7a05..3853743 100644 --- a/unidiff/constants.py +++ b/unidiff/constants.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/unidiff/errors.py b/unidiff/errors.py index f7ef7ef..dc71cca 100644 --- a/unidiff/errors.py +++ b/unidiff/errors.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal diff --git a/unidiff/patch.py b/unidiff/patch.py index 45cd6fb..8e20e20 100644 --- a/unidiff/patch.py +++ b/unidiff/patch.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # The MIT License (MIT) -# Copyright (c) 2014 Matias Bordese +# Copyright (c) 2014-2017 Matias Bordese # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -107,8 +107,12 @@ def is_context(self): @implements_to_string class PatchInfo(list): - """Lines with extended patch info. Format of this info is not documented - and it very much depends on patch producer.""" + """Lines with extended patch info. + + Format of this info is not documented and it very much depends on + patch producer. + + """ def __repr__(self): value = "" % self[0].strip() @@ -380,8 +384,9 @@ def _parse(self, diff, encoding): target_file = is_target_filename.group('filename') target_timestamp = is_target_filename.group('timestamp') # add current file to PatchSet - current_file = PatchedFile(patch_info, source_file, target_file, - source_timestamp, target_timestamp) + current_file = PatchedFile( + patch_info, source_file, target_file, + source_timestamp, target_timestamp) self.append(current_file) patch_info = None continue @@ -422,7 +427,6 @@ def from_filename(cls, filename, encoding=DEFAULT_ENCODING, errors=None): @staticmethod def _convert_string(data, encoding=None, errors='strict'): - """Return a PatchSet instance given a diff string.""" if encoding is not None: # if encoding is given, assume bytes and decode data = unicode(data, encoding=encoding, errors=errors) @@ -430,6 +434,7 @@ def _convert_string(data, encoding=None, errors='strict'): @classmethod def from_string(cls, data, encoding=None, errors='strict'): + """Return a PatchSet instance given a diff string.""" return cls(cls._convert_string(data, encoding, errors)) @property