Skip to content

Commit

Permalink
Allow syntax errors to propagate
Browse files Browse the repository at this point in the history
  • Loading branch information
twm committed Jul 29, 2024
1 parent 3d2cdb1 commit a559f5c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/incremental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def _get_setuptools_version(dist): # type: (_Distribution) -> None

try:
version = _existing_version(config.version_path)
except Exception:
except FileNotFoundError:
return

dist.metadata.version = version.public()
Expand Down Expand Up @@ -480,7 +480,7 @@ class _IncrementalConfig:
"""Path to the package root"""

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

Expand Down
47 changes: 40 additions & 7 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from subprocess import run
from tempfile import TemporaryDirectory

from build import ProjectBuilder
from build import ProjectBuilder, BuildBackendException
from build.env import DefaultIsolatedEnv
from twisted.python.filepath import FilePath
from twisted.trial.unittest import TestCase
Expand Down Expand Up @@ -116,10 +116,44 @@ def test_setuptools_no_package(self):

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

def test_setuptools_missing_versionpy(self):
"""
The setuptools plugin is a no-op when the ``_version.py`` file
isn't present.
"""
src = FilePath(self.mktemp())
src.makedirs()
src.child("setup.py").setContent(
b"""\
from setuptools import setup
setup(
name="example_missing_versionpy",
version="0.0.1",
packages=["example_missing_versionpy"],
zip_safe=False,
)
"""
)
src.child("pyproject.toml").setContent(
b"""\
[tool.incremental]
name = "example_missing_versionpy"
"""
)
package_dir = src.child("example_missing_versionpy")
package_dir.makedirs()
package_dir.child("__init__.py").setContent(b"")
# No _version.py exists

build_and_install(src)

# The version from setup.py wins.
self.assertEqual(metadata.version("example_missing_versionpy"), "0.0.1")

def test_setuptools_bad_versionpy(self):
"""
The setuptools plugin is a no-op when reading the version
from ``_version.py`` fails.
The setuptools plugin surfaces syntax errors in ``_version.py``.
"""
src = FilePath(self.mktemp())
src.makedirs()
Expand All @@ -145,10 +179,9 @@ def test_setuptools_bad_versionpy(self):
package_dir.makedirs()
package_dir.child("_version.py").setContent(b"bad version.py")

build_and_install(src)

# The version from setup.py wins.
self.assertEqual(metadata.version("example_bad_versionpy"), "0.1.2")
with self.assertRaises(BuildBackendException):
# This also spews a SyntaxError traceback to stdout.
build_and_install(src)

def test_hatchling_get_version(self):
"""
Expand Down

0 comments on commit a559f5c

Please sign in to comment.