extreqs


Nameextreqs JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/clbarnes/extreqs
SummaryParse python requirements.txt files into setuptools extras
upload_time2023-03-20 17:19:43
maintainer
docs_urlNone
authorChris L. Barnes
requires_python>=3.7, <4.0
license
keywords
VCS
bugtrack_url
requirements black flake8 isort mypy pdoc3 pytest setuptools setuptools-scm types-setuptools wheel
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # extreqs

Parse python requirements.txt files into setuptools extras.

## Usage

`extreqs` looks for special comments (`#extra:`) in your requirements files.
Note the lack of space after the `#`!
Anything which follows that (until the end of line, or another `#`) is treated as a whitespace-separated list of extras.
For example, `#extra: dev test doc` marks dependencies belonging to the `dev`, `test`, and `doc` extras.

If the `#extra:` comment is on the same line as (following) a dependency, then just that dependency belongs to that extra.
If the `#extra:` comment is on a line on its own, all dependencies below it belong to that extra, until the next `#extra:` line.

For example:

```txt
# requirements.txt
dep1
dep2  #extra: extra1

#extra: extra2
dep3

#extra: extra3  # you can still have freeform comments!
dep4  #extra: extra4 extra5
dep5
```

would be parsed into

```python
install_requires = ["dep1"]
extras_require = {
    "extra1": ["dep2"],
    "extra2": ["dep3"],
    "extra3": ["dep4", "dep5"],
    "extra4": ["dep4"],
    "extra5": ["dep4"],
}
```

Additionally, entire files can belong to a particular extra.

Note that python extras are not smart enough to deal with dependencies which belong only to _combinations_ of extras, or _negative_ extras: a dependency which belongs to multiple extras (given by the context of the file, block, or line) just belongs to multiple extras.
This is a limitation of python packaging and cannot be addressed here.

In your `setup.py`:

```python
#!/usr/bin/env python3
"""setup.py"""
from pathlib import Path

from extreqs import parse_requirements_files_dict
from setuptools import setup

here = Path(__file__).resolve().parent

req_kwargs = parse_requirements_files_dict(
    # files without an extra context are in *args
    here / "requirements.txt",
    # files with an extra context are in **kwargs
    optional=here / "requirements-optional.txt",
)

setup(
    name="my_package",
    ...
    **req_kwargs,
    ...
)
```

`extreqs` is an install-time dependency, and so must be added to your `pyproject.toml`:

```toml
# pyproject.toml
[build-system]
requires = ["setuptools", "extreqs"]
build-backend = "setuptools.build_meta"
```

Look out for dependency specifiers which are accepted by pip, but not by setuptools (e.g. editable install `-e` or references to other requirement files `-r`).

## Notes

This package should only be used in certain circumstances, and may lead to bad habits if over-used.
Requirements files are intended for specifying reproducible (i.e. hard version constraints), maximal environments for other developers, CI, and so on to be able to run all tests, features, lints etc..
Package dependencies are intended to specify the minimal dependencies with permissive version constraints for users to install the package for use.

