diff --git a/poetry/masonry/builders/builder.py b/poetry/masonry/builders/builder.py index ef38540743f..14ca2de7db6 100644 --- a/poetry/masonry/builders/builder.py +++ b/poetry/masonry/builders/builder.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- -import os import re import shutil import tempfile - from collections import defaultdict from contextlib import contextmanager from typing import Set @@ -17,12 +15,10 @@ from poetry.utils._compat import lru_cache from poetry.utils._compat import to_str from poetry.vcs import get_vcs - from ..metadata import Metadata from ..utils.module import Module from ..utils.package_include import PackageInclude - AUTHOR_REGEX = re.compile(r"(?u)^(?P[- .,\w\d'’\"()]+) <(?P.+?)>$") METADATA_BASE = """\ @@ -34,7 +30,6 @@ class Builder(object): - AVAILABLE_PYTHONS = {"2", "2.7", "3", "3.4", "3.5", "3.6", "3.7"} format = None @@ -86,8 +81,18 @@ def find_excluded_files(self): # type: () -> Set[str] explicitely_excluded = set() for excluded_glob in self._package.exclude: + excluded_path = Path(self._path, excluded_glob) + + try: + is_dir = excluded_path.is_dir() + except OSError: + # On Windows, testing if a path with a glob is a directory will raise an OSError + is_dir = False + if is_dir: + excluded_glob = Path(excluded_glob, "**/*") + for excluded in glob( - os.path.join(self._path.as_posix(), str(excluded_glob)), recursive=True + Path(self._path, excluded_glob).as_posix(), recursive=True ): explicitely_excluded.add( Path(excluded).relative_to(self._path).as_posix() diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/LICENSE b/tests/masonry/builders/fixtures/exclude_nested_data_toml/LICENSE new file mode 100644 index 00000000000..44cf2b30e68 --- /dev/null +++ b/tests/masonry/builders/fixtures/exclude_nested_data_toml/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2018 Sébastien Eustace + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/README.rst b/tests/masonry/builders/fixtures/exclude_nested_data_toml/README.rst new file mode 100644 index 00000000000..f7fe15470f9 --- /dev/null +++ b/tests/masonry/builders/fixtures/exclude_nested_data_toml/README.rst @@ -0,0 +1,2 @@ +My Package +========== diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/__init__.py b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/data/data1.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/data/data1.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/data/sub_data/data2.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/data/sub_data/data2.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/data/sub_data/data3.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/data/sub_data/data3.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/item1/itemdata1.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/item1/itemdata1.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/item1/subitem/subitemdata.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/item1/subitem/subitemdata.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/item2/itemdata2.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/item2/itemdata2.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/publicdata.txt b/tests/masonry/builders/fixtures/exclude_nested_data_toml/my_package/puplic/publicdata.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml b/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml new file mode 100644 index 00000000000..21efcba30eb --- /dev/null +++ b/tests/masonry/builders/fixtures/exclude_nested_data_toml/pyproject.toml @@ -0,0 +1,41 @@ +[tool.poetry] +name = "my-package" +version = "1.2.3" +description = "Some description." +authors = [ + "Sébastien Eustace " +] +license = "MIT" + +readme = "README.rst" + +exclude = ["my_package/data/", "**/*/item*"] + +homepage = "https://poetry.eustace.io/" +repository = "https://github.com/sdispater/poetry" +documentation = "https://poetry.eustace.io/docs" + +keywords = ["packaging", "dependency", "poetry"] + +classifiers = [ + "Topic :: Software Development :: Build Tools", + "Topic :: Software Development :: Libraries :: Python Modules" +] + +# 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/test_sdist.py b/tests/masonry/builders/test_sdist.py index 281016a3653..b67dc5ee229 100644 --- a/tests/masonry/builders/test_sdist.py +++ b/tests/masonry/builders/test_sdist.py @@ -410,6 +410,38 @@ def test_default_with_excluded_data(mocker): assert "my-package-1.2.3/PKG-INFO" in names +def test_src_excluded_nested_data(): + module_path = fixtures_dir / "exclude_nested_data_toml" + poetry = Factory().create_poetry(module_path) + + builder = SdistBuilder(poetry, NullEnv(), NullIO()) + builder.build() + + sdist = module_path / "dist" / "my-package-1.2.3.tar.gz" + + assert sdist.exists() + + with tarfile.open(str(sdist), "r") as tar: + names = tar.getnames() + assert len(names) == len(set(names)) + assert "my-package-1.2.3/LICENSE" in names + assert "my-package-1.2.3/README.rst" in names + assert "my-package-1.2.3/pyproject.toml" in names + assert "my-package-1.2.3/setup.py" in names + assert "my-package-1.2.3/PKG-INFO" in names + assert "my-package-1.2.3/my_package/__init__.py" in names + assert "my-package-1.2.3/my_package/data/sub_data/data2.txt" not in names + assert "my-package-1.2.3/my_package/data/sub_data/data3.txt" not in names + assert "my-package-1.2.3/my_package/data/data1.txt" not in names + assert "my-package-1.2.3/my_package/puplic/publicdata.txt" in names + assert "my-package-1.2.3/my_package/public/item1/itemdata1.txt" not in names + assert ( + "my-package-1.2.3/my_package/public/item1/subitem/subitemdata.txt" + not in names + ) + assert "my-package-1.2.3/my_package/public/item2/itemdata2.txt" not in names + + def test_proper_python_requires_if_two_digits_precision_version_specified(): poetry = Factory().create_poetry(project("simple_version")) diff --git a/tests/masonry/builders/test_wheel.py b/tests/masonry/builders/test_wheel.py index 7b5ec8611ea..33c50a5d6a7 100644 --- a/tests/masonry/builders/test_wheel.py +++ b/tests/masonry/builders/test_wheel.py @@ -77,6 +77,26 @@ def test_wheel_excluded_data(): assert "my_package/data/data1.txt" not in z.namelist() +def test_wheel_excluded_nested_data(): + module_path = fixtures_dir / "exclude_nested_data_toml" + poetry = Factory().create_poetry(module_path) + WheelBuilder.make(poetry, NullEnv(), NullIO()) + + whl = module_path / "dist" / "my_package-1.2.3-py3-none-any.whl" + + assert whl.exists() + + with zipfile.ZipFile(str(whl)) as z: + assert "my_package/__init__.py" in z.namelist() + assert "my_package/data/sub_data/data2.txt" not in z.namelist() + assert "my_package/data/sub_data/data3.txt" not in z.namelist() + assert "my_package/data/data1.txt" not in z.namelist() + assert "my_package/puplic/publicdata.txt" in z.namelist() + assert "my_package/public/item1/itemdata1.txt" not in z.namelist() + 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_wheel_localversionlabel(): module_path = fixtures_dir / "localversionlabel" WheelBuilder.make(Factory().create_poetry(module_path), NullEnv(), NullIO())