# highlighter
Easy to use PEP 508 markers. These are the strings in requirements after a
semicolon, such as `enum34; python_version < '3.5'` means the package `enum34`
but only on some versions of python.
```py
from packaging.markers import Marker
from packaging.requirements import Requirement
from highlighter import EnvironmentMarkers
req = Requirement("enum34; python_version < '3.5'")
env = EnvironmentMarkers.for_python("3.7.5", "win32")
env.match(req.marker) # False
# Lower-level interface, you can use Marker directly
m = Marker("python_version < '3.5'")
env.match(m) # False
# What about extras?
req = Requirement("somepackage[foo,bar]")
m = Marker("extra == 'foo'")
env.match(m, extras=req.extras) # True
```
## Egg-info Extras
This also includes a function that can convert a requires.txt (as found in
egg-info dirs, the only kind we have in sdists) into an equivalent list of
requirements.txt lines using PEP 508 markers.
```py
from highlighter.sdist import convert_sdist_requires
convert_sdist_requires("""\
[socks]
PySocks!=1.5.7,>=1.5.6
[socks:sys_platform == "win32" and python_version == "2.7"]
win_inet_pton
""") == """\
PySocks!=1.5.7,>=1.5.6; extra == 'socks'
win_inet_pton; (sys_platform == "win32" and python_version == "2.7") and extra == 'socks'
"""
```
# License
highlighter is copyright [Tim Hatch](https://timhatch.com/), and licensed under
the MIT license. I am providing code in this repository to you under an open
source license. This is my personal repository; the license you receive to
my code is from me and not from my employer. See the `LICENSE` file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/python-packaging/highlighter",
"name": "highlighter",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "",
"author": "Tim Hatch",
"author_email": "tim@timhatch.com",
"download_url": "https://files.pythonhosted.org/packages/d5/fc/d5d1e8b1fb9468efab7ca0f1955376448ca135d6c0b78259288f751ab1a0/highlighter-0.2.0.tar.gz",
"platform": null,
"description": "# highlighter\n\nEasy to use PEP 508 markers. These are the strings in requirements after a\nsemicolon, such as `enum34; python_version < '3.5'` means the package `enum34`\nbut only on some versions of python.\n\n\n```py\nfrom packaging.markers import Marker\nfrom packaging.requirements import Requirement\n\nfrom highlighter import EnvironmentMarkers\n\nreq = Requirement(\"enum34; python_version < '3.5'\")\n\nenv = EnvironmentMarkers.for_python(\"3.7.5\", \"win32\")\nenv.match(req.marker) # False\n\n# Lower-level interface, you can use Marker directly\nm = Marker(\"python_version < '3.5'\")\nenv.match(m) # False\n\n# What about extras?\nreq = Requirement(\"somepackage[foo,bar]\")\nm = Marker(\"extra == 'foo'\")\nenv.match(m, extras=req.extras) # True\n```\n\n## Egg-info Extras\n\nThis also includes a function that can convert a requires.txt (as found in\negg-info dirs, the only kind we have in sdists) into an equivalent list of\nrequirements.txt lines using PEP 508 markers.\n\n```py\nfrom highlighter.sdist import convert_sdist_requires\n\nconvert_sdist_requires(\"\"\"\\\n[socks]\nPySocks!=1.5.7,>=1.5.6\n\n[socks:sys_platform == \"win32\" and python_version == \"2.7\"]\nwin_inet_pton\n\"\"\") == \"\"\"\\\nPySocks!=1.5.7,>=1.5.6; extra == 'socks'\nwin_inet_pton; (sys_platform == \"win32\" and python_version == \"2.7\") and extra == 'socks'\n\"\"\"\n```\n\n# License\n\nhighlighter is copyright [Tim Hatch](https://timhatch.com/), and licensed under\nthe MIT license. I am providing code in this repository to you under an open\nsource license. This is my personal repository; the license you receive to\nmy code is from me and not from my employer. See the `LICENSE` file for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Easy-to-use PEP 508 markers",
"version": "0.2.0",
"project_urls": {
"Homepage": "https://github.com/python-packaging/highlighter"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b14898b0951b8250bf82c73859299fddf2f94c4f0faced1eef583caea64a16c2",
"md5": "13d4d9596136454c3223873b7f5d3c10",
"sha256": "08206ab8c0e0b6c8f77e9184df743bc7189a22e7ea062cc084d5f05a139d6a7f"
},
"downloads": -1,
"filename": "highlighter-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "13d4d9596136454c3223873b7f5d3c10",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 6528,
"upload_time": "2024-01-22T17:38:51",
"upload_time_iso_8601": "2024-01-22T17:38:51.902791Z",
"url": "https://files.pythonhosted.org/packages/b1/48/98b0951b8250bf82c73859299fddf2f94c4f0faced1eef583caea64a16c2/highlighter-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d5fcd5d1e8b1fb9468efab7ca0f1955376448ca135d6c0b78259288f751ab1a0",
"md5": "9bc8a443580f955f0570b68425918233",
"sha256": "8c32c8636e4e862d9415f665b4cba108418a5649485183f61da2de96d5d9734b"
},
"downloads": -1,
"filename": "highlighter-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "9bc8a443580f955f0570b68425918233",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 7156,
"upload_time": "2024-01-22T17:38:53",
"upload_time_iso_8601": "2024-01-22T17:38:53.052076Z",
"url": "https://files.pythonhosted.org/packages/d5/fc/d5d1e8b1fb9468efab7ca0f1955376448ca135d6c0b78259288f751ab1a0/highlighter-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-22 17:38:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "python-packaging",
"github_project": "highlighter",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "highlighter"
}