refactor: separate utils into own modules

This commit is contained in:
Yusuf Bera Ertan 2022-11-16 17:06:53 +03:00
parent f6ddebb846
commit 59870d0878
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
26 changed files with 143 additions and 77 deletions

View File

@ -263,7 +263,7 @@ in let
sourceOverrides ? oldSources: {}, sourceOverrides ? oldSources: {},
} @ args: let } @ args: let
# if dream lock is a file, read and parse it # if dream lock is a file, read and parse it
dreamLock' = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock; dreamLock' = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
fetcher = fetcher =
if args.fetcher or null == null if args.fetcher or null == null
@ -304,9 +304,9 @@ in let
allOutputs, allOutputs,
} @ args: let } @ args: let
# inject dependencies # inject dependencies
dreamLock = utils.dreamLock.injectDependencies args.dreamLock inject; dreamLock = utils.dream-lock.injectDependencies args.dreamLock inject;
dreamLockInterface = (utils.dreamLock.readDreamLock {inherit dreamLock;}).interface; dreamLockInterface = (utils.dream-lock.readDreamLock {inherit dreamLock;}).interface;
produceDerivation = name: pkg: produceDerivation = name: pkg:
utils.applyOverridesToPackage { utils.applyOverridesToPackage {
@ -337,7 +337,7 @@ in let
packageVersions packageVersions
; ;
getSource = utils.dreamLock.getSource fetchedSources; getSource = utils.dream-lock.getSource fetchedSources;
}); });
# Makes the packages tree compatible with flakes schema. # Makes the packages tree compatible with flakes schema.
@ -388,7 +388,7 @@ in let
packageOverrides ? {}, packageOverrides ? {},
} @ args: let } @ args: let
# parse dreamLock # parse dreamLock
dreamLockLoaded = utils.dreamLock.readDreamLock {inherit (args) dreamLock;}; dreamLockLoaded = utils.dream-lock.readDreamLock {inherit (args) dreamLock;};
dreamLock = dreamLockLoaded.lock; dreamLock = dreamLockLoaded.lock;
dreamLockInterface = dreamLockLoaded.interface; dreamLockInterface = dreamLockLoaded.interface;
@ -481,7 +481,7 @@ in let
project project
// rec { // rec {
dreamLock = dreamLock =
(utils.dreamLock.readDreamLock { (utils.dream-lock.readDreamLock {
dreamLock = "${toString config.projectRoot}/${project.dreamLockPath}"; dreamLock = "${toString config.projectRoot}/${project.dreamLockPath}";
}) })
.lock; .lock;

View File

@ -17,6 +17,7 @@
listDirs listDirs
listFiles listFiles
mergeFlakes mergeFlakes
mkFunction
nameVersionPair nameVersionPair
prepareSourceTree prepareSourceTree
readTextFile readTextFile
@ -335,5 +336,13 @@
licenses = l.filter (license: license != null) _licenses; licenses = l.filter (license: license != null) _licenses;
in in
licenses; licenses;
mkFunction = {type, ...} @ attrs:
l.mkOption (
attrs
// {
type = l.types.uniq (l.types.functionTo attrs.type);
}
);
in in
dlib dlib

View File

