From 832b10b03ac08dc96531002e99f2cd0682ea45c1 Mon Sep 17 00:00:00 2001 From: Audun Skaugen Date: Wed, 13 Jan 2021 19:46:29 +0100 Subject: [PATCH 1/2] Fix #3258 Paths for generated code that's excluded by vcs, but then included explicitly, were wrong because they appared in the exclude list during Builder.find_excluded_files(). I changed find_excluded_files to not exclude files which are explicitly included, by taking a set difference. Added a test for this case. --- poetry/core/masonry/builders/builder.py | 10 +++++++++- .../lib/my_package/__init__.py | 0 .../lib/my_package/generated.py | 0 .../include_excluded_code/pyproject.toml | 20 +++++++++++++++++++ tests/masonry/builders/test_wheel.py | 13 ++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/masonry/builders/fixtures/include_excluded_code/lib/my_package/__init__.py create mode 100644 tests/masonry/builders/fixtures/include_excluded_code/lib/my_package/generated.py create mode 100644 tests/masonry/builders/fixtures/include_excluded_code/pyproject.toml diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index c6f6d9cd6..b439b4616 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -111,7 +111,15 @@ def find_excluded_files(self): # type: () -> Set[str] Path(excluded).relative_to(self._path).as_posix() ) - ignored = vcs_ignored_files | explicitely_excluded + explicitely_included = set() + for inc in self._package.include: + included_glob = inc['path'] + for included in self._path.glob(str(included_glob)): + explicitely_included.add( + Path(included).relative_to(self._path).as_posix() + ) + + ignored = (vcs_ignored_files | explicitely_excluded) - explicitely_included result = set() for file in ignored: result.add(file) diff --git a/tests/masonry/builders/fixtures/include_excluded_code/lib/my_package/__init__.py b/tests/masonry/builders/fixtures/include_excluded_code/lib/my_package/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/include_excluded_code/lib/my_package/generated.py b/tests/masonry/builders/fixtures/include_excluded_code/lib/my_package/generated.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/include_excluded_code/pyproject.toml b/tests/masonry/builders/fixtures/include_excluded_code/pyproject.toml new file mode 100644 index 000000000..379b7dbc1 --- /dev/null +++ b/tests/masonry/builders/fixtures/include_excluded_code/pyproject.toml @@ -0,0 +1,20 @@ +[tool.poetry] +name = "my_package" +version = "0.1.0" +description = "" +authors = ["Audun Skaugen "] + +packages = [{include='my_package', from='lib'}] +# Simulate excluding due to .gitignore +exclude = ['lib/my_package/generated.py'] +# Include again +include = ['lib/my_package/generated.py'] + +[tool.poetry.dependencies] +python = "^3.8" + +[tool.poetry.dev-dependencies] + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/tests/masonry/builders/test_wheel.py b/tests/masonry/builders/test_wheel.py index a8bbdd527..c0cc8c1ce 100644 --- a/tests/masonry/builders/test_wheel.py +++ b/tests/masonry/builders/test_wheel.py @@ -96,6 +96,18 @@ def test_wheel_excluded_nested_data(): assert "my_package/public/item1/subitem/subitemdata.txt" not in z.namelist() assert "my_package/public/item2/itemdata2.txt" not in z.namelist() +def test_include_excluded_code(): + module_path = fixtures_dir / "include_excluded_code" + poetry = Factory().create_poetry(module_path) + wb = WheelBuilder(poetry) + wb.build() + whl = module_path / "dist" / wb.wheel_filename + assert whl.exists() + + with zipfile.ZipFile(str(whl)) as z: + assert "my_package/__init__.py" in z.namelist() + assert "my_package/generated.py" in z.namelist() + assert "lib/my_package/generated.py" not in z.namelist() def test_wheel_localversionlabel(): module_path = fixtures_dir / "localversionlabel" @@ -270,3 +282,4 @@ def test_default_src_with_excluded_data(mocker): assert "my_package/data/data1.txt" in names assert "my_package/data/sub_data/data2.txt" not in names assert "my_package/data/sub_data/data3.txt" in names + From b2d24fd7fbf7f7b7b4123067618b03228b15cd0b Mon Sep 17 00:00:00 2001 From: Audun Skaugen Date: Wed, 13 Jan 2021 19:58:09 +0100 Subject: [PATCH 2/2] Black formatting --- poetry/core/masonry/builders/builder.py | 2 +- tests/masonry/builders/test_wheel.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index b439b4616..78ef49de4 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -113,7 +113,7 @@ def find_excluded_files(self): # type: () -> Set[str] explicitely_included = set() for inc in self._package.include: - included_glob = inc['path'] + included_glob = inc["path"] for included in self._path.glob(str(included_glob)): explicitely_included.add( Path(included).relative_to(self._path).as_posix() diff --git a/tests/masonry/builders/test_wheel.py b/tests/masonry/builders/test_wheel.py index c0cc8c1ce..530680d16 100644 --- a/tests/masonry/builders/test_wheel.py +++ b/tests/masonry/builders/test_wheel.py @@ -96,6 +96,7 @@ def test_wheel_excluded_nested_data(): assert "my_package/public/item1/subitem/subitemdata.txt" not in z.namelist() assert "my_package/public/item2/itemdata2.txt" not in z.namelist() + def test_include_excluded_code(): module_path = fixtures_dir / "include_excluded_code" poetry = Factory().create_poetry(module_path) @@ -109,6 +110,7 @@ def test_include_excluded_code(): assert "my_package/generated.py" in z.namelist() assert "lib/my_package/generated.py" not in z.namelist() + def test_wheel_localversionlabel(): module_path = fixtures_dir / "localversionlabel" project = Factory().create_poetry(module_path) @@ -282,4 +284,3 @@ def test_default_src_with_excluded_data(mocker): assert "my_package/data/data1.txt" in names assert "my_package/data/sub_data/data2.txt" not in names assert "my_package/data/sub_data/data3.txt" in names -