Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 31 additions & 2 deletions tests/test_command_line.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
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,
)

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(
"<html><head><title>Example article</title></head>"
"<body><article><p>This is the article content.</p></article></body></html>",
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 == ""