Skip to content

Commit a559f5c

Browse files
committed
Allow syntax errors to propagate
1 parent 3d2cdb1 commit a559f5c

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

src/incremental/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def _get_setuptools_version(dist): # type: (_Distribution) -> None
415415

416416
try:
417417
version = _existing_version(config.version_path)
418-
except Exception:
418+
except FileNotFoundError:
419419
return
420420

421421
dist.metadata.version = version.public()
@@ -480,7 +480,7 @@ class _IncrementalConfig:
480480
"""Path to the package root"""
481481

482482
@property
483-
def version_path(self): # type: () -> str
483+
def version_path(self): # type: () -> str
484484
"""Path of the ``_version.py`` file. May not exist."""
485485
return os.path.join(self.path, "_version.py")
486486

tests/test_examples.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from subprocess import run
1111
from tempfile import TemporaryDirectory
1212

13-
from build import ProjectBuilder
13+
from build import ProjectBuilder, BuildBackendException
1414
from build.env import DefaultIsolatedEnv
1515
from twisted.python.filepath import FilePath
1616
from twisted.trial.unittest import TestCase
@@ -116,10 +116,44 @@ def test_setuptools_no_package(self):
116116

117117
self.assertEqual(metadata.version("example_no_package"), "0.0.0")
118118

119+
def test_setuptools_missing_versionpy(self):
120+
"""
121+
The setuptools plugin is a no-op when the ``_version.py`` file
122+
isn't present.
123+
"""
124+
src = FilePath(self.mktemp())
125+
src.makedirs()
126+
src.child("setup.py").setContent(
127+
b"""\
128+
from setuptools import setup
129+
130+
setup(
131+
name="example_missing_versionpy",
132+
version="0.0.1",
133+
packages=["example_missing_versionpy"],
134+
zip_safe=False,
135+
)
136+
"""
137+
)
138+
src.child("pyproject.toml").setContent(
139+
b"""\
140+
[tool.incremental]
141+
name = "example_missing_versionpy"
142+
"""
143+
)
144+
package_dir = src.child("example_missing_versionpy")
145+
package_dir.makedirs()
146+
package_dir.child("__init__.py").setContent(b"")
147+
# No _version.py exists
148+
149+
build_and_install(src)
150+
151+
# The version from setup.py wins.
152+
self.assertEqual(metadata.version("example_missing_versionpy"), "0.0.1")
153+
119154
def test_setuptools_bad_versionpy(self):
120155
"""
121-
The setuptools plugin is a no-op when reading the version
122-
from ``_version.py`` fails.
156+
The setuptools plugin surfaces syntax errors in ``_version.py``.
123157
"""
124158
src = FilePath(self.mktemp())
125159
src.makedirs()
@@ -145,10 +179,9 @@ def test_setuptools_bad_versionpy(self):
145179
package_dir.makedirs()
146180
package_dir.child("_version.py").setContent(b"bad version.py")
147181

148-
build_and_install(src)
149-
150-
# The version from setup.py wins.
151-
self.assertEqual(metadata.version("example_bad_versionpy"), "0.1.2")
182+
with self.assertRaises(BuildBackendException):
183+
# This also spews a SyntaxError traceback to stdout.
184+
build_and_install(src)
152185

153186
def test_hatchling_get_version(self):
154187
"""

0 commit comments

Comments
 (0)