diff --git a/flit/init.py b/flit/init.py index 4524d60f..8c48c19f 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' @@ -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") @@ -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] 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()