mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-18 20:11:33 +03:00
refactor: source instead of inputDirectories/Files
This commit is contained in:
parent
b4fef5baf0
commit
02eb4a1cf4
@ -445,8 +445,7 @@ class AddCommand(Command):
|
||||
with tempfile.NamedTemporaryFile("r") as output_temp_file:
|
||||
# arguments for calling the translator nix module
|
||||
translator_input = dict(
|
||||
inputFiles=[],
|
||||
inputDirectories=[sourcePath],
|
||||
source=sourcePath,
|
||||
outputFile=output_temp_file.name,
|
||||
)
|
||||
translator_input.update(specified_extra_args)
|
||||
|
@ -51,7 +51,7 @@ def checkLockJSON(lock):
|
||||
def list_translators_for_source(sourcePath):
|
||||
translators_dict = callNixFunction(
|
||||
"translators.translatorsForInputRecursive",
|
||||
inputDirectories=[sourcePath],
|
||||
source=sourcePath,
|
||||
)
|
||||
for path, translators_list in translators_dict.copy().items():
|
||||
translators_dict[path] = \
|
||||
|
@ -226,8 +226,7 @@ let
|
||||
|
||||
dreamLock' = translators.translators."${t.subsystem}"."${t.type}"."${t.name}".translate
|
||||
(translatorArgs // {
|
||||
inputFiles = [];
|
||||
inputDirectories = [ source ];
|
||||
inherit source;
|
||||
});
|
||||
|
||||
dreamLock =
|
||||
|
@ -1,12 +1,5 @@
|
||||
{
|
||||
"inputDirectories": [
|
||||
"./some_project_src"
|
||||
],
|
||||
|
||||
"inputFiles": [
|
||||
"./a/b/c/requirements.txt",
|
||||
"./a/b/c/requirements-dev.txt"
|
||||
],
|
||||
"source": "./some_project_src",
|
||||
|
||||
"outputFile": [
|
||||
"./a/b/c/dream-lock.json"
|
||||
|
@ -1,13 +1,6 @@
|
||||
{
|
||||
# dream2nix utils
|
||||
utils,
|
||||
|
||||
# nixpkgs dependenies
|
||||
bash,
|
||||
jq,
|
||||
dlib,
|
||||
lib,
|
||||
writeScriptBin,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
@ -22,26 +15,37 @@
|
||||
# The program is expected to create a file at the location specified
|
||||
# by the input parameter `outFile`.
|
||||
# The output file must contain the dream lock data encoded as json.
|
||||
translateBin = utils.writePureShellScript
|
||||
[
|
||||
bash
|
||||
coreutils
|
||||
jq
|
||||
nix
|
||||
]
|
||||
''
|
||||
# accroding to the spec, the translator reads the input from a json file
|
||||
jsonInput=$1
|
||||
translateBin =
|
||||
{
|
||||
# dream2nix utils
|
||||
utils,
|
||||
|
||||
# read the json input
|
||||
outputFile=$(${jq}/bin/jq '.outputFile' -c -r $jsonInput)
|
||||
inputDirectories=$(${jq}/bin/jq '.inputDirectories | .[]' -c -r $jsonInput)
|
||||
inputFiles=$(${jq}/bin/jq '.inputFiles | .[]' -c -r $jsonInput)
|
||||
# nixpkgs dependenies
|
||||
bash,
|
||||
jq,
|
||||
writeScriptBin,
|
||||
...
|
||||
}:
|
||||
utils.writePureShellScript
|
||||
[
|
||||
bash
|
||||
coreutils
|
||||
jq
|
||||
nix
|
||||
]
|
||||
''
|
||||
# accroding to the spec, the translator reads the input from a json file
|
||||
jsonInput=$1
|
||||
|
||||
# TODO:
|
||||
# read input files/dirs and produce a json file at $outputFile
|
||||
# containing the dream lock similar to /specifications/dream-lock-example.json
|
||||
'';
|
||||
# read the json input
|
||||
outputFile=$(${jq}/bin/jq '.outputFile' -c -r $jsonInput)
|
||||
source=$(${jq}/bin/jq '.source' -c -r $jsonInput)
|
||||
inputFiles=$(${jq}/bin/jq '.inputFiles | .[]' -c -r $jsonInput)
|
||||
|
||||
# TODO:
|
||||
# read input files/dirs and produce a json file at $outputFile
|
||||
# containing the dream lock similar to /specifications/dream-lock-example.json
|
||||
'';
|
||||
|
||||
|
||||
# From a given list of paths, this function returns all paths which can be processed by this translator.
|
||||
@ -49,20 +53,18 @@
|
||||
# to automatically select the right translator.
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
# TODO: insert regex here that matches valid input file names
|
||||
# examples:
|
||||
# - ''.*requirements.*\.txt''
|
||||
# - ''.*package-lock\.json''
|
||||
inputDirectories = lib.filter
|
||||
(utils.containsMatchingFile [ ''TODO: regex1'' ''TODO: regex2'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [];
|
||||
};
|
||||
source,
|
||||
}:
|
||||
# TODO: insert regex here that matches valid input file names
|
||||
# examples:
|
||||
# - ''.*requirements.*\.txt''
|
||||
# - ''.*package-lock\.json''
|
||||
dlib.containsMatchingFile
|
||||
[
|
||||
''TODO: regex1''
|
||||
''TODO: regex2''
|
||||
]
|
||||
source;
|
||||
|
||||
|
||||
# If the translator requires additional arguments, specify them here.
|
||||
|
@ -1,18 +1,20 @@
|
||||
{
|
||||
dlib,
|
||||
lib,
|
||||
nodejs,
|
||||
|
||||
externals,
|
||||
translatorName,
|
||||
utils,
|
||||
...
|
||||
}:
|
||||
|
||||
{
|
||||
translate =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
nodejs,
|
||||
|
||||
externals,
|
||||
translatorName,
|
||||
utils,
|
||||
...
|
||||
}:
|
||||
{
|
||||
source,
|
||||
|
||||
# arguments specified by user
|
||||
noDev,
|
||||
@ -132,20 +134,18 @@
|
||||
# to automatically select the right translator.
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
source,
|
||||
}:
|
||||
# TODO: insert regex here that matches valid input file names
|
||||
# examples:
|
||||
# - ''.*requirements.*\.txt''
|
||||
# - ''.*package-lock\.json''
|
||||
inputDirectories = lib.filter
|
||||
(utils.containsMatchingFile [ ''TODO: regex1'' ''TODO: regex2'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [];
|
||||
};
|
||||
dlib.containsMatchingFile
|
||||
[
|
||||
''TODO: regex1''
|
||||
''TODO: regex2''
|
||||
]
|
||||
source;
|
||||
|
||||
|
||||
# If the translator requires additional arguments, specify them here.
|
||||
|
@ -134,9 +134,8 @@ let
|
||||
# if the translator is compatible to all given paths
|
||||
translatorsForInput =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
source,
|
||||
}:
|
||||
lib.forEach translatorsList
|
||||
(t: rec {
|
||||
inherit (t)
|
||||
@ -145,15 +144,14 @@ let
|
||||
subsystem
|
||||
type
|
||||
;
|
||||
compatiblePaths = t.compatiblePaths args;
|
||||
compatible = compatiblePaths == args;
|
||||
compatible = t.compatiblePaths { inherit source; };
|
||||
});
|
||||
|
||||
# also includes subdirectories of the given paths up to a certain depth
|
||||
# to check for translator compatibility
|
||||
translatorsForInputRecursive =
|
||||
{
|
||||
inputDirectories,
|
||||
source,
|
||||
depth ? 2,
|
||||
}:
|
||||
let
|
||||
@ -175,20 +173,19 @@ let
|
||||
subDirs));
|
||||
|
||||
dirsToCheck =
|
||||
inputDirectories
|
||||
[ source ]
|
||||
++
|
||||
(lib.flatten
|
||||
(map
|
||||
(inputDir: listDirsRec inputDir depth)
|
||||
inputDirectories));
|
||||
[ source ]));
|
||||
|
||||
in
|
||||
lib.genAttrs
|
||||
dirsToCheck
|
||||
(dir:
|
||||
translatorsForInput {
|
||||
inputDirectories = [ dir ];
|
||||
inputFiles = [];
|
||||
source = dir;
|
||||
}
|
||||
);
|
||||
|
||||
@ -213,8 +210,7 @@ let
|
||||
}@args:
|
||||
let
|
||||
translatorsForSource = translatorsForInput {
|
||||
inputFiles = [];
|
||||
inputDirectories = [ source ];
|
||||
inherit source;
|
||||
};
|
||||
|
||||
nameFilter =
|
||||
|
@ -33,11 +33,11 @@
|
||||
|
||||
# read the json input
|
||||
outputFile=$(${jq}/bin/jq '.outputFile' -c -r $jsonInput)
|
||||
inputDirectory=$(${jq}/bin/jq '.inputDirectories | .[0]' -c -r $jsonInput)
|
||||
source=$(${jq}/bin/jq '.source' -c -r $jsonInput)
|
||||
|
||||
tmpBuild=$(mktemp -d)
|
||||
cd $tmpBuild
|
||||
cp -r $inputDirectory/* .
|
||||
cp -r $source/* .
|
||||
chmod -R +w .
|
||||
# This should be in sync with gomod2nix version in flake.lock
|
||||
nix run github:tweag/gomod2nix/67f22dd738d092c6ba88e420350ada0ed4992ae8
|
||||
@ -51,16 +51,9 @@
|
||||
# to automatically select the right translator.
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
inputDirectories = lib.filter
|
||||
(dlib.containsMatchingFile [ ''go\.sum'' ''go\.mod'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [];
|
||||
};
|
||||
source,
|
||||
}:
|
||||
dlib.containsMatchingFile [ ''go\.sum'' ''go\.mod'' ] source;
|
||||
|
||||
|
||||
# If the translator requires additional arguments, specify them here.
|
||||
|
@ -35,11 +35,11 @@
|
||||
|
||||
# read the json input
|
||||
outputFile=$(jq '.outputFile' -c -r $jsonInput)
|
||||
inputDirectory=$(jq '.inputDirectories | .[0]' -c -r $jsonInput)
|
||||
source=$(jq '.source' -c -r $jsonInput)
|
||||
npmArgs=$(jq '.npmArgs' -c -r $jsonInput)
|
||||
# inputFiles=$(jq '.inputFiles | .[]' -c -r $jsonInput)
|
||||
|
||||
cp -r $inputDirectory/* ./
|
||||
cp -r $source/* ./
|
||||
chmod -R +w ./
|
||||
rm -rf package-lock.json
|
||||
cat ./package.json
|
||||
@ -55,7 +55,7 @@
|
||||
|
||||
cat package-lock.json
|
||||
|
||||
jq ".inputDirectories[0] = \"$(pwd)\"" -c -r $jsonInput > ./newJsonInput
|
||||
jq ".source = \"$(pwd)\"" -c -r $jsonInput > ./newJsonInput
|
||||
|
||||
${translators.translators.nodejs.pure.package-lock.translateBin} $(realpath ./newJsonInput)
|
||||
'';
|
||||
@ -66,16 +66,9 @@
|
||||
# to automatically select the right translator.
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
inputDirectories = lib.filter
|
||||
(dlib.containsMatchingFile [ ''.*package.json'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [];
|
||||
};
|
||||
source,
|
||||
}:
|
||||
dlib.containsMatchingFile [ ''.*package.json'' ] source;
|
||||
|
||||
# inherit options from package-lock translator
|
||||
extraArgs =
|
||||
|
@ -15,8 +15,7 @@ in
|
||||
...
|
||||
}:
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
source,
|
||||
|
||||
name,
|
||||
noDev,
|
||||
@ -29,13 +28,9 @@ in
|
||||
|
||||
dev = ! noDev;
|
||||
|
||||
inputDir = lib.elemAt inputDirectories 0;
|
||||
inputDir = source;
|
||||
|
||||
packageLock =
|
||||
if inputDirectories != [] then
|
||||
"${inputDir}/package-lock.json"
|
||||
else
|
||||
lib.elemAt inputFiles 0;
|
||||
packageLock = "${inputDir}/package-lock.json";
|
||||
|
||||
parsed = b.fromJSON (b.readFile packageLock);
|
||||
|
||||
@ -217,16 +212,14 @@ in
|
||||
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
inputDirectories = lib.filter
|
||||
(dlib.containsMatchingFile [ ''.*package-lock\.json'' ''.*package.json'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [];
|
||||
};
|
||||
source,
|
||||
}:
|
||||
dlib.containsMatchingFile
|
||||
[
|
||||
''.*package-lock\.json''
|
||||
''.*package.json''
|
||||
]
|
||||
source;
|
||||
|
||||
extraArgs = {
|
||||
|
||||
|
@ -13,8 +13,7 @@
|
||||
...
|
||||
}:
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
source,
|
||||
|
||||
# extraArgs
|
||||
name,
|
||||
@ -28,7 +27,7 @@
|
||||
b = builtins;
|
||||
dev = ! noDev;
|
||||
|
||||
sourceDir = lib.elemAt inputDirectories 0;
|
||||
sourceDir = source;
|
||||
yarnLock = utils.readTextFile "${sourceDir}/yarn.lock";
|
||||
packageJSON = b.fromJSON (b.readFile "${sourceDir}/package.json");
|
||||
parser = import ../yarn-lock/parser.nix
|
||||
@ -281,16 +280,9 @@
|
||||
# to automatically select the right translator.
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
inputDirectories = lib.filter
|
||||
(dlib.containsMatchingFile [ ''.*yarn\.lock'' ''.*package.json'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [];
|
||||
};
|
||||
source,
|
||||
}:
|
||||
dlib.containsMatchingFile [ ''.*yarn\.lock'' ''.*package.json'' ] source;
|
||||
|
||||
|
||||
# If the translator requires additional arguments, specify them here.
|
||||
|
@ -50,7 +50,7 @@ in
|
||||
|
||||
# read the json input
|
||||
outputFile=$(${jq}/bin/jq '.outputFile' -c -r $jsonInput)
|
||||
inputDirectory=$(${jq}/bin/jq '.inputDirectories | .[0]' -c -r $jsonInput)
|
||||
source=$(${jq}/bin/jq '.source' -c -r $jsonInput)
|
||||
pythonAttr=$(${jq}/bin/jq '.pythonAttr' -c -r $jsonInput)
|
||||
application=$(${jq}/bin/jq '.application' -c -r $jsonInput)
|
||||
|
||||
@ -70,7 +70,7 @@ in
|
||||
tmp=$(mktemp -d)
|
||||
|
||||
# extract python requirements from setup.py
|
||||
cp -r $inputDirectory $tmpBuild/src
|
||||
cp -r $source $tmpBuild/src
|
||||
chmod -R +w $tmpBuild/src
|
||||
cd $tmpBuild/src
|
||||
chmod +x setup.py || true
|
||||
@ -110,14 +110,13 @@ in
|
||||
# from a given list of paths, this function returns all paths which can be processed by this translator
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
inputDirectories = [];
|
||||
|
||||
inputFiles = lib.filter (f: builtins.match ''.*requirements.*\.txt'' f != null) args.inputFiles;
|
||||
};
|
||||
source,
|
||||
}:
|
||||
dlib.containsMatchingFile
|
||||
[
|
||||
''.*requirements.*\.txt''
|
||||
]
|
||||
source;
|
||||
|
||||
# define special args and provide defaults
|
||||
extraArgs = {
|
||||
|
@ -12,15 +12,14 @@
|
||||
...
|
||||
}:
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
|
||||
source,
|
||||
packageName,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
l = lib // builtins;
|
||||
|
||||
inputDir = l.elemAt inputDirectories 0;
|
||||
inputDir = source;
|
||||
|
||||
recurseFiles = path:
|
||||
l.flatten (
|
||||
@ -34,7 +33,7 @@
|
||||
);
|
||||
|
||||
# Find all Cargo.toml files and parse them
|
||||
allFiles = l.flatten (l.map recurseFiles inputDirectories);
|
||||
allFiles = l.flatten (l.map recurseFiles [ inputDir ]);
|
||||
cargoTomlPaths = l.filter (path: l.baseNameOf path == "Cargo.toml") allFiles;
|
||||
cargoTomls =
|
||||
l.map
|
||||
@ -248,16 +247,9 @@
|
||||
# to automatically select the right translator.
|
||||
compatiblePaths =
|
||||
{
|
||||
inputDirectories,
|
||||
inputFiles,
|
||||
}@args:
|
||||
{
|
||||
inputDirectories = lib.filter
|
||||
(dlib.containsMatchingFile [ ''.*Cargo\.lock'' ])
|
||||
args.inputDirectories;
|
||||
|
||||
inputFiles = [ ];
|
||||
};
|
||||
source,
|
||||
}:
|
||||
dlib.containsMatchingFile [ ''.*Cargo\.lock'' ] source;
|
||||
|
||||
|
||||
# If the translator requires additional arguments, specify them here.
|
||||
|
Loading…
Reference in New Issue
Block a user