···
#!nix-shell update-luarocks-shell.nix -i python3
5
-
# $ nix run nixpkgs.python3Packages.black -c black update.py
5
+
# $ nix run nixpkgs#python3Packages.black -- update.py
7
-
# $ nix run nixpkgs.python3Packages.mypy -c mypy update.py
7
+
# $ nix run nixpkgs#python3Packages.mypy -- update.py
9
-
# $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265,E402 update.py
9
+
# $ nix run nixpkgs#python3Packages.flake8 -- --ignore E501,E265,E402 update.py
···
log = logging.getLogger()
log.addHandler(logging.StreamHandler())
28
-
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))).parent.parent # type: ignore
28
+
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))).parent.parent # type: ignore
from pluginupdate import update_plugins, FetchConfig, CleanEnvironment
32
-
PKG_LIST="maintainers/scripts/luarocks-packages.csv"
33
-
TMP_FILE="$(mktemp)"
34
-
GENERATED_NIXFILE="pkgs/development/lua-modules/generated-packages.nix"
35
-
LUAROCKS_CONFIG="maintainers/scripts/luarocks-config.lua"
32
+
PKG_LIST = "maintainers/scripts/luarocks-packages.csv"
33
+
TMP_FILE = "$(mktemp)"
34
+
GENERATED_NIXFILE = "pkgs/development/lua-modules/generated-packages.nix"
35
+
LUAROCKS_CONFIG = "maintainers/scripts/luarocks-config.lua"
HEADER = """/* {GENERATED_NIXFILE} is an auto-generated file -- DO NOT EDIT!
···
You can customize the generated packages in pkgs/development/lua-modules/overrides.nix
43
-
""".format(GENERATED_NIXFILE=GENERATED_NIXFILE)
44
+
GENERATED_NIXFILE=GENERATED_NIXFILE
/* GENERATED - do not edit this file */
53
-
'''Name of the plugin, as seen on luarocks.org'''
56
+
"""Name of the plugin, as seen on luarocks.org"""
55
-
'''address to the git repository'''
58
+
"""address to the git repository"""
57
-
'''git reference (branch name/tag)'''
60
+
"""git reference (branch name/tag)"""
59
-
'''Set it to pin a package '''
62
+
"""Set it to pin a package """
61
-
'''luarocks.org registers packages under different manifests.
64
+
"""luarocks.org registers packages under different manifests.
Its value can be 'http://luarocks.org/dev'
luaversion: Optional[str]
65
-
'''Attribue of the lua interpreter if a package is available only for a specific lua version'''
68
+
"""Attribue of the lua interpreter if a package is available only for a specific lua version"""
maintainers: Optional[str]
67
-
''' Optional string listing maintainers separated by spaces'''
70
+
""" Optional string listing maintainers separated by spaces"""
def normalized_name(self) -> str:
return self.name.replace(".", "-")
# rename Editor to LangUpdate/ EcosystemUpdater
class LuaEditor(pluginupdate.Editor):
···
def load_plugin_spec(self, input_file) -> List[LuaPlugin]:
80
-
csvfilename=input_file
84
+
csvfilename = input_file
log.info("Loading package descriptions from %s", csvfilename)
83
-
with open(csvfilename, newline='') as csvfile:
84
-
reader = csv.DictReader(csvfile,)
87
+
with open(csvfilename, newline="") as csvfile:
88
+
reader = csv.DictReader(
# name,server,version,luaversion,maintainers
plugin = LuaPlugin(**row)
···
update_plugins(self, args)
96
-
results: List[Tuple[LuaPlugin, str]],
100
+
def generate_nix(self, results: List[Tuple[LuaPlugin, str]], outfilename: str):
with tempfile.NamedTemporaryFile("w+") as f:
header2 = textwrap.dedent(
103
-
# header2 = inspect.cleandoc(
104
+
# header2 = inspect.cleandoc(
{ self, stdenv, lib, fetchurl, fetchgit, callPackage, ... } @ args:
110
-
for (plugin, nix_expr) in results:
112
+
for plugin, nix_expr in results:
f.write(f"{plugin.normalized_name} = {nix_expr}")
···
# luaPackages.append(plugin)
def generate_pkg_nix(plug: LuaPlugin):
Generate nix expression for a luarocks package
Our cache key associates "p.name-p.version" to its rockspec
log.debug("Generating nix expression for %s", plug.name)
custom_env = os.environ.copy()
166
-
custom_env['LUAROCKS_CONFIG'] = LUAROCKS_CONFIG
169
+
custom_env["LUAROCKS_CONFIG"] = LUAROCKS_CONFIG
# we add --dev else luarocks wont find all the "scm" (=dev) versions of the
171
-
cmd = [ "luarocks", "nix" ]
174
+
cmd = ["luarocks", "nix"]
cmd.append(f"--maintainers={plug.maintainers}")
···
# if plug.server == "src":
179
-
msg = "src must be set when 'version' is set to \"src\" for package %s" % plug.name
183
+
"src must be set when 'version' is set to \"src\" for package %s"
log.debug("Updating from source %s", plug.src)
···
if plug.version and plug.version != "src":
if plug.server != "src" and plug.server:
···
cmd.append(f"--lua-version={plug.luaversion}")
197
-
log.debug("running %s", ' '.join(cmd))
202
+
log.debug("running %s", " ".join(cmd))
output = subprocess.check_output(cmd, env=custom_env, text=True)
output = "callPackage(" + output.strip() + ") {};\n\n"
205
-
editor = LuaEditor("lua", ROOT, '',
206
-
default_in = ROOT.joinpath(PKG_LIST),
207
-
default_out = ROOT.joinpath(GENERATED_NIXFILE)
210
+
editor = LuaEditor(
214
+
default_in=ROOT.joinpath(PKG_LIST),
215
+
default_out=ROOT.joinpath(GENERATED_NIXFILE),
212
-
if __name__ == "__main__":
221
+
if __name__ == "__main__":
# vim: set ft=python noet fdm=manual fenc=utf-8 ff=unix sts=0 sw=4 ts=4 :