Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 11 additions & 14 deletions flit/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand All @@ -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({
Expand All @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down