Skip to content

Commit

Permalink
Merge pull request #568 from TyberiusPrime/rename_package_requirements
Browse files Browse the repository at this point in the history
Rename store paths for package-requirements-from-source
  • Loading branch information
DavHau committed Jul 11, 2023
2 parents fe56963 + 72b4f87 commit 725aab8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
in (import ./lib/extractor {}).extract_from_src {
py="python3";
src = srcTar;
name = "mach-nix";
}'
cat reqs/*
rm reqs
Expand Down
4 changes: 2 additions & 2 deletions lib/extractor/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ with pkgs;
rec {
inherit machnix_source mkPy pythonInterpreters;
example = extractor {pkg = "requests"; version = "2.22.0";};
extract_from_src = {py, src}:
extract_from_src = {py, src, name}:
let
py' = if isString py then pkgs."${py}" else py;
in
stdenv.mkDerivation ( (base_derivation []) // {
inherit src;
name = "package-requirements";
name = "${name}-mach-nix-requirements";
installPhase = script_single (mkPy py');
});
extractor = {pkg, version, ...}:
Expand Down
2 changes: 1 addition & 1 deletion mach_nix/nix/buildPythonPackage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ let
in
output_version
);
meta_reqs = l.extract_requirements python_pkg src "${pname}:${version}" extras;
meta_reqs = l.extract_requirements python_pkg src "${pname}-${version}" extras;
reqs =
(if requirements == "" then
if builtins.hasAttr "format" args && args.format != "setuptools" then
Expand Down
16 changes: 11 additions & 5 deletions mach_nix/nix/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,27 @@ rec {
in
condition { prov = provider; ver = oa.version; pyver = oa.passthru.pythonModule.version; };

extract = python: src: fail_msg:
extract = {python, src, fail_msg, name}:
let
file_path = "${(import ../../lib/extractor { inherit pkgs; }).extract_from_src {
py = python;
src = src;
name = name;
}}/python.json";
in
if pathExists file_path then fromJSON (builtins.unsafeDiscardStringContext (readFile file_path)) else throw fail_msg;

extract_requirements = python: src: name: extras:
let
ensureList = requires: if isString requires then [requires] else requires;
data = extract python src ''
data = extract {
python=python;
src = src;
fail_msg = ''
Automatic requirements extraction failed for ${name}.
Please manually specify 'requirements' '';
Please manually specify 'requirements' '';
name = name;
};
setup_requires = if hasAttr "setup_requires" data then ensureList data.setup_requires else [];
install_requires = if hasAttr "install_requires" data then ensureList data.install_requires else [];
extras_require =
Expand All @@ -226,7 +232,7 @@ rec {
error_msg = ''
Automatic extraction of '${for_attr}' from python package source ${src} failed.
Please manually specify '${for_attr}' '';
data = extract python src error_msg;
data = extract {python=python; src =src; fail_msg= error_msg; name = for_attr; };
result = if hasAttr attr data then data."${attr}" else throw error_msg;
msg = "\n automatically detected ${for_attr}: '${result}'";
in
Expand Down Expand Up @@ -262,7 +268,7 @@ rec {
{
"${pkg}" = pySuper."${pkg}".overrideAttrs (oa:
mapAttrs (key: val:
trace "\napplying fix '${fix}' (${key}) for ${pkg}:${oa.version}\n" (
trace "\napplying fix '${fix}' (${key}) for ${pkg}-${oa.version}\n" (
if isAttrs val && hasAttr "add" val then
combine pkg key (oa."${key}" or null) val.add
else if isAttrs val && hasAttr "mod" val && isFunction val.mod then
Expand Down

0 comments on commit 725aab8

Please sign in to comment.