Skip to content

Commit 5631bfd

Browse files
committed
Use pyproject package name if it is defined
1 parent 4a8f949 commit 5631bfd

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

python/lsst/sconsUtils/builders.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -650,11 +650,25 @@ def PackageInfo(self, pythonDir, versionString=None):
650650
if not os.path.exists(pythonDir):
651651
return
652652

653-
if os.path.exists(os.path.join(pythonDir, "lsst")):
654-
pythonPackageName = "lsst_" + state.env["packageName"]
653+
# Some information can come from the pyproject file.
654+
toml_metadata = {}
655+
if os.path.exists("pyproject.toml"):
656+
import tomllib
657+
658+
with open("pyproject.toml", "rb") as fd:
659+
toml_metadata = tomllib.load(fd)
660+
661+
pythonPackageName = ""
662+
if "project" in toml_metadata and "name" in toml_metadata["project"]:
663+
pythonPackageName = toml_metadata["project"]["name"]
655664
else:
656-
pythonPackageName = state.env["packageName"]
657-
eggDir = os.path.join(pythonDir, f"{pythonPackageName}.dist-info")
665+
if os.path.exists(os.path.join(pythonDir, "lsst")):
666+
pythonPackageName = "lsst_" + state.env["packageName"]
667+
else:
668+
pythonPackageName = state.env["packageName"]
669+
pythonPackageName = pythonPackageName.replace("_", "-")
670+
# The directory name is required to use "_" instead of "-"
671+
eggDir = os.path.join(pythonDir, f"{pythonPackageName.replace('-', '_')}.dist-info")
658672
filename = os.path.join(eggDir, "METADATA")
659673
oldMd5 = _calcMd5(filename)
660674

@@ -681,14 +695,8 @@ def makePackageMetadata(target, source, env):
681695

682696
# Create the entry points file if defined in the pyproject.toml file.
683697
entryPoints = {}
684-
if os.path.exists("pyproject.toml"):
685-
import tomllib
686-
687-
with open("pyproject.toml", "rb") as fd:
688-
metadata = tomllib.load(fd)
689-
690-
if "project" in metadata and "entry-points" in metadata["project"]:
691-
entryPoints = metadata["project"]["entry-points"]
698+
if "project" in toml_metadata and "entry-points" in toml_metadata["project"]:
699+
entryPoints = toml_metadata["project"]["entry-points"]
692700

693701
if entryPoints:
694702
filename = os.path.join(eggDir, "entry_points.txt")

0 commit comments

Comments
 (0)