mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-08-17 02:10:31 +03:00
improve translators:
- translator flags - translatedBy - translatorParams
This commit is contained in:
parent
d23fb76ef6
commit
aa7902a09e
@ -163,9 +163,6 @@ Potery uses `pyproject.toml` and `poetry.lock` to lock dependencies
|
||||
// this indicates which builder must be used
|
||||
"buildSystem": "python",
|
||||
|
||||
// versioning the format to ensure builder compatibility
|
||||
"buildSystemFormatVersion": 1,
|
||||
|
||||
// translator which generated this file
|
||||
// (not relevant for building)
|
||||
"producedBy": "translator-poetry-1",
|
||||
|
@ -14,9 +14,9 @@
|
||||
|
||||
"generic": {
|
||||
"buildSystem": "python",
|
||||
"buildSystemFormatVersion": 1,
|
||||
"producedBy": "translator-poetry-1",
|
||||
"rootPackage": "requests",
|
||||
"translatedBy": "python.pure.poetry",
|
||||
"translatorParams": "--flag_application",
|
||||
"mainPackage": "requests",
|
||||
"dependencyGraph": {
|
||||
"requests": [
|
||||
"certifi"
|
||||
|
@ -74,7 +74,6 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"buildSystem": { "type": "string" },
|
||||
"buildSystemFormatVersion": { "type": "integer" },
|
||||
"producedBy": { "type": "string" },
|
||||
"dependencyGraph": {
|
||||
"type": "object",
|
||||
|
@ -16,6 +16,11 @@ def strip_hashes_from_lock(lock):
|
||||
del source['hash']
|
||||
|
||||
|
||||
def order_dict(d):
|
||||
return {k: order_dict(v) if isinstance(v, dict) else v
|
||||
for k, v in sorted(d.items())}
|
||||
|
||||
|
||||
def list_translators(args):
|
||||
out = "Available translators per build system"
|
||||
for subsystem, trans_types in translators.items():
|
||||
@ -30,11 +35,20 @@ def list_translators(args):
|
||||
f"\n special args:",
|
||||
)
|
||||
for argName, argData in translator.items():
|
||||
lines += (
|
||||
f"\n --arg_{argName} {{value}}",
|
||||
f"\n default: {argData['default']}",
|
||||
f"\n examples: {', '.join(argData['examples'])}",
|
||||
)
|
||||
if argData['type'] == 'argument':
|
||||
lines += (
|
||||
f"\n --arg_{argName} {{value}}",
|
||||
f"\n description: {argData['description']}",
|
||||
f"\n default: {argData['default']}",
|
||||
f"\n examples: {', '.join(argData['examples'])}",
|
||||
)
|
||||
elif argData['type'] == 'flag':
|
||||
lines += (
|
||||
f"\n --flag_{argName}",
|
||||
f"\n description: {argData['description']}",
|
||||
)
|
||||
else:
|
||||
raise Exception(f"Unknown type '{argData['type']}' of argument '{arg_Name}'")
|
||||
displayed.append(''.join(lines))
|
||||
nl = '\n'
|
||||
out += f"\n\n - {subsystem}.{f'{nl} - {subsystem}.'.join(displayed)}"
|
||||
@ -52,6 +66,8 @@ def translate(args):
|
||||
for argName, argVal in vars(args).items():
|
||||
if argName.startswith("arg_"):
|
||||
specialArgs[argName[4:]] = argVal
|
||||
elif argName.startswith("flag_"):
|
||||
specialArgs[argName[5:]] = True
|
||||
|
||||
# check if all inputs exist
|
||||
for path in inputPaths:
|
||||
@ -141,8 +157,12 @@ def translate(args):
|
||||
# read produced lock file
|
||||
with open(output) as f:
|
||||
lock = json.load(f)
|
||||
|
||||
# write translator information to lock file
|
||||
lock['generic']['translatedBy'] = f"{subsystem}.{trans_type}.{trans_name}"
|
||||
lock['generic']['translatorParams'] = " ".join(sys.argv[2:])
|
||||
|
||||
# calculate combined hash
|
||||
# calculate combined hash if --combined was specified
|
||||
if args.combined:
|
||||
|
||||
print("Building FOD of combined sources to retrieve output hash")
|
||||
@ -174,7 +194,7 @@ def translate(args):
|
||||
# store the hash in the lock
|
||||
lock['generic']['sourcesCombinedHash'] = hash
|
||||
with open(output, 'w') as f:
|
||||
json.dump(lock, f, indent=2)
|
||||
json.dump(order_dict(lock), f, indent=2)
|
||||
|
||||
|
||||
print(f"Created {output}")
|
||||
@ -241,6 +261,8 @@ def parse_args():
|
||||
for arg in unknown:
|
||||
if arg.startswith("--arg_"):
|
||||
translate_parser.add_argument(arg.split('=')[0])
|
||||
if arg.startswith("--flag_"):
|
||||
translate_parser.add_argument(arg.split('=')[0], action='store_true')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -20,6 +20,7 @@ let
|
||||
externals = {
|
||||
npmlock2nix = pkgs.callPackage "${externalSources}/npmlock2nix/internal.nix" {};
|
||||
};
|
||||
|
||||
in
|
||||
|
||||
rec {
|
||||
|
@ -171,7 +171,12 @@ let
|
||||
data = {
|
||||
SpecialArgsDefaults =
|
||||
lib.mapAttrs
|
||||
(name: def: def.default)
|
||||
(name: def:
|
||||
if def.type == "flag" then
|
||||
false
|
||||
else
|
||||
def.default
|
||||
)
|
||||
translator.specialArgs or {};
|
||||
inherit (translator) subsystem type name;
|
||||
};
|
||||
|
@ -26,8 +26,8 @@
|
||||
|
||||
generic = {
|
||||
buildSystem = "nodejs";
|
||||
buildSystemFormatVersion = 1;
|
||||
producedBy = translatorName;
|
||||
mainPackage = null;
|
||||
dependencyGraph = null;
|
||||
sourcesCombinedHash = null;
|
||||
};
|
||||
|
@ -46,7 +46,7 @@
|
||||
-r ''${inputFiles/$'\n'/$' -r '}
|
||||
|
||||
# generate the generic lock from the downloaded list of files
|
||||
$tmpBuild/python/bin/python ${./generate-generic-lock.py} $tmp $outputFile
|
||||
$tmpBuild/python/bin/python ${./generate-generic-lock.py} $tmp $jsonInput
|
||||
|
||||
rm -rf $tmp $tmpBuild
|
||||
'';
|
||||
@ -75,6 +75,22 @@
|
||||
"python39"
|
||||
"python310"
|
||||
];
|
||||
type = "argument";
|
||||
};
|
||||
|
||||
main = {
|
||||
default = "";
|
||||
description = "name of the main package";
|
||||
examples = [
|
||||
"some-package"
|
||||
];
|
||||
type = "argument";
|
||||
};
|
||||
|
||||
application = {
|
||||
description = "build application instead of package";
|
||||
type = "flag";
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import sys
|
||||
|
||||
def main():
|
||||
directory = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
|
||||
with open(sys.argv[2]) as f:
|
||||
jsonInput = json.load(f)
|
||||
|
||||
packages = {}
|
||||
|
||||
@ -46,8 +48,7 @@ def main():
|
||||
sources={},
|
||||
generic={
|
||||
"buildSystem": "python",
|
||||
"buildSystemFormatVersion": 1,
|
||||
"producedBy": "external-pip",
|
||||
"mainPackage": None,
|
||||
|
||||
# This translator is not aware of the exact dependency graph.
|
||||
# This restricts us to use a single derivation builder later,
|
||||
@ -57,6 +58,8 @@ def main():
|
||||
"sourcesCombinedHash": None,
|
||||
},
|
||||
buildSystem={
|
||||
"main": jsonInput['main'],
|
||||
"application": jsonInput['application'],
|
||||
"pythonAttr": f"python{sys.version_info.major}{sys.version_info.minor}",
|
||||
"sourceFormats":
|
||||
{pname: data['format'] for pname, data in packages.items()}
|
||||
@ -72,7 +75,8 @@ def main():
|
||||
)
|
||||
|
||||
# dump generic lock to stdout (json)
|
||||
with open(output_file, 'w') as lock:
|
||||
print(jsonInput['outputFile'])
|
||||
with open(jsonInput['outputFile'], 'w') as lock:
|
||||
json.dump(generic_lock, lock, indent=2)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user