-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpyproject-gen.awk
More file actions
executable file
·40 lines (39 loc) · 1.37 KB
/
pyproject-gen.awk
File metadata and controls
executable file
·40 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/awk -f
BEGIN {
arrays["classifiers"] = "";
arrays["dependencies"] = "";
tables["project.optional-dependencies"] = "";
tables["project.scripts"] = "";
tables["project.urls"] = ""
getline version < "pyproject/version";
FS="\t"}
!$1 || /^#/ {next} # skip blank lines and comments
$1 == "unset-optional" {delete optional[$2]; next}
$1 == "same-version" {
$1 = "dependencies"
arrays[$1] = arrays[$1] "\n \"" $2 "~=" version "\","; next}
$1 == "optional" {
if (!($2 in optional)) {optional[$2] = "\"" $3 "\""}
else {optional[$2] = optional[$2] ",\n \"" $3 "\""}
next
}
$1 == "same-optional" {
if (!($2 in optional)) {optional[$2] = "\"" $3 "~=" version "\""}
else {optional[$2] = optional[$2] ",\n \"" $3 "~=" version "\""}
next
}
$1 in arrays {arrays[$1] = arrays[$1] "\n \"" $2 "\","; next}
$1 in tables {tables[$1] = tables[$1] "\n" $2; next}
$1 in metadata {
print "error: singular metadata", $1, "specified twice" | "cat 1>&2"; next}
{ metadata[$1] = $2}
END {
system("cat pyproject/preamble");
print "version = \"" version "\"";
for (j in metadata) print(j " = \"" metadata[j] "\"");
for (j in arrays) if (arrays[j]) print(j " = [" arrays[j] "\n]");
if (length(optional)) {
print "\n[project.optional-dependencies]";
for (j in optional) print j " = [" optional[j] "]";
}
for (j in tables) if (tables[j]) print("\n[" j "]" tables[j]);}