Skip to content

Commit

Permalink
Merge pull request #49 from matiasb/preparing-0.5.5
Browse files Browse the repository at this point in the history
Minor updates preparing release.
  • Loading branch information
matiasb authored Jan 3, 2018
2 parents 2e3b11a + 7638839 commit 4ed24ae
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 37 deletions.
9 changes: 7 additions & 2 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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`_)
6 changes: 6 additions & 0 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -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
------------------

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include bin/*
include tests/samples/*
include HISTORY
include LICENSE
include README.md
include README.rst
24 changes: 18 additions & 6 deletions README.md → README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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.
Expand All @@ -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
-------
Expand All @@ -77,13 +83,17 @@ 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
<PatchSet: [<PatchedFile: added_file>, <PatchedFile: modified_file>, <PatchedFile: removed_file>]>

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:
Expand All @@ -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()
Expand All @@ -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
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[bdist_wheel]
universal=1

[metadata]
license_file = LICENSE
51 changes: 38 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'
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='[email protected]',
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',
Expand All @@ -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',
)
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hunks.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_patchedfile.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions unidiff/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,6 +26,7 @@

from __future__ import unicode_literals

from unidiff import __version__
from unidiff.patch import (
DEFAULT_ENCODING,
LINE_TYPE_ADDED,
Expand All @@ -37,5 +38,4 @@
UnidiffParseError,
)


VERSION = '0.5.4'
VERSION = __version__.__version__
24 changes: 24 additions & 0 deletions unidiff/__version__.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion unidiff/constants.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion unidiff/errors.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 11 additions & 6 deletions unidiff/patch.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = "<PatchInfo: %s>" % self[0].strip()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -422,14 +427,14 @@ 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)
return StringIO(data)

@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
Expand Down

0 comments on commit 4ed24ae

Please sign in to comment.