1 #!/usr/bin/env nix-shell
2 #!nix-shell -i python3 -p python3
13 with
open(os
.path
.join(os
.path
.dirname(__file__
), 'node-packages.json'), 'r+') as node_packages_json
:
14 packages
= json
.load(node_packages_json
)
16 while idx
< len(packages
):
17 if packages
[idx
] == attr
or (isinstance(packages
[idx
], collections
.abc
.Mapping
) and next(iter(packages
[idx
].keys())) == attr
):
22 node_packages_json
.seek(0)
23 for idx
, package
in enumerate(packages
):
25 node_packages_json
.write('[\n ')
27 node_packages_json
.write(', ')
28 json
.dump(package
, node_packages_json
)
29 node_packages_json
.write('\n')
30 node_packages_json
.write(']\n')
31 node_packages_json
.truncate()
33 with fileinput
.input(os
.path
.join(os
.path
.dirname(__file__
), 'node-packages.nix'), inplace
=1) as node_packages
:
34 safe_attr
= re
.escape(attr
)
36 for line
in node_packages
:
38 if re
.fullmatch(r
' \};\n', line
):
41 if re
.fullmatch(rf
' (?:{safe_attr}|"{safe_attr}") = nodeEnv\.buildNodePackage \{{\n', line
):
44 sys
.stdout
.write(line
)
46 with fileinput
.input(os
.path
.join(os
.path
.dirname(__file__
), 'main-programs.nix'), inplace
=1) as main_programs
:
47 safe_attr
= re
.escape(attr
)
48 for line
in main_programs
:
49 if not re
.fullmatch(rf
' "?{safe_attr}"? = ".*";\n', line
):
50 sys
.stdout
.write(line
)
52 with fileinput
.input(os
.path
.join(os
.path
.dirname(__file__
), 'overrides.nix'), inplace
=1) as overrides
:
53 safe_attr
= re
.escape(attr
)
55 for line
in overrides
:
57 if re
.fullmatch(r
' \}\)?;\n', line
):
60 if re
.fullmatch(rf
' (?:{safe_attr}|"{safe_attr}") = .* \{{\n', line
):
63 sys
.stdout
.write(line
)
66 if __name__
== '__main__':
69 parser
= argparse
.ArgumentParser(description
='Remove a given package from the node-packages.nix file')
70 parser
.add_argument('attr', help='The package attribute to remove')
71 args
= parser
.parse_args()