This package is, therefore, more applicable to distributing applications (CLI, web backends, etc.) than it is libraries.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/clbarnes/extreqs",
    "name": "extreqs",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7, <4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Chris L. Barnes",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/06/1b/8e8673295341d744a393aa811b0b0e9c5b4953c38880fe24290e31ce98d6/extreqs-1.1.0.tar.gz",
    "platform": null,
    "description": "# extreqs\n\nParse python requirements.txt files into setuptools extras.\n\n## Usage\n\n`extreqs` looks for special comments (`#extra:`) in your requirements files.\nNote the lack of space after the `#`!\nAnything which follows that (until the end of line, or another `#`) is treated as a whitespace-separated list of extras.\nFor example, `#extra: dev test doc` marks dependencies belonging to the `dev`, `test`, and `doc` extras.\n\nIf the `#extra:` comment is on the same line as (following) a dependency, then just that dependency belongs to that extra.\nIf the `#extra:` comment is on a line on its own, all dependencies below it belong to that extra, until the next `#extra:` line.\n\nFor example:\n\n```txt\n# requirements.txt\ndep1\ndep2  #extra: extra1\n\n#extra: extra2\ndep3\n\n#extra: extra3  # you can still have freeform comments!\ndep4  #extra: extra4 extra5\ndep5\n```\n\nwould be parsed into\n\n```python\ninstall_requires = [\"dep1\"]\nextras_require = {\n    \"extra1\": [\"dep2\"],\n    \"extra2\": [\"dep3\"],\n    \"extra3\": [\"dep4\", \"dep5\"],\n    \"extra4\": [\"dep4\"],\n    \"extra5\": [\"dep4\"],\n}\n```\n\nAdditionally, entire files can belong to a particular extra.\n\nNote that python extras are not smart enough to deal with dependencies which belong only to _combinations_ of extras, or _negative_ extras: a dependency which belongs to multiple extras (given by the context of the file, block, or line) just belongs to multiple extras.\nThis is a limitation of python packaging and cannot be addressed here.\n\nIn your `setup.py`:\n\n```python\n#!/usr/bin/env python3\n\"\"\"setup.py\"\"\"\nfrom pathlib import Path\n\nfrom extreqs import parse_requirements_files_dict\nfrom setuptools import setup\n\nhere = Path(__file__).resolve().parent\n\nreq_kwargs = parse_requirements_files_dict(\n    # files without an extra context are in *args\n    here / \"requirements.txt\",\n    # files with an extra context are in **kwargs\n    optional=here / \"requirements-optional.txt\",\n)\n\nsetup(\n    name=\"my_package\",\n    ...\n    **req_kwargs,\n    ...\n)\n```\n\n`extreqs` is an install-time dependency, and so must be added to your `pyproject.toml`:\n\n```toml\n# pyproject.toml\n[build-system]\nrequires = [\"setuptools\", \"extreqs\"]\nbuild-backend = \"setuptools.build_meta\"\n```\n\nLook out for dependency specifiers which are accepted by pip, but not by setuptools (e.g. editable install `-e` or references to other requirement files `-r`).\n\n## Notes\n\nThis package should only be used in certain circumstances, and may lead to bad habits if over-used.\nRequirements files are intended for specifying reproducible (i.e. hard version constraints), maximal environments for other developers, CI, and so on to be able to run all tests, features, lints etc..\nPackage dependencies are intended to specify the minimal dependencies with permissive version constraints for users to install the package for use.\n\nThis package is, therefore, more applicable to distributing applications (CLI, web backends, etc.) than it is libraries.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Parse python requirements.txt files into setuptools extras",
    "version": "1.1.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ec2fa1a9013ebd76389581f231c3169bf5f02c0a1ef6ed8756a8ea207c7c54e1",
                "md5": "41c46bc3215737ef535dd4643a13eb3c",
                "sha256": "8c43b6d1828f8e12c65376ab8142986a121fc4d317ad2d7a6d5bc385bfdfc388"
            },
            "downloads": -1,
            "filename": "extreqs-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41c46bc3215737ef535dd4643a13eb3c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7, <4.0",
            "size": 5486,
            "upload_time": "2023-03-20T17:19:41",
            "upload_time_iso_8601": "2023-03-20T17:19:41.949556Z",
            "url": "https://files.pythonhosted.org/packages/ec/2f/a1a9013ebd76389581f231c3169bf5f02c0a1ef6ed8756a8ea207c7c54e1/extreqs-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "061b8e8673295341d744a393aa811b0b0e9c5b4953c38880fe24290e31ce98d6",
                "md5": "e28806263c5388cf2f55460ed0df6d44",
                "sha256": "eedf9f3da76e5df81a17d32fb216c1921dfcd2252215f3f6d2f2e729b4d9f6c7"
            },
            "downloads": -1,
            "filename": "extreqs-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e28806263c5388cf2f55460ed0df6d44",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7, <4.0",
            "size": 7755,
            "upload_time": "2023-03-20T17:19:43",
            "upload_time_iso_8601": "2023-03-20T17:19:43.466290Z",
            "url": "https://files.pythonhosted.org/packages/06/1b/8e8673295341d744a393aa811b0b0e9c5b4953c38880fe24290e31ce98d6/extreqs-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-20 17:19:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "clbarnes",
    "github_project": "extreqs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "black",
            "specs": []
        },
        {
            "name": "flake8",
            "specs": []
        },
        {
            "name": "isort",
            "specs": []
        },
        {
            "name": "mypy",
            "specs": []
        },
        {
            "name": "pdoc3",
            "specs": []
        },
        {
            "name": "pytest",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        },
        {
            "name": "setuptools-scm",
            "specs": []
        },
        {
            "name": "types-setuptools",
            "specs": []
        },
        {
            "name": "wheel",
            "specs": []
        }
    ],
    "lcname": "extreqs"
}
        
Elapsed time: 0.05472s