Skip to content

Commit 3f78430

Browse files
committed
single function
1 parent 645fd0f commit 3f78430

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

.github/actions/tox/install_packages.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -110,50 +110,42 @@ def get_envlist(tox_config: RawConfigParser) -> list[str]:
110110
return envlist
111111

112112

113-
def from_setupcfg(path: str) -> Optional[str]:
114-
"""Read package name from setup.cfg file.
113+
def read_package_name(path: str, tox_py: str) -> Optional[str]:
114+
"""Read package name from from setup.cfg or by running setup.py.
115115
116116
:param path: the location of the python package
117+
:param tox_py: python executable using to test setup.py
117118
:returns: A python package name
118119
"""
119120
setup_cfg = os.path.join(path, "setup.cfg")
120-
if not os.path.exists(setup_cfg):
121+
name = None
122+
if os.path.exists(setup_cfg):
123+
config = ConfigParser()
124+
config.read(setup_cfg)
125+
try:
126+
name = config.get("metadata", "name")
127+
except (NoSectionError, NoOptionError):
128+
# Some things have a setup.cfg, but don't keep
129+
# metadata in it; fall back to setup.py below
130+
logger.info("[metadata] name not found in %s, skipping", setup_cfg)
131+
else:
121132
logger.info("%s does not exist", setup_cfg)
122-
return None
123-
config = ConfigParser()
124-
config.read(setup_cfg)
125-
try:
126-
return config.get("metadata", "name")
127-
except (NoSectionError, NoOptionError):
128-
# Some things have a setup.cfg, but don't keep
129-
# metadata in it; fall back to setup.py below
130-
logger.info("[metadata] name not found in %s, skipping", setup_cfg)
131-
return None
132-
133-
134-
def from_setuppy(path: str, tox_py: str) -> Optional[str]:
135-
"""Read package name by executing setup.py.
136-
137-
:param path: the location of the python package
138-
:param tox_py: python executable using to test setup.py
139-
:returns: A python package name
140-
"""
141-
setup_py = os.path.join(path, "setup.py")
142-
if not os.path.exists(setup_py):
143-
logger.info("%s does not exist", setup_py)
144-
return None
145-
# It's a python package but doesn't use pbr, so we need to run
146-
# python setup.py --name to get setup.py to tell us what the
147-
# package name is.
148-
package_name = subprocess.check_output(
149-
[os.path.abspath(tox_py), "setup.py", "--name"],
150-
cwd=path,
151-
shell=True,
152-
stderr=subprocess.STDOUT,
153-
).decode("utf-8")
154-
if package_name:
155-
return package_name.strip()
156-
return None
133+
setup_py = os.path.join(path, "setup.py")
134+
if not os.path.exists(setup_py):
135+
logger.info("%s does not exist", setup_py)
136+
else:
137+
# It's a python package but doesn't use pbr, so we need to run
138+
# python setup.py --name to get setup.py to tell us what the
139+
# package name is.
140+
package_name = subprocess.check_output(
141+
[os.path.abspath(tox_py), "setup.py", "--name"],
142+
cwd=path,
143+
shell=True,
144+
stderr=subprocess.STDOUT,
145+
).decode("utf-8")
146+
if package_name:
147+
name = package_name.strip()
148+
return name
157149

158150

159151
def identify_packages(dirs: list[str], tox_py: str) -> dict[str, str]:
@@ -165,7 +157,7 @@ def identify_packages(dirs: list[str], tox_py: str) -> dict[str, str]:
165157
"""
166158
packages = {}
167159
for path in dirs:
168-
package_name = from_setupcfg(path) or from_setuppy(path, tox_py)
160+
package_name = read_package_name(path, tox_py)
169161
if not package_name:
170162
logger.info("Could not find package name for '%s'", path)
171163
else:

0 commit comments

Comments
 (0)