From dd49ea6a6e03bea72ca88d2bdfd2e8e82fcc7862 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 9 Feb 2025 16:42:33 +0000 Subject: [PATCH 1/3] Create new style license metadata with flit init --- flit/init.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/flit/init.py b/flit/init.py index 4524d60f..2f18386e 100644 --- a/flit/init.py +++ b/flit/init.py @@ -49,10 +49,10 @@ def store_defaults(d): ('skip', "Skip - choose a license later"), ] -license_names_to_classifiers = { - 'mit': 'License :: OSI Approved :: MIT License', - 'gpl3': 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', - 'apache': 'License :: OSI Approved :: Apache Software License' +license_names_to_spdx = { + 'mit': 'MIT', + 'apache': 'Apache-2.0', + 'gpl3': 'GPL-3.0-or-later', } license_templates_dir = Path(__file__).parent / 'license_templates' @@ -213,9 +213,7 @@ def initialise(self): else: authors_list = "[]" - classifiers = [] if license != 'skip': - classifiers = [license_names_to_classifiers[license]] self.write_license(license, author) with (self.directory / 'pyproject.toml').open('w', encoding='utf-8') as f: @@ -225,9 +223,8 @@ def initialise(self): if readme: f.write(tomli_w.dumps({'readme': readme})) if license != 'skip': - f.write('license = {file = "LICENSE"}\n') - if classifiers: - f.write(f"classifiers = {json.dumps(classifiers)}\n") + f.write(tomli_w.dumps({'license': license_names_to_spdx[license]})) + f.write(f"license-files = {json.dumps(['LICENSE'])}\n") f.write('dynamic = ["version", "description"]\n') if home_page: f.write("\n" + tomli_w.dumps({ @@ -239,7 +236,7 @@ def initialise(self): TEMPLATE = """\ [build-system] -requires = ["flit_core >=3.2,<4"] +requires = ["flit_core >=3.11,<4"] build-backend = "flit_core.buildapi" [project] From 1ddd56952c941c20f6c4bacd60f713f5419f4b89 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 9 Feb 2025 16:45:21 +0000 Subject: [PATCH 2/3] Simplify some code using pathlib read_text & write_text methods --- flit/init.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/flit/init.py b/flit/init.py index 2f18386e..8c48c19f 100644 --- a/flit/init.py +++ b/flit/init.py @@ -119,11 +119,11 @@ def write_license(self, name, author): if (self.directory / 'LICENSE').exists(): return year = date.today().year - with (license_templates_dir / name).open(encoding='utf-8') as f: - license_text = f.read() + license_text = (license_templates_dir / name).read_text('utf-8') - with (self.directory / 'LICENSE').open('w', encoding='utf-8') as f: - f.write(license_text.format(year=year, author=author)) + (self.directory / 'LICENSE').write_text( + license_text.format(year=year, author=author), encoding='utf-8' + ) def find_readme(self): allowed = ("readme.md","readme.rst","readme.txt") From 30bf6b69e88cc67f1fd0e870548ec8552de522bd Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 9 Feb 2025 16:47:48 +0000 Subject: [PATCH 3/3] Fix failing test for flit init --- tests/test_init.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_init.py b/tests/test_init.py index 832343fe..94f93851 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -113,7 +113,8 @@ def test_init(): data = tomllib.load(f) assert data['project']['authors'][0]['email'] == "test@example.com" license = Path(td) / 'LICENSE' - assert data['project']['license']['file'] == 'LICENSE' + assert data['project']['license'] == 'MIT' + assert data['project']['license-files'] == ['LICENSE'] assert_isfile(license) with license.open() as f: license_text = f.read()