Skip to content

Commit 4756c53

Browse files
committed
Write entry points definitions
1 parent c58fb99 commit 4756c53

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

python/lsst/sconsUtils/builders.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,52 @@ def makePackageInfo(target, source, env):
674674
if _calcMd5(target[0].abspath) != oldMd5: # only print if something's changed
675675
state.log.info(f'PackageInfo(["{target[0]}"], [])')
676676

677-
result = self.Command(filename, [], self.Action(makePackageInfo, strfunction=lambda *args: None))
677+
results = []
678+
results.append(self.Command(filename, [], self.Action(makePackageInfo, strfunction=lambda *args: None)))
678679

679-
self.AlwaysBuild(result)
680-
return result
680+
# Create the entry points file if defined in the pyproject.toml file.
681+
entryPoints = {}
682+
if os.path.exists("pyproject.toml"):
683+
import tomllib
684+
685+
with open("pyproject.toml", "rb") as fd:
686+
metadata = tomllib.load(fd)
687+
688+
if "project" in metadata and "entry-points" in metadata["project"]:
689+
entryPoints = metadata["project"]["entry-points"]
690+
691+
if entryPoints:
692+
filename = os.path.join(eggDir, "entry_points.txt")
693+
oldMd5 = _calcMd5(filename)
694+
695+
def makeEntryPoints(target, source, env):
696+
# Make the entry points file as necessary.
697+
if not entryPoints:
698+
return
699+
os.makedirs(os.path.dirname(target[0].abspath), exist_ok=True)
700+
701+
# Structure of entry points dict is something like:
702+
# "entry-points": {
703+
# "butler.cli": {
704+
# "pipe_base": "lsst.pipe.base.cli:get_cli_subcommands"
705+
# }
706+
# }
707+
# Which becomes a file with:
708+
# [butler.cli]
709+
# pipe_base = lsst.pipe.base.cli:get_cli_subcommands
710+
with open(target[0].abspath, "w") as fd:
711+
for entryGroup in entryPoints:
712+
print(f"[{entryGroup}]", file=fd)
713+
for entryPoint, entryValue in entryPoints[entryGroup].items():
714+
print(f"{entryPoint} = {entryValue}", file=fd)
715+
716+
if _calcMd5(target[0].abspath) != oldMd5: # only print if something's changed
717+
state.log.info(f'PackageInfo(["{target[0]}"], [])')
718+
719+
if entryPoints:
720+
results.append(
721+
self.Command(filename, [], self.Action(makeEntryPoints, strfunction=lambda *args: None))
722+
)
723+
724+
self.AlwaysBuild(results)
725+
return results

0 commit comments

Comments
 (0)