From 20e2ffd6b9660cc83a0ef7579439ea0e15804eec Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Thu, 18 Mar 2021 16:51:34 +0000
Subject: [PATCH 1/7] Validate the source directory passed to ProjectBuilder
---
src/build/__init__.py | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/build/__init__.py b/src/build/__init__.py
index 1c4eb716..90c9585c 100644
--- a/src/build/__init__.py
+++ b/src/build/__init__.py
@@ -59,6 +59,16 @@ class TypoWarning(Warning):
"""
+def _validate_source_directory(srcdir):
+ # type: (str) -> None
+ if not os.path.isdir(srcdir):
+ raise BuildException('Source {} is not a directory'.format(srcdir))
+ pyproject_toml = os.path.join(srcdir, "pyproject.toml")
+ setup_py = os.path.join(srcdir, "setup.py")
+ if not (os.path.exists(pyproject_toml) or os.path.exists(setup_py)):
+ raise BuildException('Source {} does not appear to be a Python project: no pyproject.toml or setup.py'.format(srcdir))
+
+
def check_dependency(req_string, ancestral_req_strings=(), parent_extras=frozenset()):
# type: (str, Tuple[str, ...], AbstractSet[str]) -> Iterator[Tuple[str, ...]]
"""
@@ -137,6 +147,7 @@ def __init__(self, srcdir, python_executable=sys.executable, scripts_dir=None):
:param python_executable: The python executable where the backend lives
"""
self.srcdir = os.path.abspath(srcdir) # type: str
+ _validate_source_directory(srcdir)
spec_file = os.path.join(srcdir, 'pyproject.toml')
From 2a12106307240249d14b688d05a1fd402fa027ba Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Thu, 18 Mar 2021 19:03:47 +0000
Subject: [PATCH 2/7] Lint fixes
---
src/build/__init__.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/build/__init__.py b/src/build/__init__.py
index 90c9585c..8eb62c52 100644
--- a/src/build/__init__.py
+++ b/src/build/__init__.py
@@ -63,8 +63,8 @@ def _validate_source_directory(srcdir):
# type: (str) -> None
if not os.path.isdir(srcdir):
raise BuildException('Source {} is not a directory'.format(srcdir))
- pyproject_toml = os.path.join(srcdir, "pyproject.toml")
- setup_py = os.path.join(srcdir, "setup.py")
+ pyproject_toml = os.path.join(srcdir, 'pyproject.toml')
+ setup_py = os.path.join(srcdir, 'setup.py')
if not (os.path.exists(pyproject_toml) or os.path.exists(setup_py)):
raise BuildException('Source {} does not appear to be a Python project: no pyproject.toml or setup.py'.format(srcdir))
From 8c37d99317c3ffd2c153fc0b2bb64c647b5a6c5a Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Thu, 18 Mar 2021 19:06:54 +0000
Subject: [PATCH 3/7] Rewrite test logic
---
src/build/__init__.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/build/__init__.py b/src/build/__init__.py
index 8eb62c52..10e5c9df 100644
--- a/src/build/__init__.py
+++ b/src/build/__init__.py
@@ -65,7 +65,7 @@ def _validate_source_directory(srcdir):
raise BuildException('Source {} is not a directory'.format(srcdir))
pyproject_toml = os.path.join(srcdir, 'pyproject.toml')
setup_py = os.path.join(srcdir, 'setup.py')
- if not (os.path.exists(pyproject_toml) or os.path.exists(setup_py)):
+ if not os.path.exists(pyproject_toml) and not os.path.exists(setup_py):
raise BuildException('Source {} does not appear to be a Python project: no pyproject.toml or setup.py'.format(srcdir))
From f027d234165caf0422b0c140a2e784febf5f8fad Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Thu, 18 Mar 2021 22:55:13 +0000
Subject: [PATCH 4/7] Add tests for the new functionality
---
tests/conftest.py | 5 +++++
tests/packages/test-no-project/empty.txt | 0
tests/test_projectbuilder.py | 12 ++++++++++++
3 files changed, 17 insertions(+)
create mode 100644 tests/packages/test-no-project/empty.txt
diff --git a/tests/conftest.py b/tests/conftest.py
index ee7a4962..e04914c1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -135,6 +135,11 @@ def test_no_backend_path(packages_path):
return os.path.join(packages_path, 'test-no-backend')
+@pytest.fixture
+def test_no_project_path(packages_path):
+ return os.path.join(packages_path, 'test-no-project')
+
+
@pytest.fixture
def test_no_requires_path(packages_path):
return os.path.join(packages_path, 'test-no-requires')
diff --git a/tests/packages/test-no-project/empty.txt b/tests/packages/test-no-project/empty.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/test_projectbuilder.py b/tests/test_projectbuilder.py
index c83895ce..654c6550 100644
--- a/tests/test_projectbuilder.py
+++ b/tests/test_projectbuilder.py
@@ -136,6 +136,18 @@ def test_check_dependency(monkeypatch, requirement_string, expected):
assert next(build.check_dependency(requirement_string), None) == expected
+def test_bad_project(test_no_project_path):
+ # Passing a nonexistent project directory
+ with pytest.raises(build.BuildException):
+ build.ProjectBuilder(os.path.join(test_no_project_path, "does-not-exist"))
+ # Passing a file as a project directory
+ with pytest.raises(build.BuildException):
+ build.ProjectBuilder(os.path.join(test_no_project_path, "empty.txt"))
+ # Passing a project directory with no pyproject.toml or setup.py
+ with pytest.raises(build.BuildException):
+ build.ProjectBuilder(test_no_project_path)
+
+
def test_init(mocker, test_flit_path, legacy_path, test_no_permission, test_bad_syntax_path):
mocker.patch('pep517.wrappers.Pep517HookCaller')
From 1400a34ed956b7ce3b593b0ba36dae32d3fbbc08 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Thu, 18 Mar 2021 22:59:00 +0000
Subject: [PATCH 5/7] Add a changelog entry
---
CHANGELOG.rst | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 4f298480..d3d55d7d 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -3,6 +3,15 @@ Changelog
+++++++++
+0.3.2 (XX-XX-2021)
+==================
+
+- Validate that the supplied source directory is valid (`PR #260`_)
+
+.. _PR 260: https://github.com/pypa/build/pull/260
+
+
+
0.3.1 (09-03-2021)
==================
From 1bfe27d9467addf37f7cd76f7adb0be0ce2de351 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Thu, 18 Mar 2021 23:03:06 +0000
Subject: [PATCH 6/7] Lint fixes
---
tests/test_projectbuilder.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/test_projectbuilder.py b/tests/test_projectbuilder.py
index 654c6550..1485b740 100644
--- a/tests/test_projectbuilder.py
+++ b/tests/test_projectbuilder.py
@@ -139,10 +139,10 @@ def test_check_dependency(monkeypatch, requirement_string, expected):
def test_bad_project(test_no_project_path):
# Passing a nonexistent project directory
with pytest.raises(build.BuildException):
- build.ProjectBuilder(os.path.join(test_no_project_path, "does-not-exist"))
+ build.ProjectBuilder(os.path.join(test_no_project_path, 'does-not-exist'))
# Passing a file as a project directory
with pytest.raises(build.BuildException):
- build.ProjectBuilder(os.path.join(test_no_project_path, "empty.txt"))
+ build.ProjectBuilder(os.path.join(test_no_project_path, 'empty.txt'))
# Passing a project directory with no pyproject.toml or setup.py
with pytest.raises(build.BuildException):
build.ProjectBuilder(test_no_project_path)
From 3fb27c749bcee681698148695cf7423f6a9fc2e7 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Fri, 19 Mar 2021 07:55:46 +0000
Subject: [PATCH 7/7] Changelog fixes
---
CHANGELOG.rst | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index d3d55d7d..f025405e 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -6,9 +6,10 @@ Changelog
0.3.2 (XX-XX-2021)
==================
-- Validate that the supplied source directory is valid (`PR #260`_)
+- Validate that the supplied source directory is valid (`PR #260`_, Fixes `#259`_)
-.. _PR 260: https://github.com/pypa/build/pull/260
+.. _PR #260: https://github.com/pypa/build/pull/260
+.. _#259: https://github.com/pypa/build/issues/259