parts


Nameparts JSON
Version 2.1.0 PyPI version JSON
download
home_pageNone
SummaryMinimal library that enables partitioning of iterable collections in a concise manner.
upload_time2024-12-24 04:06:15
maintainerNone
docs_urlNone
authorAndrei Lapets
requires_python>=3.7
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =====
parts
=====

Minimal library that enables partitioning of iterable collections in a concise manner.

|pypi| |readthedocs| |actions| |coveralls|

.. |pypi| image:: https://badge.fury.io/py/parts.svg#
   :target: https://badge.fury.io/py/parts
   :alt: PyPI version and link.

.. |readthedocs| image:: https://readthedocs.org/projects/parts/badge/?version=latest
   :target: https://parts.readthedocs.io/en/latest/?badge=latest
   :alt: Read the Docs documentation status.

.. |actions| image:: https://github.com/lapets/parts/workflows/lint-test-cover-docs/badge.svg#
   :target: https://github.com/lapets/parts/actions/workflows/lint-test-cover-docs.yml
   :alt: GitHub Actions status.

.. |coveralls| image:: https://coveralls.io/repos/github/lapets/parts/badge.svg?branch=main
   :target: https://coveralls.io/github/lapets/parts?branch=main
   :alt: Coveralls test coverage summary.

Purpose
-------
This library provides a function for partitioning `iterable <https://docs.python.org/3/glossary.html#term-iterable>`__ data structure instances. When the number of parts is specified explicitly, it is treated as a strict requirement and an exception is raised when it cannot be satisfied. When a length for all parts (or each part) is specified explicitly, a best-effort approach is used: as many parts of the specified length are retrieved as possible, with the possibility that some parts at the end of the partition sequence have a shorter (but still non-zero) length.

Installation and Usage
----------------------
This library is available as a `package on PyPI <https://pypi.org/project/parts>`__:

.. code-block:: bash

    python -m pip install parts

The library can be imported in the usual manner:

.. code-block:: python

    import parts
    from parts import parts

Examples
^^^^^^^^
Several examples are presented below:

.. code-block:: python

    >>> list(parts([1, 2, 3, 4, 5, 6, 7], length=2))
    [[1, 2], [3, 4], [5, 6], [7]]

    >>> list(parts([1, 2, 3, 4, 5, 6, 7], length=4))
    [[1, 2, 3, 4], [5, 6, 7]]

    >>> list(parts([1, 2, 3, 4, 5, 6, 7], number=1))
    [[1, 2, 3, 4, 5, 6, 7]]

    >>> list(parts([1, 2, 3, 4, 5, 6, 7], 5))
    [[1], [2], [3], [4, 5], [6, 7]]

    >>> list(parts([1, 2, 3, 4, 5, 6], 2, 3))
    [[1, 2, 3], [4, 5, 6]]

    >>> list(parts([1, 2, 3, 4, 5, 6], number=3, length=2))
    [[1, 2], [3, 4], [5, 6]]

    >>> list(parts([1, 2, 3, 4, 5, 6, 7], 7, [1, 1, 1, 1, 1, 1, 1]))
    [[1], [2], [3], [4], [5], [6], [7]]

    >>> list(parts([1, 2, 3, 4, 5, 6], length=[2, 2, 2]))
    [[1, 2], [3, 4], [5, 6]]

    >>> list(parts([1, 2, 3, 4, 5, 6], length=[1, 2, 3]))
    [[1], [2, 3], [4, 5, 6]]

    >>> list(parts([1, 2, 3, 4, 5, 6, 7], number=3, length=2))
    Traceback (most recent call last):
      ...
    ValueError: cannot retrieve 3 parts from object given part length parameter of 2

Development
-----------
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:

.. code-block:: bash

    python -m pip install ".[docs,lint]"

Documentation
^^^^^^^^^^^^^
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:

.. code-block:: bash

    python -m pip install ".[docs]"
    cd docs
    sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html

Testing and Conventions
^^^^^^^^^^^^^^^^^^^^^^^
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):

.. code-block:: bash

    python -m pip install ".[test]"
    python -m pytest

Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:

.. code-block:: bash

    python src/parts/parts.py -v

Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:

.. code-block:: bash

    python -m pip install ".[lint]"
    python -m pylint src/parts

Contributions
^^^^^^^^^^^^^
In order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/lapets/parts>`__ for this library.

Versioning
^^^^^^^^^^
Beginning with version 0.2.0, the version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 <https://semver.org/#semantic-versioning-200>`__.

Publishing
^^^^^^^^^^
This library can be published as a `package on PyPI <https://pypi.org/project/parts>`__ via the GitHub Actions workflow found in ``.github/workflows/build-publish-sign-release.yml`` that follows the `recommendations found in the Python Packaging User Guide <https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/>`__.

Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions.

To publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number):

