Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect REUSE spec when including licenses #57

Merged
merged 14 commits into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions poetry/core/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,20 @@ def _write_metadata(self, wheel):
with self._write_to_zip(wheel, self.dist_info + "/entry_points.txt") as f:
self._write_entry_points(f)

license_files_to_add = []
for base in ("COPYING", "LICENSE"):
for path in sorted(self._path.glob(base + "*")):
self._add_file(wheel, path, "%s/%s" % (self.dist_info, path.name))
license_files_to_add.append(self._path / base)
license_files_to_add.extend(self._path.glob(base + ".*"))
MrJohz marked this conversation as resolved.
Show resolved Hide resolved

license_files_to_add.extend((self._path / "LICENSES").glob("**" + os.sep + "*"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
license_files_to_add.extend((self._path / "LICENSES").glob("**" + os.sep + "*"))
license_files_to_add.extend(self._path.glob("LICENSES/**/*"))

pathlib is smart enough to handle OS diferences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful to know, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that this isn't the case when using the .glob method. I'm not sure why it isn't normalised, but you can see in this run when this change was added that the only failure was in the Windows builds.

I've reverted this change as a result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check shortly but this might be related to https://bugs.python.org/issue31202

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it is. In this case; can you try this suggestion? This should also confirm that the issue is as identified above or if pathlib does not handle os diferences as advertised.

Suggested change
license_files_to_add.extend((self._path / "LICENSES").glob("**" + os.sep + "*"))
license_files_to_add.extend(self._path.joinpath("LICENSES").glob("**/*"))


for path in license_files_to_add:
MrJohz marked this conversation as resolved.
Show resolved Hide resolved
if not path.is_file():
continue

self._add_file(
wheel, path, "%s/%s" % (self.dist_info, path.relative_to(self._path))
)
MrJohz marked this conversation as resolved.
Show resolved Hide resolved

with self._write_to_zip(wheel, self.dist_info + "/WHEEL") as f:
self._write_wheel_file(f)
Expand Down
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions tests/masonry/builders/fixtures/licenses_and_copying/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.2.3"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[tool.poetry]
name = "my-package"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
maintainers = [
"People Everywhere <[email protected]>"
]
license = "MIT"

readme = "README.rst"

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"
]

# Requirements
[tool.poetry.dependencies]
python = "^3.6"
cleo = "^0.6"
cachy = { version = "^0.2.0", extras = ["msgpack"] }

[tool.poetry.dependencies.pendulum]
version = "^1.4"
markers= 'python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5"'
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"
extra-script = {callable = "my_package.extra:main", extras = ["time"]}

[tool.poetry.urls]
"Issue Tracker" = "https://github.com/python-poetry/poetry/issues"
17 changes: 17 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,23 @@ def test_wheel_package_pep_561_stub_only_includes_typed_marker():
assert "pkg-stubs/py.typed" in z.namelist()


def test_wheel_includes_licenses_in_correct_paths():
root = fixtures_dir / "licenses_and_copying"
WheelBuilder.make(Factory().create_poetry(root))

whl = root / "dist" / "my_package-1.2.3-py3-none-any.whl"

assert whl.exists()
with zipfile.ZipFile(str(whl)) as z:
assert "my_package-1.2.3.dist-info/COPYING" in z.namelist()
assert "my_package-1.2.3.dist-info/COPYING.txt" in z.namelist()
assert "my_package-1.2.3.dist-info/LICENSE" in z.namelist()
assert "my_package-1.2.3.dist-info/LICENSE.md" in z.namelist()
assert "my_package-1.2.3.dist-info/LICENSES/CUSTOM-LICENSE" in z.namelist()
assert "my_package-1.2.3.dist-info/LICENSES/BSD-3.md" in z.namelist()
assert "my_package-1.2.3.dist-info/LICENSES/MIT.txt" in z.namelist()


def test_wheel_with_file_with_comma():
root = fixtures_dir / "comma_file"
WheelBuilder.make(Factory().create_poetry(root))
Expand Down