From 8cfc194dc48f4d2428f5f9744334024162564351 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 17 Jul 2026 11:56:45 -0400 Subject: [PATCH 1/2] Omit license metadata when no license is declared Previously the build defaulted to Apache-2.0 when no `__license__` was declared. Treat license selection as a positive signal instead: omit the License-Expression metadata (and the injected LICENSE file) entirely when no license is indicated. Declare Apache-2.0 for coherent.build itself. Ref #67 Co-Authored-By: Claude Opus 4.8 --- __init__.py | 2 ++ flit.py | 3 ++- metadata.py | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/__init__.py b/__init__.py index 0ae735c..446f42d 100644 --- a/__init__.py +++ b/__init__.py @@ -4,6 +4,8 @@ 'importlib_resources; python_version < "3.12"', ] +__license__ = 'Apache-2.0' + # honor PYTHONSAFEPATH (coherent-oss/system#21) import jaraco.compat.py310.safe_path # noqa: F401 diff --git a/flit.py b/flit.py index 46a05f9..b3a22ea 100644 --- a/flit.py +++ b/flit.py @@ -113,4 +113,5 @@ def gen_files(self): yield from super().gen_files() yield 'pyproject.toml', render(self.metadata) yield self.metadata.readme_filename, self.metadata['Description'] - yield 'LICENSE', coherent.licensed.resolve(self.metadata['License-Expression']) + if license := self.metadata['License-Expression']: + yield 'LICENSE', coherent.licensed.resolve(license) diff --git a/metadata.py b/metadata.py index bddae05..86fb88f 100644 --- a/metadata.py +++ b/metadata.py @@ -112,7 +112,8 @@ def _discover_fields(): yield from discovery.best_description() for classifier in discovery.generate_classifiers(): yield 'Classifier', classifier - yield 'License-Expression', discovery.declared_license() or 'Apache-2.0' + if license := discovery.declared_license(): + yield 'License-Expression', license @classmethod @suppress(MetadataNotFound) @@ -153,8 +154,9 @@ def render_toml(self): "dependencies": self.get_all("Requires-Dist") or [], "classifiers": self.get_all("Classifier") or [], 'urls': self.urls, - 'license': self['License-Expression'], } + if license := self['License-Expression']: + project['license'] = license return project From 3fffa6e4fd519f4fdac82c73e683ef298da11d0b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 17 Jul 2026 14:02:22 -0400 Subject: [PATCH 2/2] Make declared_license doctest independent of the working directory The first `>>> declared_license()` example ran in the repo's own directory, which now declares __license__, so it returned 'Apache-2.0' instead of None. chdir into a clean tmp_path before exercising the no-license case. Co-Authored-By: Claude Opus 4.8 --- discovery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discovery.py b/discovery.py index 563d569..bf4525c 100644 --- a/discovery.py +++ b/discovery.py @@ -201,10 +201,10 @@ def declared_license(): Returns None if no ``__license__`` is declared. - >>> declared_license() >>> monkeypatch = getfixture('monkeypatch') >>> tmp_path = getfixture('tmp_path') >>> monkeypatch.chdir(tmp_path) + >>> declared_license() >>> _ = (tmp_path / '__init__.py').write_text('__license__ = "MIT"\\n') >>> declared_license() 'MIT'