Hello community, here is the log from the commit of package python-first for openSUSE:Factory checked in at 2019-03-10 09:38:50 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-first (Old) and /work/SRC/openSUSE:Factory/.python-first.new.28833 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-first" Sun Mar 10 09:38:50 2019 rev:2 rq:682713 version:2.0.2 Changes: -------- --- /work/SRC/openSUSE:Factory/python-first/python-first.changes 2019-03-07 10:50:40.965849609 +0100 +++ /work/SRC/openSUSE:Factory/.python-first.new.28833/python-first.changes 2019-03-10 09:38:56.608124974 +0100 @@ -1,0 +2,8 @@ +Fri Mar 8 06:01:15 UTC 2019 - John Vandenberg <jay...@gmail.com> + +- Use tests from upstream sdist +- Update to v2.0.2 + * Package tests as part of the dist. + * Update docs. + +------------------------------------------------------------------- Old: ---- first-2.0.1.tar.gz test_first.py New: ---- first-2.0.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-first.spec ++++++ --- /var/tmp/diff_new_pack.myBl7o/_old 2019-03-10 09:38:57.124124850 +0100 +++ /var/tmp/diff_new_pack.myBl7o/_new 2019-03-10 09:38:57.124124850 +0100 @@ -18,14 +18,13 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-first -Version: 2.0.1 +Version: 2.0.2 Release: 0 Summary: Return the first true value of an iterable License: MIT Group: Development/Languages/Python URL: http://github.com/hynek/first/ Source: https://files.pythonhosted.org/packages/source/f/first/first-%{version}.tar.gz -Source1: https://raw.githubusercontent.com/hynek/first/master/test_first.py BuildRequires: %{python_module setuptools} BuildRequires: fdupes BuildRequires: python-rpm-macros @@ -37,7 +36,6 @@ %prep %setup -q -n first-%{version} -cp %{SOURCE1} . %build %python_build @@ -47,7 +45,7 @@ %python_expand %fdupes %{buildroot}%{$python_sitelib} %check -%python_expand PYTHONPATH=. $python test_first.py +%python_expand PYTHONPATH=. $python setup.py test %files %{python_files} %doc AUTHORS.rst README.rst ++++++ first-2.0.1.tar.gz -> first-2.0.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/.travis.yml new/first-2.0.2/.travis.yml --- old/first-2.0.1/.travis.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/first-2.0.2/.travis.yml 2019-03-07 10:27:11.000000000 +0100 @@ -0,0 +1,24 @@ +dist: xenial +group: travis_latest +cache: + directories: + - $HOME/.cache/pip + +language: python + +matrix: + include: + - python: "2.6" + dist: trusty + - python: "2.7" + - python: "3.3" + dist: trusty + - python: "3.4" + - python: "3.5" + - python: "3.6" + - python: "3.7" + +install: + - "pip install ." + +script: make test diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/AUTHORS.rst new/first-2.0.2/AUTHORS.rst --- old/first-2.0.1/AUTHORS.rst 2012-10-12 21:23:45.000000000 +0200 +++ new/first-2.0.2/AUTHORS.rst 2019-03-06 15:12:40.000000000 +0100 @@ -3,6 +3,7 @@ “first” is written and maintained by Hynek Schlawack and various contributors: +- Artem Bezsmertnyi - Łukasz Langa - Nick Coghlan - Vincent Driessen diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/CONTRIBUTING.rst new/first-2.0.2/CONTRIBUTING.rst --- old/first-2.0.1/CONTRIBUTING.rst 1970-01-01 01:00:00.000000000 +0100 +++ new/first-2.0.2/CONTRIBUTING.rst 2019-01-17 10:52:47.000000000 +0100 @@ -0,0 +1,22 @@ +How To Contribute +================= + +Although very small, “first” is always open for suggestions and contributions +by generous developers. I’ve collected a few tipps to get you started. + +Please: + +- Obey `PEP 8`_ and `PEP 257`_. +- *Always* add tests and docs for your code. +- Add yourself to the AUTHORS.rst_ file in an alphabetical fashion. +- Write `good commit messages`_. +- Ideally, squash_ your commits, i.e. make your pull requests just one commit. + +Thank you for considering to contribute to “first”! + + +.. _`squash`: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html +.. _`PEP 8`: http://www.python.org/dev/peps/pep-0008/ +.. _`PEP 257`: http://www.python.org/dev/peps/pep-0257/ +.. _`good commit messages`: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html +.. _`AUTHORS.rst`: https://github.com/hynek/first/blob/master/AUTHORS.rst diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/HISTORY.rst new/first-2.0.2/HISTORY.rst --- old/first-2.0.1/HISTORY.rst 2013-08-04 11:19:16.000000000 +0200 +++ new/first-2.0.2/HISTORY.rst 2019-03-07 10:13:30.000000000 +0100 @@ -3,31 +3,42 @@ History ------- +2.0.2 (2019-03-07) +++++++++++++++++++ + +- Package tests as part of the dist. +- Update docs. +- Drop unsupported Python versions from CI. + N.B. The code hasn't changed and ``first`` continues to work as before. + + 2.0.1 (2013-08-04) ++++++++++++++++++ - - Make installable on systems that don’t support UTF-8 by default. - - *Backward incompatible*: Drop support for Python older than 2.6, the previous fix gets too convoluted otherwise. - Please don’t use Python < 2.6 anyway. - I beg you. - N.B. that this is a *pure packaging/QA matter*: the module still works perfectly with ancient Python versions. + +- Make installable on systems that don’t support UTF-8 by default. +- *Backward incompatible*: Drop support for Python older than 2.6, the previous fix gets too convoluted otherwise. + Please don’t use Python < 2.6 anyway. + I beg you. + N.B. that this is a *pure packaging/QA matter*: the module still works perfectly with ancient Python versions. 2.0.0 (2012-10-13) ++++++++++++++++++ - - `pred` proved to be rather useless. Changed to `key` which is just - a selector. This is a *backward incompatible* change and the reason for - going 2.0. - - Add `default` argument which is returned instead of `None` if no true - element is found. + +- `pred` proved to be rather useless. Changed to `key` which is just a selector. This is a *backward incompatible* change and the reason for going 2.0. +- Add `default` argument which is returned instead of `None` if no true element is found. 1.0.2 (2012-10-09) ++++++++++++++++++ - - Fix packaging. I get this never right the first time. :-/ + +- Fix packaging. I get this never right the first time. :-/ 1.0.1 (2012-10-09) ++++++++++++++++++ - - Documentation fixes only. + +- Documentation fixes only. 1.0.0 (2012-10-09) ++++++++++++++++++ - - Initial release. + +- Initial release. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/MANIFEST.in new/first-2.0.2/MANIFEST.in --- old/first-2.0.1/MANIFEST.in 2013-08-04 11:20:59.000000000 +0200 +++ new/first-2.0.2/MANIFEST.in 2019-03-07 10:47:58.000000000 +0100 @@ -1 +1 @@ -include README.rst AUTHORS.rst LICENSE HISTORY.rst +include *.rst LICENSE test_first.py tox.ini Makefile .travis.yml diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/Makefile new/first-2.0.2/Makefile --- old/first-2.0.1/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ new/first-2.0.2/Makefile 2019-03-06 15:58:31.000000000 +0100 @@ -0,0 +1,7 @@ +test: + python -m pytest --doctest-glob='*.rst' --doctest-modules --ignore=setup.py + +cov: + python -m pytest --cov first --cov-report=term-missing . + +.PHONY: test cov diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/PKG-INFO new/first-2.0.2/PKG-INFO --- old/first-2.0.1/PKG-INFO 2013-08-04 11:28:04.000000000 +0200 +++ new/first-2.0.2/PKG-INFO 2019-03-07 11:00:07.000000000 +0100 @@ -1,6 +1,6 @@ -Metadata-Version: 1.1 +Metadata-Version: 2.1 Name: first -Version: 2.0.1 +Version: 2.0.2 Summary: Return the first true value of an iterable. Home-page: http://github.com/hynek/first/ Author: Hynek Schlawack @@ -9,19 +9,16 @@ Description: first: The function you always missed in Python =============================================== - .. image:: https://secure.travis-ci.org/hynek/first.png - :target: https://secure.travis-ci.org/hynek/first - - *first* is an MIT licensed Python package with a simple function that returns - the first true value from an iterable, or ``None`` if there is none. If you - need more power, you can also supply a ``key`` function that is used to judge - the truth value of the element or a ``default`` value if ``None`` doesn’t fit - your use case. - - I’m using the term “true” consistently with Python docs for ``any()`` and - ``all()`` — it means that the value evaluates to true like: ``True``, ``1``, - ``"foo"`` or ``[None]``. But **not**: ``None``, ``False`` or ``0``. In - JavaScript, they call this “truthy”. + .. image:: https://travis-ci.org/hynek/first.svg?branch=master + :target: https://travis-ci.org/hynek/first + :alt: CI Status + + ``first`` is an MIT-licensed Python package with a simple function that returns the first true value from an iterable, or ``None`` if there is none. + If you need more power, you can also supply a ``key`` function that is used to judge the truth value of the element or a ``default`` value if ``None`` doesn’t fit your use case. + + N.B. I’m using the term “true” consistently with Python docs for ``any()`` and ``all()`` — it means that the value evaluates to true like: ``True``, ``1``, ``"foo"``, or ``[None]``. + But **not**: ``None``, ``False``, ``[]``, or ``0``. + In JavaScript, they call this “truthy”. Examples @@ -35,8 +32,7 @@ >>> first([0, None, False, [], (), 42]) 42 - However, it’s especially useful for dealing with regular expressions in - ``if/elif/else`` branches: + However, it’s especially useful for dealing with regular expressions in ``if/elif/else`` branches: .. code-block:: python @@ -56,8 +52,8 @@ elif m.re is re2: print('re2', m.group(1)) - The optional ``key`` function gives you even *more* selection power. If you - want to return the first even number from a list, just do the following: + The optional ``key`` function gives you even *more* selection power. + If you want to return the first even number from a list, just do the following: .. code-block:: pycon @@ -65,8 +61,7 @@ >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0) 4 - ``default`` on the other hand allows you to specify a value that is returned - if none of the elements is true: + ``default`` on the other hand allows you to specify a value that is returned if none of the elements is true: .. code-block:: pycon @@ -86,26 +81,21 @@ first(iterable, default=None, key=None) - This function returns the first element of ``iterable`` that is true if - ``key`` is ``None``. If there is no true element, the value of ``default`` is - returned, which is ``None`` by default. - - If a callable is supplied in ``key``, the result of ``key(element)`` is - used to judge the truth value of the element, but the element itself is - returned. + This function returns the first element of ``iterable`` that is true if ``key`` is ``None``. + If there is no true element, the value of ``default`` is returned, which is ``None`` by default. + + If a callable is supplied in ``key``, the result of ``key(element)`` is used to judge the truth value of the element, but the element itself is returned. - *first* has no dependencies and should work with any Python available. Of - course, it works with the awesome `Python 3`_ everybody should be using. + ``first`` has no dependencies and should work with any Python available. Alternatives ============ - *first* brings nothing to the table that wasn’t possible before. However the - existing solutions aren’t very idiomatic for such a common and simple problem. + ``first`` brings nothing to the table that wasn’t possible before. + However the existing solutions aren’t very idiomatic for such a common and simple problem. - The following constructs are equivalent to ``first(seq)`` and work since Python - 2.6: + The following constructs are equivalent to ``first(seq)`` and work since Python 2.6: .. code-block:: python @@ -113,16 +103,20 @@ next(itertools.ifilter(bool, seq), None) next((x for x in seq if x), None) - None of them is as pretty as I’d like them to be. The ``re`` example from - above would look like the following: + None of them is as pretty as I’d like them to be. + The ``re`` example from above would look like the following: .. code-block:: python next(itertools.ifilter(None, (regexp.match('abc') for regexp in [re1, re2])), None) next((regexp.match('abc') for regexp in [re1, re2] if regexp.match('abc')), None) + next((match for match in itertools.imap( + operator.methodcaller('match', 'abc'), [re1, re2]) if match), None) - Note that in the second case you have to call ``regexp.match()`` *twice*. For - comparison, one more time the *first*-version: + Note that in the second case you have to call ``regexp.match()`` *twice*. + The third example "fixes" that problem but also summons Cthulhu. + + For comparison, one more time the ``first``-version: .. code-block:: python @@ -130,21 +124,20 @@ Idiomatic, clear and readable. Pythonic. :) + ---- + + As of version 0.6.5 from 2015, the excellent `boltons package <https://boltons.readthedocs.io/>`_ contains a ``first``-like function as part of its `iterutils module <https://boltons.readthedocs.io/en/latest/iterutils.html#boltons.iterutils.first>`_. + Background ========== - The idea for *first* goes back to a discussion I had with `Łukasz Langa`_ about - how the ``re`` example above is painful in Python. We figured such a function - is missing Python, however it’s rather unlikely we’d get it in and even if, it - wouldn’t get in before 3.4 anyway, which is years away as of yours truly is - writing this. + The idea for ``first`` goes back to a discussion I had with `Łukasz Langa`_ about how the ``re`` example above is painful in Python. + We figured such a function is missing Python, however it’s rather unlikely we’d get it in and even if, it wouldn’t get in before 3.4 anyway, which is years away as of yours truly is writing this. - So I decided to release it as a package for now. If it proves popular enough, - it may even make it into Python’s stdlib in the end. + So I decided to release it as a package for now. If it proves popular enough, it may even make it into Python’s stdlib in the end. - .. _`Python 3`: http://getpython3.com/ .. _`Łukasz Langa`: https://github.com/ambv @@ -153,34 +146,45 @@ History ------- + 2.0.2 (2019-03-07) + ++++++++++++++++++ + + - Package tests as part of the dist. + - Update docs. + - Drop unsupported Python versions from CI. + N.B. The code hasn't changed and ``first`` continues to work as before. + + 2.0.1 (2013-08-04) ++++++++++++++++++ - - Make installable on systems that don’t support UTF-8 by default. - - *Backward incompatible*: Drop support for Python older than 2.6, the previous fix gets too convoluted otherwise. - Please don’t use Python < 2.6 anyway. - I beg you. - N.B. that this is a *pure packaging/QA matter*: the module still works perfectly with ancient Python versions. + + - Make installable on systems that don’t support UTF-8 by default. + - *Backward incompatible*: Drop support for Python older than 2.6, the previous fix gets too convoluted otherwise. + Please don’t use Python < 2.6 anyway. + I beg you. + N.B. that this is a *pure packaging/QA matter*: the module still works perfectly with ancient Python versions. 2.0.0 (2012-10-13) ++++++++++++++++++ - - `pred` proved to be rather useless. Changed to `key` which is just - a selector. This is a *backward incompatible* change and the reason for - going 2.0. - - Add `default` argument which is returned instead of `None` if no true - element is found. + + - `pred` proved to be rather useless. Changed to `key` which is just a selector. This is a *backward incompatible* change and the reason for going 2.0. + - Add `default` argument which is returned instead of `None` if no true element is found. 1.0.2 (2012-10-09) ++++++++++++++++++ - - Fix packaging. I get this never right the first time. :-/ + + - Fix packaging. I get this never right the first time. :-/ 1.0.1 (2012-10-09) ++++++++++++++++++ - - Documentation fixes only. + + - Documentation fixes only. 1.0.0 (2012-10-09) ++++++++++++++++++ - - Initial release. + + - Initial release. Credits @@ -188,6 +192,7 @@ “first” is written and maintained by Hynek Schlawack and various contributors: + - Artem Bezsmertnyi - Łukasz Langa - Nick Coghlan - Vincent Driessen @@ -203,8 +208,12 @@ Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.0 -Classifier: Programming Language :: Python :: 3.1 -Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries :: Python Modules +Description-Content-Type: text/x-rst diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/README.rst new/first-2.0.2/README.rst --- old/first-2.0.1/README.rst 2013-08-04 10:30:28.000000000 +0200 +++ new/first-2.0.2/README.rst 2019-03-06 15:44:02.000000000 +0100 @@ -1,19 +1,16 @@ first: The function you always missed in Python =============================================== -.. image:: https://secure.travis-ci.org/hynek/first.png - :target: https://secure.travis-ci.org/hynek/first - -*first* is an MIT licensed Python package with a simple function that returns -the first true value from an iterable, or ``None`` if there is none. If you -need more power, you can also supply a ``key`` function that is used to judge -the truth value of the element or a ``default`` value if ``None`` doesn’t fit -your use case. - - I’m using the term “true” consistently with Python docs for ``any()`` and - ``all()`` — it means that the value evaluates to true like: ``True``, ``1``, - ``"foo"`` or ``[None]``. But **not**: ``None``, ``False`` or ``0``. In - JavaScript, they call this “truthy”. +.. image:: https://travis-ci.org/hynek/first.svg?branch=master + :target: https://travis-ci.org/hynek/first + :alt: CI Status + +``first`` is an MIT-licensed Python package with a simple function that returns the first true value from an iterable, or ``None`` if there is none. +If you need more power, you can also supply a ``key`` function that is used to judge the truth value of the element or a ``default`` value if ``None`` doesn’t fit your use case. + +N.B. I’m using the term “true” consistently with Python docs for ``any()`` and ``all()`` — it means that the value evaluates to true like: ``True``, ``1``, ``"foo"``, or ``[None]``. +But **not**: ``None``, ``False``, ``[]``, or ``0``. +In JavaScript, they call this “truthy”. Examples @@ -27,8 +24,7 @@ >>> first([0, None, False, [], (), 42]) 42 -However, it’s especially useful for dealing with regular expressions in -``if/elif/else`` branches: +However, it’s especially useful for dealing with regular expressions in ``if/elif/else`` branches: .. code-block:: python @@ -48,8 +44,8 @@ elif m.re is re2: print('re2', m.group(1)) -The optional ``key`` function gives you even *more* selection power. If you -want to return the first even number from a list, just do the following: +The optional ``key`` function gives you even *more* selection power. +If you want to return the first even number from a list, just do the following: .. code-block:: pycon @@ -57,8 +53,7 @@ >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0) 4 -``default`` on the other hand allows you to specify a value that is returned -if none of the elements is true: +``default`` on the other hand allows you to specify a value that is returned if none of the elements is true: .. code-block:: pycon @@ -78,26 +73,21 @@ first(iterable, default=None, key=None) -This function returns the first element of ``iterable`` that is true if -``key`` is ``None``. If there is no true element, the value of ``default`` is -returned, which is ``None`` by default. - -If a callable is supplied in ``key``, the result of ``key(element)`` is -used to judge the truth value of the element, but the element itself is -returned. +This function returns the first element of ``iterable`` that is true if ``key`` is ``None``. +If there is no true element, the value of ``default`` is returned, which is ``None`` by default. + +If a callable is supplied in ``key``, the result of ``key(element)`` is used to judge the truth value of the element, but the element itself is returned. -*first* has no dependencies and should work with any Python available. Of -course, it works with the awesome `Python 3`_ everybody should be using. +``first`` has no dependencies and should work with any Python available. Alternatives ============ -*first* brings nothing to the table that wasn’t possible before. However the -existing solutions aren’t very idiomatic for such a common and simple problem. +``first`` brings nothing to the table that wasn’t possible before. +However the existing solutions aren’t very idiomatic for such a common and simple problem. -The following constructs are equivalent to ``first(seq)`` and work since Python -2.6: +The following constructs are equivalent to ``first(seq)`` and work since Python 2.6: .. code-block:: python @@ -105,16 +95,20 @@ next(itertools.ifilter(bool, seq), None) next((x for x in seq if x), None) -None of them is as pretty as I’d like them to be. The ``re`` example from -above would look like the following: +None of them is as pretty as I’d like them to be. +The ``re`` example from above would look like the following: .. code-block:: python next(itertools.ifilter(None, (regexp.match('abc') for regexp in [re1, re2])), None) next((regexp.match('abc') for regexp in [re1, re2] if regexp.match('abc')), None) + next((match for match in itertools.imap( + operator.methodcaller('match', 'abc'), [re1, re2]) if match), None) + +Note that in the second case you have to call ``regexp.match()`` *twice*. +The third example "fixes" that problem but also summons Cthulhu. -Note that in the second case you have to call ``regexp.match()`` *twice*. For -comparison, one more time the *first*-version: +For comparison, one more time the ``first``-version: .. code-block:: python @@ -122,19 +116,18 @@ Idiomatic, clear and readable. Pythonic. :) +---- + +As of version 0.6.5 from 2015, the excellent `boltons package <https://boltons.readthedocs.io/>`_ contains a ``first``-like function as part of its `iterutils module <https://boltons.readthedocs.io/en/latest/iterutils.html#boltons.iterutils.first>`_. + Background ========== -The idea for *first* goes back to a discussion I had with `Łukasz Langa`_ about -how the ``re`` example above is painful in Python. We figured such a function -is missing Python, however it’s rather unlikely we’d get it in and even if, it -wouldn’t get in before 3.4 anyway, which is years away as of yours truly is -writing this. +The idea for ``first`` goes back to a discussion I had with `Łukasz Langa`_ about how the ``re`` example above is painful in Python. +We figured such a function is missing Python, however it’s rather unlikely we’d get it in and even if, it wouldn’t get in before 3.4 anyway, which is years away as of yours truly is writing this. -So I decided to release it as a package for now. If it proves popular enough, -it may even make it into Python’s stdlib in the end. +So I decided to release it as a package for now. If it proves popular enough, it may even make it into Python’s stdlib in the end. -.. _`Python 3`: http://getpython3.com/ .. _`Łukasz Langa`: https://github.com/ambv diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/first.egg-info/PKG-INFO new/first-2.0.2/first.egg-info/PKG-INFO --- old/first-2.0.1/first.egg-info/PKG-INFO 2013-08-04 11:28:04.000000000 +0200 +++ new/first-2.0.2/first.egg-info/PKG-INFO 2019-03-07 11:00:07.000000000 +0100 @@ -1,6 +1,6 @@ -Metadata-Version: 1.1 +Metadata-Version: 2.1 Name: first -Version: 2.0.1 +Version: 2.0.2 Summary: Return the first true value of an iterable. Home-page: http://github.com/hynek/first/ Author: Hynek Schlawack @@ -9,19 +9,16 @@ Description: first: The function you always missed in Python =============================================== - .. image:: https://secure.travis-ci.org/hynek/first.png - :target: https://secure.travis-ci.org/hynek/first - - *first* is an MIT licensed Python package with a simple function that returns - the first true value from an iterable, or ``None`` if there is none. If you - need more power, you can also supply a ``key`` function that is used to judge - the truth value of the element or a ``default`` value if ``None`` doesn’t fit - your use case. - - I’m using the term “true” consistently with Python docs for ``any()`` and - ``all()`` — it means that the value evaluates to true like: ``True``, ``1``, - ``"foo"`` or ``[None]``. But **not**: ``None``, ``False`` or ``0``. In - JavaScript, they call this “truthy”. + .. image:: https://travis-ci.org/hynek/first.svg?branch=master + :target: https://travis-ci.org/hynek/first + :alt: CI Status + + ``first`` is an MIT-licensed Python package with a simple function that returns the first true value from an iterable, or ``None`` if there is none. + If you need more power, you can also supply a ``key`` function that is used to judge the truth value of the element or a ``default`` value if ``None`` doesn’t fit your use case. + + N.B. I’m using the term “true” consistently with Python docs for ``any()`` and ``all()`` — it means that the value evaluates to true like: ``True``, ``1``, ``"foo"``, or ``[None]``. + But **not**: ``None``, ``False``, ``[]``, or ``0``. + In JavaScript, they call this “truthy”. Examples @@ -35,8 +32,7 @@ >>> first([0, None, False, [], (), 42]) 42 - However, it’s especially useful for dealing with regular expressions in - ``if/elif/else`` branches: + However, it’s especially useful for dealing with regular expressions in ``if/elif/else`` branches: .. code-block:: python @@ -56,8 +52,8 @@ elif m.re is re2: print('re2', m.group(1)) - The optional ``key`` function gives you even *more* selection power. If you - want to return the first even number from a list, just do the following: + The optional ``key`` function gives you even *more* selection power. + If you want to return the first even number from a list, just do the following: .. code-block:: pycon @@ -65,8 +61,7 @@ >>> first([1, 1, 3, 4, 5], key=lambda x: x % 2 == 0) 4 - ``default`` on the other hand allows you to specify a value that is returned - if none of the elements is true: + ``default`` on the other hand allows you to specify a value that is returned if none of the elements is true: .. code-block:: pycon @@ -86,26 +81,21 @@ first(iterable, default=None, key=None) - This function returns the first element of ``iterable`` that is true if - ``key`` is ``None``. If there is no true element, the value of ``default`` is - returned, which is ``None`` by default. - - If a callable is supplied in ``key``, the result of ``key(element)`` is - used to judge the truth value of the element, but the element itself is - returned. + This function returns the first element of ``iterable`` that is true if ``key`` is ``None``. + If there is no true element, the value of ``default`` is returned, which is ``None`` by default. + + If a callable is supplied in ``key``, the result of ``key(element)`` is used to judge the truth value of the element, but the element itself is returned. - *first* has no dependencies and should work with any Python available. Of - course, it works with the awesome `Python 3`_ everybody should be using. + ``first`` has no dependencies and should work with any Python available. Alternatives ============ - *first* brings nothing to the table that wasn’t possible before. However the - existing solutions aren’t very idiomatic for such a common and simple problem. + ``first`` brings nothing to the table that wasn’t possible before. + However the existing solutions aren’t very idiomatic for such a common and simple problem. - The following constructs are equivalent to ``first(seq)`` and work since Python - 2.6: + The following constructs are equivalent to ``first(seq)`` and work since Python 2.6: .. code-block:: python @@ -113,16 +103,20 @@ next(itertools.ifilter(bool, seq), None) next((x for x in seq if x), None) - None of them is as pretty as I’d like them to be. The ``re`` example from - above would look like the following: + None of them is as pretty as I’d like them to be. + The ``re`` example from above would look like the following: .. code-block:: python next(itertools.ifilter(None, (regexp.match('abc') for regexp in [re1, re2])), None) next((regexp.match('abc') for regexp in [re1, re2] if regexp.match('abc')), None) + next((match for match in itertools.imap( + operator.methodcaller('match', 'abc'), [re1, re2]) if match), None) - Note that in the second case you have to call ``regexp.match()`` *twice*. For - comparison, one more time the *first*-version: + Note that in the second case you have to call ``regexp.match()`` *twice*. + The third example "fixes" that problem but also summons Cthulhu. + + For comparison, one more time the ``first``-version: .. code-block:: python @@ -130,21 +124,20 @@ Idiomatic, clear and readable. Pythonic. :) + ---- + + As of version 0.6.5 from 2015, the excellent `boltons package <https://boltons.readthedocs.io/>`_ contains a ``first``-like function as part of its `iterutils module <https://boltons.readthedocs.io/en/latest/iterutils.html#boltons.iterutils.first>`_. + Background ========== - The idea for *first* goes back to a discussion I had with `Łukasz Langa`_ about - how the ``re`` example above is painful in Python. We figured such a function - is missing Python, however it’s rather unlikely we’d get it in and even if, it - wouldn’t get in before 3.4 anyway, which is years away as of yours truly is - writing this. + The idea for ``first`` goes back to a discussion I had with `Łukasz Langa`_ about how the ``re`` example above is painful in Python. + We figured such a function is missing Python, however it’s rather unlikely we’d get it in and even if, it wouldn’t get in before 3.4 anyway, which is years away as of yours truly is writing this. - So I decided to release it as a package for now. If it proves popular enough, - it may even make it into Python’s stdlib in the end. + So I decided to release it as a package for now. If it proves popular enough, it may even make it into Python’s stdlib in the end. - .. _`Python 3`: http://getpython3.com/ .. _`Łukasz Langa`: https://github.com/ambv @@ -153,34 +146,45 @@ History ------- + 2.0.2 (2019-03-07) + ++++++++++++++++++ + + - Package tests as part of the dist. + - Update docs. + - Drop unsupported Python versions from CI. + N.B. The code hasn't changed and ``first`` continues to work as before. + + 2.0.1 (2013-08-04) ++++++++++++++++++ - - Make installable on systems that don’t support UTF-8 by default. - - *Backward incompatible*: Drop support for Python older than 2.6, the previous fix gets too convoluted otherwise. - Please don’t use Python < 2.6 anyway. - I beg you. - N.B. that this is a *pure packaging/QA matter*: the module still works perfectly with ancient Python versions. + + - Make installable on systems that don’t support UTF-8 by default. + - *Backward incompatible*: Drop support for Python older than 2.6, the previous fix gets too convoluted otherwise. + Please don’t use Python < 2.6 anyway. + I beg you. + N.B. that this is a *pure packaging/QA matter*: the module still works perfectly with ancient Python versions. 2.0.0 (2012-10-13) ++++++++++++++++++ - - `pred` proved to be rather useless. Changed to `key` which is just - a selector. This is a *backward incompatible* change and the reason for - going 2.0. - - Add `default` argument which is returned instead of `None` if no true - element is found. + + - `pred` proved to be rather useless. Changed to `key` which is just a selector. This is a *backward incompatible* change and the reason for going 2.0. + - Add `default` argument which is returned instead of `None` if no true element is found. 1.0.2 (2012-10-09) ++++++++++++++++++ - - Fix packaging. I get this never right the first time. :-/ + + - Fix packaging. I get this never right the first time. :-/ 1.0.1 (2012-10-09) ++++++++++++++++++ - - Documentation fixes only. + + - Documentation fixes only. 1.0.0 (2012-10-09) ++++++++++++++++++ - - Initial release. + + - Initial release. Credits @@ -188,6 +192,7 @@ “first” is written and maintained by Hynek Schlawack and various contributors: + - Artem Bezsmertnyi - Łukasz Langa - Nick Coghlan - Vincent Driessen @@ -203,8 +208,12 @@ Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 -Classifier: Programming Language :: Python :: 3.0 -Classifier: Programming Language :: Python :: 3.1 -Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 +Classifier: Programming Language :: Python :: 3.4 +Classifier: Programming Language :: Python :: 3.5 +Classifier: Programming Language :: Python :: 3.6 +Classifier: Programming Language :: Python :: 3.7 +Classifier: Programming Language :: Python :: Implementation :: CPython +Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries :: Python Modules +Description-Content-Type: text/x-rst diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/first.egg-info/SOURCES.txt new/first-2.0.2/first.egg-info/SOURCES.txt --- old/first-2.0.1/first.egg-info/SOURCES.txt 2013-08-04 11:28:04.000000000 +0200 +++ new/first-2.0.2/first.egg-info/SOURCES.txt 2019-03-07 11:00:07.000000000 +0100 @@ -1,11 +1,16 @@ +.travis.yml AUTHORS.rst +CONTRIBUTING.rst HISTORY.rst LICENSE MANIFEST.in +Makefile README.rst first.py setup.cfg setup.py +test_first.py +tox.ini first.egg-info/PKG-INFO first.egg-info/SOURCES.txt first.egg-info/dependency_links.txt diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/first.py new/first-2.0.2/first.py --- old/first-2.0.1/first.py 2013-08-04 11:20:06.000000000 +0200 +++ new/first-2.0.2/first.py 2019-03-07 10:13:21.000000000 +0100 @@ -33,10 +33,10 @@ """ __title__ = 'first' -__version__ = '2.0.1' +__version__ = '2.0.2' __author__ = 'Hynek Schlawack' __license__ = 'MIT' -__copyright__ = 'Copyright 2012–2013 Hynek Schlawack' +__copyright__ = 'Copyright 2012 Hynek Schlawack' def first(iterable, default=None, key=None): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/setup.cfg new/first-2.0.2/setup.cfg --- old/first-2.0.1/setup.cfg 2013-08-04 11:28:04.000000000 +0200 +++ new/first-2.0.2/setup.cfg 2019-03-07 11:00:07.000000000 +0100 @@ -1,8 +1,10 @@ -[wheel] +[bdist_wheel] universal = 1 +[metadata] +license_file = LICENSE + [egg_info] tag_build = tag_date = 0 -tag_svn_revision = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/setup.py new/first-2.0.2/setup.py --- old/first-2.0.1/setup.py 2013-08-04 11:26:19.000000000 +0200 +++ new/first-2.0.2/setup.py 2019-03-07 10:14:01.000000000 +0100 @@ -10,14 +10,19 @@ import codecs openf = codecs.open +def read(fn): + with openf(fn, encoding='utf-8') as fp: + return fp.read() + setup( name='first', version=first.__version__, description='Return the first true value of an iterable.', - long_description=(openf('README.rst', encoding='utf-8').read() + '\n\n' + - openf('HISTORY.rst', encoding='utf-8').read() + '\n\n' + - openf('AUTHORS.rst', encoding='utf-8').read()), + long_description=(read('README.rst') + '\n\n' + + read('HISTORY.rst') + '\n\n' + + read('AUTHORS.rst')), + long_description_content_type="text/x-rst", url='http://github.com/hynek/first/', license=first.__license__, author=first.__author__, @@ -34,10 +39,13 @@ 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.0', - 'Programming Language :: Python :: 3.1', - 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries :: Python Modules', ], ) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/test_first.py new/first-2.0.2/test_first.py --- old/first-2.0.1/test_first.py 1970-01-01 01:00:00.000000000 +0100 +++ new/first-2.0.2/test_first.py 2019-01-17 10:52:47.000000000 +0100 @@ -0,0 +1,40 @@ +import unittest +from first import first + + +isbool = lambda x: isinstance(x, bool) +isint = lambda x: isinstance(x, int) +odd = lambda x: isint(x) and x % 2 != 0 +even = lambda x: isint(x) and x % 2 == 0 +is_meaning_of_life = lambda x: x == 42 + + +class TestFirst(unittest.TestCase): + def test_empty_iterables(self): + s = set() + l = [] + assert first(s) is None + assert first(l) is None + + def test_default_value(self): + s = set() + l = [] + assert first(s, default=42) == 42 + assert first(l, default=3.14) == 3.14 + + l = [0, False, []] + assert first(l, default=3.14) == 3.14 + + def test_selection(self): + l = [(), 0, False, 3, []] + + assert first(l, default=42) == 3 + assert first(l, key=isint) == 0 + assert first(l, key=isbool) is False + assert first(l, key=odd) == 3 + assert first(l, key=even) == 0 + assert first(l, key=is_meaning_of_life) is None + + +if __name__ == '__main__': + unittest.main() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/first-2.0.1/tox.ini new/first-2.0.2/tox.ini --- old/first-2.0.1/tox.ini 1970-01-01 01:00:00.000000000 +0100 +++ new/first-2.0.2/tox.ini 2019-03-07 10:35:25.000000000 +0100 @@ -0,0 +1,25 @@ +[tox] +envlist = py{27,34,35,36,37,py,pi-description},manifest + + +[testenv] +deps=pytest +commands=python -m pytest --doctest-glob='*.rst' --doctest-modules --ignore=setup.py + + +[testenv:pypi-description] +basepython = python3.7 +skip_install = true +deps = + twine + pip >= 18.0.0 +commands = + pip wheel -w {envtmpdir}/build --no-deps . + twine check {envtmpdir}/build/* + + +[testenv:manifest] +basepython = python3.7 +deps = check-manifest +skip_install = true +commands = check-manifest