Skip to content

Commit

Permalink
BUG: include license file in the metadata directory
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Jul 6, 2022
1 parent 4847aeb commit f6601ee
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ def build(
whl.writestr(f'{self.distinfo_dir}/METADATA', self._project.metadata)
whl.writestr(f'{self.distinfo_dir}/WHEEL', self.wheel)

# add license (see https://github.com/FFY00/meson-python/issues/88)
if self._project._metadata:
license_ = self._project._metadata.license
if license_ and license_.file:
whl.write(
self._project._source_dir / license_.file,
f'{self.distinfo_dir}/{os.path.basename(license_.file)}',
)

print('{light_blue}{bold}Copying files to wheel...{reset}'.format(**_STYLES))
with mesonpy._util.cli_counter(
len(list(itertools.chain.from_iterable(wheel_files.values()))),
Expand Down
4 changes: 4 additions & 0 deletions tests/packages/license-file/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project(
'license-file',
version: '1.0.0',
)
8 changes: 8 additions & 0 deletions tests/packages/license-file/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
build-backend = 'mesonpy'
requires = ['meson-python']

[project]
name = 'license-file'
version = '1.0.0'
license = { file = 'something/LICENSE.custom' }
1 change: 1 addition & 0 deletions tests/packages/license-file/something/LICENSE.custom
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello!
5 changes: 5 additions & 0 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ def test_local_lib(virtual_env, wheel_link_against_local_lib):
subprocess.check_output([
virtual_env, '-c', 'import example; print(example.example_sum(1, 2))'
]).decode() == '3'


def test_contents_license_file(wheel_license_file):
artifact = wheel.wheelfile.WheelFile(wheel_license_file)
assert artifact.read('license_file-1.0.0.dist-info/LICENSE.custom') == b'Hello!\n'

0 comments on commit f6601ee

Please sign in to comment.