@ -52,7 +52,7 @@
# simpleTranslate2 puts dream-lock in result # simpleTranslate2 puts dream-lock in result
dreamLock = dreamLock'.result or dreamLock'; dreamLock = dreamLock'.result or dreamLock';
in in
dream2nix.framework.utils.dreamLock.toJSON dream2nix.framework.utils.dream-lock.toJSON
# don't use nix to detect cycles, this will be more efficient in python # don't use nix to detect cycles, this will be more efficient in python
(dreamLock // { (dreamLock // {
_generic = builtins.removeAttrs dreamLock._generic [ \"cyclicDependencies\" ]; _generic = builtins.removeAttrs dreamLock._generic [ \"cyclicDependencies\" ];

View File

@ -25,6 +25,11 @@ in {
./translators ./translators
./indexers ./indexers
./utils ./utils
./utils.translator
./utils.index
./utils.override
./utils.toTOML
./utils.dream-lock
]; ];
options = { options = {
lib = lib.mkOption { lib = lib.mkOption {

View File

@ -0,0 +1,6 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -6,7 +6,7 @@
dreamLock, dreamLock,
newSourceRoot, newSourceRoot,
} @ args: let } @ args: let
dreamLockLoaded = config.utils.dreamLock.readDreamLock {dreamLock = args.dreamLock;}; dreamLockLoaded = config.utils.dream-lock.readDreamLock {dreamLock = args.dreamLock;};
iface = dreamLockLoaded.interface; iface = dreamLockLoaded.interface;
patchVersion = version: source: patchVersion = version: source:
if if
@ -320,7 +320,7 @@
in in
json; json;
in { in {
config.utils.dreamLock = { config.utils.dream-lock = {
inherit inherit
compressDreamLock compressDreamLock
decompressDreamLock decompressDreamLock

View File

@ -0,0 +1,35 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
in {
options.utils.dream-lock = {
compressDreamLock = mkFunction {
type = t.attrs;
};
decompressDreamLock = mkFunction {
type = t.attrs;
};
getMainPackageSource = mkFunction {
type = t.attrs;
};
getSource = mkFunction {
type = t.functionTo (t.functionTo (t.either t.package t.path));
};
getSubDreamLock = mkFunction {
type = t.functionTo (t.functionTo t.attrs);
};
readDreamLock = mkFunction {
type = t.attrs;
};
replaceRootSources = mkFunction {
type = t.attrs;
};
injectDependencies = mkFunction {
type = t.functionTo t.attrs;
};
toJSON = mkFunction {
type = t.attrs;
};
};
}

View File

@ -0,0 +1,6 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -0,0 +1,14 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
generatePackagesFromLocksTree = mkFunction {
type = t.attrsOf t.package;
};
makeOutputsForIndexes = mkFunction {
type = t.attrs;
};
};
}

View File

@ -0,0 +1,6 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -0,0 +1,14 @@
{config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
applyOverridesToPackage = mkFunction {
type = t.attrs;
};
loadOverridesDirs = mkFunction {
type = t.attrs;
};
};
}

View File

@ -0,0 +1,6 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -0,0 +1,10 @@
{config, ...}: let
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
toTOML = config.dlib.mkFunction {
type = t.attrs;
};
};
}

View File

@ -0,0 +1,6 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -0,0 +1,10 @@
{config, ...}: let
l = config.lib // builtins;
t = l.types;
in {
options.utils = {
simpleTranslate = config.dlib.mkFunction {
type = t.functionTo t.attrs;
};
};
}

View File

@ -216,13 +216,6 @@
script // {passthru = {inherit project;};}; script // {passthru = {inherit project;};};
}; };
in { in {
imports = [
./dream-lock.nix
./override.nix
./translator.nix
./toTOML.nix
./index
];
config = { config = {
utils = impl; utils = impl;
}; };

View File

@ -1,14 +1,7 @@
{config, ...}: let {config, ...}: let
inherit (config.dlib) mkFunction;
l = config.lib // builtins; l = config.lib // builtins;
t = l.types; t = l.types;
mkFunction = {type, ...} @ attrs:
l.mkOption (
attrs
// {
type = t.uniq (t.functionTo attrs.type);
}
);
in { in {
options.utils = { options.utils = {
scripts = { scripts = {
@ -22,41 +15,9 @@ in {
type = t.path; type = t.path;
}; };
}; };
dreamLock = {
compressDreamLock = mkFunction {
type = t.attrs;
};
decompressDreamLock = mkFunction {
type = t.attrs;
};
getMainPackageSource = mkFunction {
type = t.attrs;
};
getSource = mkFunction {
type = t.functionTo (t.functionTo (t.either t.package t.path));
};
getSubDreamLock = mkFunction {
type = t.functionTo (t.functionTo t.attrs);
};
readDreamLock = mkFunction {
type = t.attrs;
};
replaceRootSources = mkFunction {
type = t.attrs;
};
injectDependencies = mkFunction {
type = t.functionTo t.attrs;
};
toJSON = mkFunction {
type = t.attrs;
};
};
toDrv = mkFunction { toDrv = mkFunction {
type = t.package; type = t.package;
}; };
toTOML = mkFunction {
type = t.str;
};
hashPath = mkFunction { hashPath = mkFunction {
type = t.functionTo t.str; type = t.functionTo t.str;
}; };
@ -78,20 +39,5 @@ in {
makeTranslateScript = mkFunction { makeTranslateScript = mkFunction {
type = t.package; type = t.package;
}; };
applyOverridesToPackage = mkFunction {
type = t.attrs;
};
loadOverridesDirs = mkFunction {
type = t.attrs;
};
simpleTranslate = mkFunction {
type = t.functionTo t.attrs;
};
generatePackagesFromLocksTree = mkFunction {
type = t.attrsOf t.package;
};
makeOutputsForIndexes = mkFunction {
type = t.attrs;
};
}; };
} }

View File

@ -68,4 +68,4 @@
}; };
}); });
in in
dream2nix.framework.utils.dreamLock.toJSON translated dream2nix.framework.utils.dream-lock.toJSON translated

View File

@ -12,12 +12,12 @@
}: let }: let
inherit (framework) utils fetchers; inherit (framework) utils fetchers;
lockUtils = utils.dreamLock; lockUtils = utils.dream-lock;
updaters = callPackageDream ./updaters.nix {}; updaters = callPackageDream ./updaters.nix {};
getUpdaterName = {dreamLock}: let getUpdaterName = {dreamLock}: let
lock = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock; lock = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
source = lockUtils.getMainPackageSource lock; source = lockUtils.getMainPackageSource lock;
in in
lock.updater lock.updater
@ -28,7 +28,7 @@
dreamLock, dreamLock,
updater ? getUpdaterName {inherit dreamLock;}, updater ? getUpdaterName {inherit dreamLock;},
}: let }: let
lock = (utils.dreamLock.readDreamLock {inherit dreamLock;}).lock; lock = (utils.dream-lock.readDreamLock {inherit dreamLock;}).lock;
source = lockUtils.getMainPackageSource lock; source = lockUtils.getMainPackageSource lock;
updater' = updaters."${updater}"; updater' = updaters."${updater}";
in in

View File

@ -26,7 +26,7 @@ exampleDreamLock = dict(
def test_dream_lock_inject(): def test_dream_lock_inject():
result = nix_ffi.callNixFunction( result = nix_ffi.callNixFunction(
'framework.utils.dreamLock.injectDependencies', 'framework.utils.dream-lock.injectDependencies',
dreamLock=exampleDreamLock, dreamLock=exampleDreamLock,
inject=dict( inject=dict(
example={ example={
@ -43,7 +43,7 @@ def test_dream_lock_inject():
def test_dream_lock_replace_root_sources(): def test_dream_lock_replace_root_sources():
result = nix_ffi.callNixFunction( result = nix_ffi.callNixFunction(
'framework.utils.dreamLock.replaceRootSources', 'framework.utils.dream-lock.replaceRootSources',
dreamLock=exampleDreamLock, dreamLock=exampleDreamLock,
newSourceRoot=dict( newSourceRoot=dict(
type = "http", type = "http",