diff --git a/poetry/core/factory.py b/poetry/core/factory.py index 8d474bc22..8d4fe4a55 100644 --- a/poetry/core/factory.py +++ b/poetry/core/factory.py @@ -112,7 +112,18 @@ def create_poetry(self, cwd=None): # type: (Optional[Path]) -> Poetry package.build = local_config["build"] if "include" in local_config: - package.include = local_config["include"] + package.include = [] + + for include in local_config["include"]: + if not isinstance(include, dict): + include = {"include": include} + + formats = include.get("format", []) + if formats and not isinstance(formats, list): + formats = [formats] + include["format"] = formats + + package.include.append(include) if "exclude" in local_config: package.exclude = local_config["exclude"] diff --git a/poetry/core/json/schemas/poetry-schema.json b/poetry/core/json/schemas/poetry-schema.json index 10aff39e5..60e241b8c 100644 --- a/poetry/core/json/schemas/poetry-schema.json +++ b/poetry/core/json/schemas/poetry-schema.json @@ -83,7 +83,7 @@ "format": { "oneOf": [ {"type": "string"}, - {"type": "array", "items": {"type": "string"}} + {"type": "array", "items": {"type": "string"}} ], "description": "The format(s) for which the package must be included." } @@ -92,7 +92,42 @@ }, "include": { "type": "array", - "description": "A list of files and folders to include." + "description": "A list of files and folders to include.", + "items": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "object", + "description": "Information about where the file or folder resides.", + "additionalProperties": false, + "required": [ + "include" + ], + "properties": { + "include": { + "type": "string", + "description": "What to include in the package." + }, + "format": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "type": "string" + } + } + ], + "description": "The format(s) for which the file(s) or folder(s) must be included." + } + } + } + ] + } }, "exclude": { "type": "array", diff --git a/poetry/core/masonry/builders/builder.py b/poetry/core/masonry/builders/builder.py index 5f146358e..fe2e1db69 100644 --- a/poetry/core/masonry/builders/builder.py +++ b/poetry/core/masonry/builders/builder.py @@ -61,11 +61,25 @@ def __init__( packages.append(p) + includes = [] + for i in self._package.include: + formats = i.get("format", []) + + if ( + formats + and self.format + and self.format not in formats + and not ignore_packages_formats + ): + continue + + includes.append(i) + self._module = Module( self._package.name, self._path.as_posix(), packages=packages, - includes=self._package.include, + includes=includes, ) self._meta = Metadata.from_package(self._package) @@ -127,6 +141,15 @@ def find_files_to_add(self, exclude_build=True): # type: (bool) -> list continue if file.is_dir(): + if self.format == "sdist" or self.format in include.formats: + for f in Path(file).glob("**/*"): + included = f.relative_to(self._path) + if ( + included not in to_add + and not f.is_dir() + and not self.is_excluded(included) + ): + to_add.append(included) continue file = file.relative_to(self._path) diff --git a/poetry/core/masonry/utils/module.py b/poetry/core/masonry/utils/module.py index bde49bf3f..597c1681f 100644 --- a/poetry/core/masonry/utils/module.py +++ b/poetry/core/masonry/utils/module.py @@ -74,7 +74,9 @@ def __init__(self, name, directory=".", packages=None, includes=None): ) for include in includes: - self._includes.append(Include(self._path, include)) + self._includes.append( + Include(self._path, include["include"], formats=include["format"]) + ) @property def name(self): # type: () -> str diff --git a/tests/masonry/builders/fixtures/with_include_inline_table/pyproject.toml b/tests/masonry/builders/fixtures/with_include_inline_table/pyproject.toml new file mode 100644 index 000000000..4c1fd9bb6 --- /dev/null +++ b/tests/masonry/builders/fixtures/with_include_inline_table/pyproject.toml @@ -0,0 +1,47 @@ +[tool.poetry] +name = "with-include" +version = "1.2.3" +description = "Some description." +authors = [ + "Sébastien Eustace <sebastien@eustace.io>" +] +license = "MIT" + +homepage = "https://python-poetry.org/" +repository = "https://github.com/python-poetry/poetry" +documentation = "https://python-poetry.org/docs" + +keywords = ["packaging", "dependency", "poetry"] + +classifiers = [ + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules" +] + +packages = [ + { include = "src_package", from = "src"}, +] + +include = [ + { include = "tests", format = "sdist" }, + { include = "wheel_only.txt", format = "wheel" } +] + + +# Requirements +[tool.poetry.dependencies] +python = "^3.6" +cleo = "^0.6" +cachy = { version = "^0.2.0", extras = ["msgpack"] } + +pendulum = { version = "^1.4", optional = true } + +[tool.poetry.dev-dependencies] +pytest = "~3.4" + +[tool.poetry.extras] +time = ["pendulum"] + +[tool.poetry.scripts] +my-script = "my_package:main" +my-2nd-script = "my_package:main2" diff --git a/tests/masonry/builders/fixtures/with_include_inline_table/src/src_package/__init__.py b/tests/masonry/builders/fixtures/with_include_inline_table/src/src_package/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/with_include_inline_table/tests/__init__.py b/tests/masonry/builders/fixtures/with_include_inline_table/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/with_include_inline_table/tests/test_foo/test.py b/tests/masonry/builders/fixtures/with_include_inline_table/tests/test_foo/test.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/fixtures/with_include_inline_table/wheel_only.txt b/tests/masonry/builders/fixtures/with_include_inline_table/wheel_only.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/masonry/builders/test_sdist.py b/tests/masonry/builders/test_sdist.py index 19daef31e..270a026af 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -465,3 +465,41 @@ def test_proper_python_requires_if_three_digits_precision_version_specified(): parsed = p.parsestr(to_str(pkg_info)) assert parsed["Requires-Python"] == "==2.7.15" + + +def test_includes(): + poetry = Factory().create_poetry(project("with-include")) + + builder = SdistBuilder(poetry) + + builder.build() + + sdist = fixtures_dir / "with-include" / "dist" / "with-include-1.2.3.tar.gz" + + assert sdist.exists() + + with tarfile.open(str(sdist), "r") as tar: + assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in tar.getnames() + assert "with-include-1.2.3/notes.txt" in tar.getnames() + + +def test_includes_with_inline_table(): + poetry = Factory().create_poetry(project("with_include_inline_table")) + + builder = SdistBuilder(poetry) + + builder.build() + + sdist = ( + fixtures_dir + / "with_include_inline_table" + / "dist" + / "with-include-1.2.3.tar.gz" + ) + + assert sdist.exists() + + with tarfile.open(str(sdist), "r") as tar: + assert "with-include-1.2.3/wheel_only.txt" not in tar.getnames() + assert "with-include-1.2.3/tests/__init__.py" in tar.getnames() + assert "with-include-1.2.3/tests/test_foo/test.py" in tar.getnames() diff --git a/tests/masonry/builders/test_wheel.py b/tests/masonry/builders/test_wheel.py index b8bbd2080..6832cf665 100644 --- a/tests/masonry/builders/test_wheel.py +++ b/tests/masonry/builders/test_wheel.py @@ -155,3 +155,16 @@ def test_dist_info_file_permissions(): z.getinfo("my_package-1.2.3.dist-info/entry_points.txt").external_attr == 0o644 << 16 ) + + +def test_wheel_includes_inline_table(): + module_path = fixtures_dir / "with_include_inline_table" + WheelBuilder.make(Factory().create_poetry(module_path)) + + whl = module_path / "dist" / "with_include-1.2.3-py3-none-any.whl" + + assert whl.exists() + + with zipfile.ZipFile(str(whl)) as z: + assert "wheel_only.txt" in z.namelist() + assert "notes.txt" not in z.namelist()