Skip to content

Commit 60d8182

Browse files
add test_package_with_include_symbolic_links inside test_complete
1 parent bca3c50 commit 60d8182

File tree

21 files changed

+190
-2
lines changed

21 files changed

+190
-2
lines changed

src/poetry/core/masonry/builders/sdist.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ def find_nearest_pkg(rel_path: str) -> tuple[str, str]:
316316

317317
return pkgdir, sorted(packages), pkg_data
318318

319-
def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile]:
319+
def find_files_to_add(
320+
self, exclude_build: bool = False, resolve_symlinks: bool = True
321+
) -> set[BuildIncludeFile]:
320322
to_add = super().find_files_to_add(exclude_build)
321323

322324
# add any additional files, starting with all LICENSE files
@@ -334,7 +336,10 @@ def find_files_to_add(self, exclude_build: bool = False) -> set[BuildIncludeFile
334336

335337
for additional_file in additional_files:
336338
file = BuildIncludeFile(
337-
path=additional_file, project_root=self._path, source_root=self._path
339+
path=additional_file,
340+
project_root=self._path,
341+
source_root=self._path,
342+
resolve_symlinks=resolve_symlinks,
338343
)
339344
if file.path.exists():
340345
logger.debug(f"Adding: {file.relative_to_source_root()}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2018 Sébastien Eustace
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
My Package
2+
==========

tests/masonry/builders/fixtures/with-include-symbolic/data/1/35/2/blabla.txt

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/data/2/4/5/nd.txt

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/data/3/3/3/je.txt

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/data/4/1/2/erric.txt

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/extra_dir/README.md

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/extra_dir/__init__.py

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/extra_dir/sub_pkg/__init__.py

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/extra_dir/sub_pkg/vcs_excluded.txt

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/extra_dir/vcs_excluded.txt

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/for_wheel_only/__init__.py

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/my_module.py

Whitespace-only changes.

tests/masonry/builders/fixtures/with-include-symbolic/notes.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.2.3"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[tool.poetry]
2+
name = "with-include-symbolic"
3+
version = "1.2.3"
4+
description = "Some description."
5+
authors = [
6+
"Sébastien Eustace <[email protected]>"
7+
]
8+
license = "MIT"
9+
10+
readme = "README.rst"
11+
12+
homepage = "https://python-poetry.org/"
13+
repository = "https://github.com/python-poetry/poetry"
14+
documentation = "https://python-poetry.org/docs"
15+
16+
keywords = ["packaging", "dependency", "poetry"]
17+
18+
classifiers = [
19+
"Topic :: Software Development :: Build Tools",
20+
"Topic :: Software Development :: Libraries :: Python Modules"
21+
]
22+
23+
packages = [
24+
{ include = "extra_dir/**/*.py" },
25+
{ include = "extra_dir/**/*.py" },
26+
{ include = "my_module.py" },
27+
{ include = "package_with_include" },
28+
{ include = "tests", format = "sdist" },
29+
{ include = "for_wheel_only", format = ["wheel"] },
30+
{ include = "src_package", from = "src", format = ["wheel","sdist"] },
31+
]
32+
33+
include = [
34+
"extra_dir/vcs_excluded.txt",
35+
{ path = "src/src_package/data", format = ["wheel","sdist"] },
36+
"notes.txt"
37+
]
38+
39+
40+
# Requirements
41+
[tool.poetry.dependencies]
42+
python = "^3.6"
43+
cleo = "^0.6"
44+
cachy = { version = "^0.2.0", extras = ["msgpack"] }
45+
46+
pendulum = { version = "^1.4", optional = true }
47+
48+
[tool.poetry.dev-dependencies]
49+
pytest = "~3.4"
50+
51+
[tool.poetry.extras]
52+
time = ["pendulum"]
53+
54+
[tool.poetry.scripts]
55+
my-script = "my_package:main"
56+
my-2nd-script = "my_package:main2"

tests/masonry/builders/fixtures/with-include-symbolic/src/src_package/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../data

tests/masonry/builders/fixtures/with-include-symbolic/tests/__init__.py

Whitespace-only changes.

tests/masonry/builders/test_complete.py

+103
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,109 @@ def test_package_with_include(mocker: MockerFixture) -> None:
582582
assert "src_package/__init__.py" in names
583583

584584

585+
def test_package_with_include_symbolic_links(mocker: MockerFixture) -> None:
586+
module_path = fixtures_dir / "with-include-symbolic"
587+
588+
# Patch git module to return specific excluded files
589+
p = mocker.patch("poetry.core.vcs.git.Git.get_ignored_files")
590+
p.return_value = [
591+
str(
592+
Path(__file__).parent
593+
/ "fixtures"
594+
/ "with-include-symbolic"
595+
/ "extra_dir"
596+
/ "vcs_excluded.txt"
597+
),
598+
str(
599+
Path(__file__).parent
600+
/ "fixtures"
601+
/ "with-include-symbolic"
602+
/ "extra_dir"
603+
/ "sub_pkg"
604+
/ "vcs_excluded.txt"
605+
),
606+
]
607+
builder = Builder(Factory().create_poetry(module_path))
608+
builder.build(fmt="all")
609+
610+
sdist = (
611+
fixtures_dir
612+
/ "with-include-symbolic"
613+
/ "dist"
614+
/ "with-include-symbolic-1.2.3.tar.gz"
615+
)
616+
617+
assert sdist.exists()
618+
619+
with tarfile.open(str(sdist), "r") as tar:
620+
names = tar.getnames()
621+
assert len(names) == len(set(names))
622+
assert "with-include-symbolic-1.2.3/LICENSE" in names
623+
assert "with-include-symbolic-1.2.3/README.rst" in names
624+
assert "with-include-symbolic-1.2.3/extra_dir/__init__.py" in names
625+
assert "with-include-symbolic-1.2.3/extra_dir/vcs_excluded.txt" in names
626+
assert "with-include-symbolic-1.2.3/extra_dir/sub_pkg/__init__.py" in names
627+
assert (
628+
"with-include-symbolic-1.2.3/extra_dir/sub_pkg/vcs_excluded.txt"
629+
not in names
630+
)
631+
assert "with-include-symbolic-1.2.3/my_module.py" in names
632+
assert "with-include-symbolic-1.2.3/notes.txt" in names
633+
assert "with-include-symbolic-1.2.3/package_with_include/__init__.py" in names
634+
assert "with-include-symbolic-1.2.3/tests/__init__.py" in names
635+
assert "with-include-symbolic-1.2.3/pyproject.toml" in names
636+
assert "with-include-symbolic-1.2.3/setup.py" in names
637+
assert "with-include-symbolic-1.2.3/PKG-INFO" in names
638+
assert "with-include-symbolic-1.2.3/for_wheel_only/__init__.py" not in names
639+
assert "with-include-symbolic-1.2.3/src/src_package/__init__.py" in names
640+
assert "with-include-symbolic-1.2.3/data/1/35/2/blabla.txt" in names
641+
assert "with-include-symbolic-1.2.3/data/2/4/5/nd.txt" in names
642+
assert "with-include-symbolic-1.2.3/data/3/3/3/je.txt" in names
643+
assert "with-include-symbolic-1.2.3/data/4/1/2/erric.txt" in names
644+
645+
file = tar.extractfile("with-include-symbolic-1.2.3/setup.py")
646+
assert file
647+
setup = file.read()
648+
setup_ast = ast.parse(setup)
649+
650+
setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
651+
ns: dict[str, Any] = {}
652+
exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
653+
assert ns["package_dir"] == {"": "src"}
654+
assert ns["packages"] == [
655+
"extra_dir",
656+
"extra_dir.sub_pkg",
657+
"package_with_include",
658+
"src_package",
659+
"tests",
660+
]
661+
assert ns["package_data"] == {"": ["*"]}
662+
assert ns["modules"] == ["my_module"]
663+
664+
whl = module_path / "dist" / "with_include_symbolic-1.2.3-py3-none-any.whl"
665+
666+
assert whl.exists()
667+
668+
with zipfile.ZipFile(str(whl)) as z:
669+
names = z.namelist()
670+
assert len(names) == len(set(names))
671+
assert "with_include_symbolic-1.2.3.dist-info/LICENSE" in names
672+
assert "extra_dir/__init__.py" in names
673+
assert "extra_dir/vcs_excluded.txt" in names
674+
assert "extra_dir/sub_pkg/__init__.py" in names
675+
assert "extra_dir/sub_pkg/vcs_excluded.txt" not in names
676+
assert "for_wheel_only/__init__.py" in names
677+
assert "my_module.py" in names
678+
assert "notes.txt" in names
679+
assert "package_with_include/__init__.py" in names
680+
assert "tests/__init__.py" not in names
681+
assert "src_package/__init__.py" in names
682+
assert "src_package/data/1/35/2/blabla.txt" in names
683+
assert "src_package/data/2/4/5/nd.txt" in names
684+
assert "src_package/data/3/3/3/je.txt" in names
685+
assert "src_package/data/4/1/2/erric.txt" in names
686+
687+
585688
def test_respect_format_for_explicit_included_files() -> None:
586689
module_path = fixtures_dir / "exclude-whl-include-sdist"
587690
builder = Builder(Factory().create_poetry(module_path))

0 commit comments

Comments
 (0)