python3Packages.primp: drop, python3Packages.ddgs: replace primp with httpx (#453960)

This commit is contained in:
Gaétan Lepage
2025-10-20 19:51:55 +00:00
committed by GitHub
6 changed files with 54 additions and 181 deletions
@@ -4,7 +4,6 @@
fetchFromGitHub,
setuptools,
click,
primp,
lxml,
httpx,
h2,
@@ -23,11 +22,23 @@ buildPythonPackage rec {
hash = "sha256-NaOwklHea3TUDa2M23X549IiX5zP87N9qWKkr5PObLY=";
};
patches = [
# We're removing the HTTP client primp below for security reasons,
# but can use the already included httpx instead.
# Note that while httpx is only used for HTTP/2 by upstream,
# it can handle HTTP/1.1 just fine as well.
./replace-primp.patch
];
pythonRemoveDeps = [
# primp requires a very outdated, potentially insecure version of boringssl
"primp"
];
build-system = [ setuptools ];
dependencies = [
click
primp
lxml
httpx
h2
@@ -0,0 +1,39 @@
diff --git a/ddgs/base.py b/ddgs/base.py
index e964511..34d1c4f 100644
--- a/ddgs/base.py
+++ b/ddgs/base.py
@@ -11,7 +11,7 @@ from typing import Any, Generic, Literal, TypeVar
from lxml import html
from lxml.etree import HTMLParser as LHTMLParser
-from .http_client import HttpClient
+from .http_client2 import HttpClient2 as HttpClient
from .results import BooksResult, ImagesResult, NewsResult, TextResult, VideosResult
logger = logging.getLogger(__name__)
diff --git a/ddgs/cli.py b/ddgs/cli.py
index d295f77..38adb71 100644
--- a/ddgs/cli.py
+++ b/ddgs/cli.py
@@ -12,11 +12,11 @@ from typing import Any
from urllib.parse import unquote
import click
-import primp
from . import __version__
from .ddgs import DDGS
from .utils import _expand_proxy_tb_alias, json_dumps
+from .http_client2 import HttpClient2
logger = logging.getLogger(__name__)
@@ -101,7 +101,7 @@ def _sanitize_query(query: str) -> str:
def _download_file(url: str, dir_path: str, filename: str, proxy: str | None, verify: bool) -> None:
try:
- resp = primp.Client(proxy=proxy, impersonate="random", impersonate_os="random", timeout=10, verify=verify).get(
+ resp = HttpClient2(proxy=proxy, timeout=10, verify=verify).get(
url
)
if resp.status_code == 200:
@@ -1,43 +0,0 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
setuptools,
click,
primp,
lxml,
}:
buildPythonPackage rec {
pname = "duckduckgo-search";
version = "9.5.5";
pyproject = true;
src = fetchFromGitHub {
owner = "deedy5";
repo = "ddgs";
tag = "v${version}";
hash = "sha256-Pwl6fCEBj+eUXYEf4wCTw1fpKZh3j4IVC6SW0Vqcmf4=";
};
build-system = [ setuptools ];
dependencies = [
click
primp
lxml
];
doCheck = false; # tests require network access
pythonImportsCheck = [ "ddgs" ];
meta = {
description = "Python CLI and library for searching for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine";
mainProgram = "ddgs";
homepage = "https://github.com/deedy5/ddgs";
changelog = "https://github.com/deedy5/ddgs/releases/tag/${src.tag}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ drawbu ];
};
}
@@ -1,132 +0,0 @@
{
lib,
stdenv,
buildPythonPackage,
fetchFromGitHub,
rustPlatform,
pytest,
runCommand,
boringssl,
libiconv,
gcc-unwrapped,
python,
fetchpatch,
}:
let
boringsslPatched = boringssl.overrideAttrs (oa: {
# boringssl source obtained from https://github.com/0x676e67/boring2/tree/1a0f1cd24e728aac100df68027c820f858199224/boring-sys/deps
src = fetchFromGitHub {
owner = "google";
repo = "boringssl";
rev = "44b3df6f03d85c901767250329c571db405122d5";
hash = "sha256-REELo7X9aFy2OHjubYLO1UQXLTgekD4QFd2vyFthIrg=";
};
modRoot = "./src";
patches = [
# A patch required to build boringssl compatible with `boring-sys2`.
# See https://github.com/0x676e67/boring2/blob/refs/tags/v4.15.11/boring-sys/build/main.rs#L486-L489
(fetchpatch {
name = "boringssl-44b3df6f03d85c901767250329c571db405122d5.patch";
url = "https://raw.githubusercontent.com/0x676e67/boring2/refs/tags/v4.15.11/boring-sys/patches/boringssl-44b3df6f03d85c901767250329c571db405122d5.patch";
hash = "sha256-JRRATcCXo0HBQTzgCAuLpxC3NEGrTw1cEmC0VHOgO2M=";
})
];
# Remove bazel specific build file to make way for build directory
# This is a problem on Darwin because of case-insensitive filesystem
preBuild =
(lib.optionalString stdenv.hostPlatform.isDarwin ''
rm ../BUILD
'')
+ oa.preBuild;
env.NIX_CFLAGS_COMPILE =
oa.env.NIX_CFLAGS_COMPILE
+ " "
+ toString (
lib.optionals stdenv.cc.isClang [
"-Wno-error=reorder-ctor"
]
++ lib.optionals stdenv.cc.isGNU [
"-Wno-error=reorder"
"-Wno-error=ignored-attributes"
]
);
vendorHash = "sha256-06MkjXl0DKFzIH/H+uT9kXsQdPq7qdZh2dlLW/YhJuk=";
installPhase = ''
runHook preInstall
mkdir -p $bin/bin $dev $out/lib
install -Dm755 tool/bssl -t $bin/bin
install -Dm644 ssl/libssl.a -t $out/lib
install -Dm644 crypto/libcrypto.a -t $out/lib
install -Dm644 decrepit/libdecrepit.a -t $out/lib
cp -r ../include $dev
runHook postInstall
'';
});
# boring-sys expects the static libraries in build/ instead of lib/
boringssl-wrapper = runCommand "boringssl-wrapper" { } ''
mkdir $out
ln -s ${boringsslPatched.out}/lib $out/build
ln -s ${boringsslPatched.dev}/include $out/include
'';
in
buildPythonPackage rec {
pname = "primp";
version = "0.15.0";
pyproject = true;
src = fetchFromGitHub {
owner = "deedy5";
repo = "primp";
tag = "v${version}";
hash = "sha256-13o0Ni0dvZaoKgYy2cFQhebwKAJGm5Z2s+gVAddxYxU=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-UBpf9f3wJgbizHERsm83cuKHiMixj/8JX/IGvteySIo=";
};
nativeBuildInputs = [
rustPlatform.bindgenHook
rustPlatform.cargoSetupHook
rustPlatform.maturinBuildHook
];
# TODO: Can we improve this?
postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
patchelf --add-rpath ${lib.getLib gcc-unwrapped.lib} --add-needed libstdc++.so.6 $out/${python.sitePackages}/primp/primp.abi3.so
'';
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
libiconv
];
env.BORING_BSSL_PATH = boringssl-wrapper;
env.BORING_BSSL_ASSUME_PATCHED = true;
optional-dependencies = {
dev = [ pytest ];
};
# Test use network
doCheck = false;
pythonImportsCheck = [ "primp" ];
meta = {
changelog = "https://github.com/deedy5/primp/releases/tag/${version}";
description = "Python Requests IMPersonate, the fastest Python HTTP client that can impersonate web browsers";
homepage = "https://github.com/deedy5/primp";
license = lib.licenses.mit;
maintainers = [ ];
};
}
+2
View File
@@ -238,6 +238,7 @@ mapAliases {
doctest-ignore-unicode = throw "doctest-ignore-unicode has been removed since it has been unmaintained for 11 years"; # added 2024-05-20
dogpile_cache = dogpile-cache; # added 2021-10-28
dogpile-core = throw "dogpile-core is no longer maintained, use dogpile-cache instead"; # added 2021-11-20
duckduckgo-search = ddgs; # added 2025-10-20
dugong = throw "dugong is unmaintained since 2022 and has therefore been removed"; # added 2024-12-12
editdistance-s = throw "editdistance-s has been removed since it was added solely for the identity package, which has moved on to ukkonen"; # added 2025-08-04
easyeda2ato = throw "easyeda2ato as been removed in favor of atopile-easyda2kicad"; # added 2025-06-08
@@ -541,6 +542,7 @@ mapAliases {
powerlineMemSegment = powerline-mem-segment; # added 2021-10-08
prayer-times-calculator = prayer-times-calculator-offline; # added 2024-08-11
premailer = throw "premailer was removed, as it is not compatible with lxml>4.9.4.";
primp = throw "primp was removed as it required a very outdated version of boringssl"; # added 2025-10-20
privacyidea-ldap-proxy = throw "privacyidea-ldap-proxy has been removed from nixpkgs"; # added 2023-10-31
proboscis = throw "proboscis has been removed since it has not been maintained for 11 years"; # added 2024-05-20
prometheus_client = prometheus-client; # added 2021-06-10
-4
View File
@@ -4479,8 +4479,6 @@ self: super: with self; {
duckdb-engine = callPackage ../development/python-modules/duckdb-engine { };
duckduckgo-search = callPackage ../development/python-modules/duckduckgo-search { };
duct-py = callPackage ../development/python-modules/duct-py { };
duden = callPackage ../development/python-modules/duden { };
@@ -12168,8 +12166,6 @@ self: super: with self; {
primer3 = callPackage ../development/python-modules/primer3 { };
primp = callPackage ../development/python-modules/primp { };
print-color = callPackage ../development/python-modules/print-color { };
priority = callPackage ../development/python-modules/priority { };