.. code-block:: bash

    git tag ?.?.?
    git push origin ?.?.?

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "parts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Andrei Lapets",
    "author_email": "a@lapets.io",
    "download_url": "https://files.pythonhosted.org/packages/da/ec/b651b06d388bda33e02d3a03c768ff6c53c266cf99c6268b9bc09abfd298/parts-2.1.0.tar.gz",
    "platform": null,
    "description": "=====\nparts\n=====\n\nMinimal library that enables partitioning of iterable collections in a concise manner.\n\n|pypi| |readthedocs| |actions| |coveralls|\n\n.. |pypi| image:: https://badge.fury.io/py/parts.svg#\n   :target: https://badge.fury.io/py/parts\n   :alt: PyPI version and link.\n\n.. |readthedocs| image:: https://readthedocs.org/projects/parts/badge/?version=latest\n   :target: https://parts.readthedocs.io/en/latest/?badge=latest\n   :alt: Read the Docs documentation status.\n\n.. |actions| image:: https://github.com/lapets/parts/workflows/lint-test-cover-docs/badge.svg#\n   :target: https://github.com/lapets/parts/actions/workflows/lint-test-cover-docs.yml\n   :alt: GitHub Actions status.\n\n.. |coveralls| image:: https://coveralls.io/repos/github/lapets/parts/badge.svg?branch=main\n   :target: https://coveralls.io/github/lapets/parts?branch=main\n   :alt: Coveralls test coverage summary.\n\nPurpose\n-------\nThis library provides a function for partitioning `iterable <https://docs.python.org/3/glossary.html#term-iterable>`__ data structure instances. When the number of parts is specified explicitly, it is treated as a strict requirement and an exception is raised when it cannot be satisfied. When a length for all parts (or each part) is specified explicitly, a best-effort approach is used: as many parts of the specified length are retrieved as possible, with the possibility that some parts at the end of the partition sequence have a shorter (but still non-zero) length.\n\nInstallation and Usage\n----------------------\nThis library is available as a `package on PyPI <https://pypi.org/project/parts>`__:\n\n.. code-block:: bash\n\n    python -m pip install parts\n\nThe library can be imported in the usual manner:\n\n.. code-block:: python\n\n    import parts\n    from parts import parts\n\nExamples\n^^^^^^^^\nSeveral examples are presented below:\n\n.. code-block:: python\n\n    >>> list(parts([1, 2, 3, 4, 5, 6, 7], length=2))\n    [[1, 2], [3, 4], [5, 6], [7]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6, 7], length=4))\n    [[1, 2, 3, 4], [5, 6, 7]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6, 7], number=1))\n    [[1, 2, 3, 4, 5, 6, 7]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6, 7], 5))\n    [[1], [2], [3], [4, 5], [6, 7]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6], 2, 3))\n    [[1, 2, 3], [4, 5, 6]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6], number=3, length=2))\n    [[1, 2], [3, 4], [5, 6]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6, 7], 7, [1, 1, 1, 1, 1, 1, 1]))\n    [[1], [2], [3], [4], [5], [6], [7]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6], length=[2, 2, 2]))\n    [[1, 2], [3, 4], [5, 6]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6], length=[1, 2, 3]))\n    [[1], [2, 3], [4, 5, 6]]\n\n    >>> list(parts([1, 2, 3, 4, 5, 6, 7], number=3, length=2))\n    Traceback (most recent call last):\n      ...\n    ValueError: cannot retrieve 3 parts from object given part length parameter of 2\n\nDevelopment\n-----------\nAll installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[docs,lint]\"\n\nDocumentation\n^^^^^^^^^^^^^\nThe documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[docs]\"\n    cd docs\n    sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html\n\nTesting and Conventions\n^^^^^^^^^^^^^^^^^^^^^^^\nAll unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):\n\n.. code-block:: bash\n\n    python -m pip install \".[test]\"\n    python -m pytest\n\nAlternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:\n\n.. code-block:: bash\n\n    python src/parts/parts.py -v\n\nStyle conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:\n\n.. code-block:: bash\n\n    python -m pip install \".[lint]\"\n    python -m pylint src/parts\n\nContributions\n^^^^^^^^^^^^^\nIn order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/lapets/parts>`__ for this library.\n\nVersioning\n^^^^^^^^^^\nBeginning with version 0.2.0, the version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 <https://semver.org/#semantic-versioning-200>`__.\n\nPublishing\n^^^^^^^^^^\nThis library can be published as a `package on PyPI <https://pypi.org/project/parts>`__ via the GitHub Actions workflow found in ``.github/workflows/build-publish-sign-release.yml`` that follows the `recommendations found in the Python Packaging User Guide <https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/>`__.\n\nEnsure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions.\n\nTo publish the package, create and push a tag for the version being published (replacing ``?.?.?`` with the version number):\n\n.. code-block:: bash\n\n    git tag ?.?.?\n    git push origin ?.?.?\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Minimal library that enables partitioning of iterable collections in a concise manner.",
    "version": "2.1.0",
    "project_urls": {
        "Documentation": "https://parts.readthedocs.io",
        "Repository": "https://github.com/lapets/parts"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4a8ef229c54918a76e99350ca460117cd288201850dcef907d03b223d2f45d9c",
                "md5": "b504845a8c3caac4837dd093b5736a2d",
                "sha256": "abc2e742fd0449f5f80f37272c7e1d2a05f035f495f34071d3028a4dd3ff0518"
            },
            "downloads": -1,
            "filename": "parts-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b504845a8c3caac4837dd093b5736a2d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7666,
            "upload_time": "2024-12-24T04:06:13",
            "upload_time_iso_8601": "2024-12-24T04:06:13.535284Z",
            "url": "https://files.pythonhosted.org/packages/4a/8e/f229c54918a76e99350ca460117cd288201850dcef907d03b223d2f45d9c/parts-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "daecb651b06d388bda33e02d3a03c768ff6c53c266cf99c6268b9bc09abfd298",
                "md5": "b1f2dc86840882a8e74355a61971f687",
                "sha256": "cdab873aff29338ec2548408a3c68c30f649830228c206d52ef7c55b322a1e87"
            },
            "downloads": -1,
            "filename": "parts-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b1f2dc86840882a8e74355a61971f687",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9377,
            "upload_time": "2024-12-24T04:06:15",
            "upload_time_iso_8601": "2024-12-24T04:06:15.063635Z",
            "url": "https://files.pythonhosted.org/packages/da/ec/b651b06d388bda33e02d3a03c768ff6c53c266cf99c6268b9bc09abfd298/parts-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-24 04:06:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lapets",
    "github_project": "parts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "parts"
}
        
Elapsed time: 1.28409s