mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 06:21:30 +03:00
pdm: Use fetchFromPypi from pyproject.nix
This commit is contained in:
parent
e28ae15e36
commit
2c8f520108
@ -9,6 +9,10 @@
|
||||
};
|
||||
|
||||
libpyproject = import (dream2nix.inputs.pyproject-nix + "/lib") {inherit lib;};
|
||||
libpyproject-fetchers = import (dream2nix.inputs.pyproject-nix + "/fetchers") {
|
||||
inherit lib;
|
||||
pkgs = config.deps;
|
||||
};
|
||||
|
||||
selectWheel = files: let
|
||||
wheelFiles = lib.filter libpyproject.pypa.isWheelFileName files;
|
||||
@ -31,11 +35,6 @@
|
||||
parsed_lock_data = libpdm.parseLockData {
|
||||
inherit environ lock_data selector;
|
||||
};
|
||||
|
||||
fetchFromPypi = import ./fetch-from-pypi.nix {
|
||||
inherit lib;
|
||||
inherit (config.deps) curl jq stdenvNoCC;
|
||||
};
|
||||
in {
|
||||
imports = [
|
||||
dream2nix.modules.dream2nix.groups
|
||||
@ -48,6 +47,7 @@ in {
|
||||
deps = {nixpkgs, ...}: {
|
||||
inherit
|
||||
(nixpkgs)
|
||||
buildPackages
|
||||
curl
|
||||
jq
|
||||
stdenvNoCC
|
||||
@ -94,7 +94,7 @@ in {
|
||||
};
|
||||
mkDerivation = {
|
||||
# required: { pname, file, version, hash, kind, curlOpts ? "" }:
|
||||
src = fetchFromPypi {
|
||||
src = libpyproject-fetchers.fetchFromPypi {
|
||||
pname = name;
|
||||
file = pkg.source.file;
|
||||
version = pkg.version;
|
||||
|
@ -1,73 +0,0 @@
|
||||
# copied from poetry2nix
|
||||
# LICENSE: https://github.com/nix-community/poetry2nix/blob/master/LICENSE
|
||||
{
|
||||
lib,
|
||||
curl,
|
||||
jq,
|
||||
stdenvNoCC,
|
||||
}: let
|
||||
# Predict URL from the PyPI index.
|
||||
# Args:
|
||||
# pname: package name
|
||||
# file: filename including extension
|
||||
# hash: SRI hash
|
||||
# kind: Language implementation and version tag
|
||||
predictURLFromPypi = lib.makeOverridable (
|
||||
{
|
||||
pname,
|
||||
file,
|
||||
hash,
|
||||
kind,
|
||||
}: "https://files.pythonhosted.org/packages/${kind}/${lib.toLower (builtins.substring 0 1 file)}/${pname}/${file}"
|
||||
);
|
||||
|
||||
# Fetch from the PyPI index.
|
||||
# At first we try to fetch the predicated URL but if that fails we
|
||||
# will use the Pypi API to determine the correct URL.
|
||||
# Args:
|
||||
# pname: package name
|
||||
# file: filename including extension
|
||||
# version: the version string of the dependency
|
||||
# hash: SRI hash
|
||||
# kind: Language implementation and version tag
|
||||
fetchFromPypi = lib.makeOverridable (
|
||||
{
|
||||
pname,
|
||||
file,
|
||||
version,
|
||||
hash,
|
||||
kind,
|
||||
curlOpts ? "",
|
||||
}: let
|
||||
predictedURL = predictURLFromPypi {inherit pname file hash kind;};
|
||||
in (stdenvNoCC.mkDerivation {
|
||||
name = file;
|
||||
nativeBuildInputs = [
|
||||
curl
|
||||
jq
|
||||
];
|
||||
isWheel = lib.strings.hasSuffix "whl" file;
|
||||
system = "builtin";
|
||||
|
||||
preferLocalBuild = true;
|
||||
impureEnvVars =
|
||||
lib.fetchers.proxyImpureEnvVars
|
||||
++ [
|
||||
"NIX_CURL_FLAGS"
|
||||
];
|
||||
|
||||
inherit pname file version curlOpts predictedURL;
|
||||
|
||||
builder = ./fetch-from-pypi.sh;
|
||||
|
||||
outputHashMode = "flat";
|
||||
outputHashAlgo = "sha256";
|
||||
outputHash = hash;
|
||||
|
||||
passthru = {
|
||||
urls = [predictedURL]; # retain compatibility with nixpkgs' fetchurl
|
||||
};
|
||||
})
|
||||
);
|
||||
in
|
||||
fetchFromPypi
|
@ -1,27 +0,0 @@
|
||||
# copied from poetry2nix
|
||||
# LICENSE: https://github.com/nix-community/poetry2nix/blob/master/LICENSE
|
||||
|
||||
source $stdenv/setup
|
||||
set -euo pipefail
|
||||
|
||||
curl="curl \
|
||||
--location \
|
||||
--max-redirs 20 \
|
||||
--retry 2 \
|
||||
--disable-epsv \
|
||||
--cookie-jar cookies \
|
||||
--insecure \
|
||||
--speed-time 5 \
|
||||
--progress-bar \
|
||||
--fail \
|
||||
$curlOpts \
|
||||
$NIX_CURL_FLAGS"
|
||||
|
||||
echo "Trying to fetch with predicted URL: $predictedURL"
|
||||
|
||||
$curl $predictedURL --output $out && exit 0
|
||||
|
||||
echo "Predicted URL '$predictedURL' failed, querying pypi.org"
|
||||
$curl "https://pypi.org/pypi/$pname/json" | jq -r ".releases.\"$version\"[] | select(.filename == \"$file\") | .url" > url
|
||||
url=$(cat url)
|
||||
$curl -k $url --output $out
|
Loading…
Reference in New Issue
Block a user