Skip to content

Commit aa2b00f

Browse files
author
Hu Ji
committed
update scripts
1 parent ad80b53 commit aa2b00f

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/linktools_setup/setup.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
import abc
4+
import hashlib
45
import json
56
import logging
67
import os
@@ -206,26 +207,31 @@ def _parse_script(self, script):
206207
attr=script.get("object", self.const.default_script_attr)
207208
)
208209
elif "path" in script:
209-
yield from self._iter_module_scripts(
210-
path=script.get("path"),
211-
prefix=f"{script.get("module").rstrip(".")}.",
212-
object=script.get("object", self.const.default_script_object),
213-
attr=script.get("object", self.const.default_script_attr),
214-
)
210+
module = script.get("module").rstrip(".")
211+
path = script.get("path")
212+
root_path = os.path.join(path, "__init__.py")
213+
if os.path.exists(root_path):
214+
m = hashlib.md5()
215+
m.update(root_path.encode())
216+
yield ModuleEntryPoint(
217+
name=f"module-{m.hexdigest()}",
218+
module=module,
219+
)
220+
yield from self._iter_module_scripts(
221+
path=script.get("path"),
222+
prefix=f"{module}.",
223+
object=script.get("object", self.const.default_script_object),
224+
attr=script.get("object", self.const.default_script_attr),
225+
)
215226

216227
def _iter_module_scripts(self, path, prefix, object, attr, parents=None):
217228
for module_info in pkgutil.iter_modules([path]):
218229
if module_info.ispkg:
219230
spec = module_info.module_finder.find_spec(module_info.name)
220231
module = module_from_spec(spec)
221232
spec.loader.exec_module(module)
222-
name = getattr(module, self.const.module_command_key, module_info.name)
223233
items = list(parents or [])
224234
items.append(getattr(module, self.const.module_command_key, module_info.name))
225-
yield ModuleEntryPoint(
226-
name=name,
227-
module=f"{prefix}{module_info.name}",
228-
)
229235
yield from self._iter_module_scripts(
230236
path=os.path.join(path, module_info.name),
231237
prefix=f"{prefix}{module_info.name}.",
@@ -273,8 +279,8 @@ def finalize_distribution_options(dist: setuptools.Distribution) -> None:
273279

274280
scripts = [{
275281
"path": os.path.expanduser("~/Projects/linktools/src/linktools/cli/commands"),
276-
"module": "linktools.cli.commands.common",
282+
"module": "linktools.cli.commands",
277283
}]
278284
print([ep.as_script() for ep in context._parse_scripts(scripts)])
279-
print([ep.as_script() for ep in context._parse_scripts(scripts) if isinstance(ep, ScriptEntryPoint)])
280-
print([ep.as_script() for ep in context._parse_scripts(scripts) if not isinstance(ep, SubScriptEntryPoint)])
285+
# print([ep.as_script() for ep in context._parse_scripts(scripts) if isinstance(ep, ScriptEntryPoint)])
286+
# print([ep.as_script() for ep in context._parse_scripts(scripts) if not isinstance(ep, SubScriptEntryPoint)])

0 commit comments

Comments
 (0)