add drv generator to extractor

This commit is contained in:
DavHau 2021-04-21 00:51:11 +07:00
parent 8652cf9da3
commit 67238320a7
2 changed files with 26 additions and 13 deletions

View file

@ -8,9 +8,9 @@
python37
python38
]),
limitPythonVersions ? [],
...
}:
with builtins;
with lib;
let
commit = "1434cc0ee2da462f0c719d3a4c0ab4c87d0931e7";
@ -97,7 +97,7 @@ let
f.close();
exec(compile(code, __file__, 'exec'))
'';
script = ''
script = pyVersions: ''
mkdir $out
${concatStringsSep "\n" (forEach pythonInterpreters (interpreter:
let
@ -107,7 +107,7 @@ let
minor = elemAt verSplit 1;
v = "${major}${minor}";
# only use selected interpreters
in optionalString (limitPythonVerions == [] || elem v limitPythonVerions) ''
in optionalString (pyVersions == [] || elem v pyVersions) ''
echo "extracting metadata for python${v}"
out_file=$out/python${v}.json ${py}/bin/python -c "${setuptools_shim}" install &> $out/python${v}.log || true
''
@ -118,14 +118,14 @@ let
echo "extracting dependencies"
out_file=$out/python.json ${py}/bin/python -c "${setuptools_shim}" install &> $out/python.log || true
'';
base_derivation = with pkgs; {
base_derivation = pyVersions: with pkgs; {
buildInputs = [ unzip pkg-config pipenv ];
phases = ["unpackPhase" "installPhase"];
# Tells our modified python builtins to dump setup attributes instead of doing an actual installation
dump_setup_attrs = "y";
PYTHONIOENCODING = "utf8"; # My gut feeling is that encoding issues might decrease by this
LANG = "C.utf8";
installPhase = script;
installPhase = script pyVersions;
};
in
with pkgs;
@ -133,21 +133,33 @@ rec {
inherit machnix_source pythonInterpreters;
example = extractor {pkg = "requests"; version = "2.22.0";};
extract_from_src = {py, src}:
stdenv.mkDerivation ( base_derivation // {
stdenv.mkDerivation ( (base_derivation []) // {
inherit src;
name = "package-requirements";
installPhase = script_single (mkPy py);
});
extractor = {pkg, version}:
extractor = {pkg, version, ...}:
stdenv.mkDerivation ({
name = "${pkg}-${version}-requirements";
src = fetchPypi pkg version;
} // base_derivation);
extractor-fast = {pkg, version, url, sha256}:
stdenv.mkDerivation ({
} // (base_derivation []));
extractor-fast = {pkg, version, url, sha256, pyVersions ? [], ...}:
stdenv.mkDerivation ( rec {
name = "${pkg}-${version}-requirements";
src = pkgs.fetchurl {
src = (pkgs.fetchurl {
inherit url sha256;
};
} // base_derivation);
}).overrideAttrs (_: {
name = replaceStrings [" "] [""] _.name;
});
} // (base_derivation pyVersions));
make-drvs =
let
jobs = fromJSON (readFile (getEnv "EXTRACTOR_JOBS_JSON_FILE"));
results = listToAttrs (map (job:
nameValuePair
"${job.pkg}#${job.version}"
(extractor-fast job).drvPath
) jobs);
in toJSON results;
}

View file

@ -0,0 +1 @@
(import ./default.nix {}).make-drvs