diff --git a/README.md b/README.md index dbc8908..378d2e4 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,13 @@ The command-line interface accepts a local HTML file or a URL: python -m readability -u https://example.com ``` +Installing the package also provides the `readability-lxml` command with the same +options. You can run it without a separate installation using `uvx`: + +```bash +uvx readability-lxml article.html +``` + Run the real-page extraction benchmark with the default minimum F1 of 0.95: ```bash diff --git a/pyproject.toml b/pyproject.toml index 22cfc61..01f5cd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,9 @@ include = [ { path = "NOTICE", format = ["sdist", "wheel"] }, ] +[tool.poetry.scripts] +readability-lxml = "readability.readability:main" + [tool.poetry.dependencies] python = ">=3.8.2,<3.15" chardet = "^5.2.0" diff --git a/setup.py b/setup.py index d4653f4..c764d48 100755 --- a/setup.py +++ b/setup.py @@ -42,6 +42,9 @@ def find_version(*file_paths): license="Apache License 2.0", url="http://github.com/buriy/python-readability", packages=["readability"], + entry_points={ + "console_scripts": ["readability-lxml=readability.readability:main"], + }, python_requires=">=3.8.2,<3.15", install_requires=[ "chardet", diff --git a/tests/test_command_line.py b/tests/test_command_line.py index a85512d..5dae3eb 100644 --- a/tests/test_command_line.py +++ b/tests/test_command_line.py @@ -1,10 +1,21 @@ +import os import subprocess import sys +import sysconfig +from pathlib import Path +import pytest -def test_package_command_line_help(): + +CONSOLE_SCRIPT = Path(sysconfig.get_path("scripts")) / ( + "readability-lxml.exe" if os.name == "nt" else "readability-lxml" +) + + +@pytest.mark.parametrize("command", [[sys.executable, "-m", "readability"], [str(CONSOLE_SCRIPT)]]) +def test_package_command_line_help(command): result = subprocess.run( - [sys.executable, "-m", "readability", "--help"], + command + ["--help"], check=True, capture_output=True, text=True, @@ -12,3 +23,21 @@ def test_package_command_line_help(): assert "Usage:" in result.stdout assert result.stderr == "" + + +def test_console_script_reads_local_file(tmp_path): + html = tmp_path / "article.html" + html.write_text( + "Example article" + "

This is the article content.

", + encoding="utf-8", + ) + result = subprocess.run( + [str(CONSOLE_SCRIPT), str(html)], + check=True, + capture_output=True, + text=True, + ) + assert "Title:Example article" in result.stdout + assert "This is the article content." in result.stdout + assert result.stderr == ""