diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index c6f6d9cd6..78ef49de4 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..530680d16 100644 --- a/tests/masonry/builders/test_wheel.py +++ b/tests/masonry/builders/test_wheel.py @@ -97,6 +97,20 @@ def test_wheel_excluded_nested_data(): 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" project = Factory().create_poetry(module_path)