Skip to content

Commit

Permalink
fix: require version in dynamic if unset
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 29, 2023
1 parent f5e1688 commit 1904306
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
9 changes: 5 additions & 4 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class StandardMetadata:

def __post_init__(self) -> None:
self.name = re.sub(r'[-_.]+', '-', self.name).lower()
self._update_dynamic(self.version)

@classmethod
def from_pyproject(
Expand Down Expand Up @@ -226,6 +225,10 @@ def from_pyproject(

version_string = fetcher.get_str('project.version')
requires_python_string = fetcher.get_str('project.requires-python')
version = packaging.version.Version(version_string) if version_string else None

if version is None and 'version' not in dynamic:
raise ConfigurationError('Field "project.version" missing and "version" not specified in "project.dynamic"')

# Description can't be multiline
description = fetcher.get_str('project.description')
Expand All @@ -234,7 +237,7 @@ def from_pyproject(

return cls(
name,
packaging.version.Version(version_string) if version_string else None,
version,
description,
cls._get_license(fetcher, project_dir),
cls._get_readme(fetcher, project_dir),
Expand All @@ -255,8 +258,6 @@ def from_pyproject(
def _update_dynamic(self, value: Any) -> None:
if value and 'version' in self.dynamic:
self.dynamic.remove('version')
elif not value and 'version' not in self.dynamic:
self.dynamic.append('version')

def __setattr__(self, name: str, value: Any) -> None:
# update dynamic when version is set
Expand Down
Loading

0 comments on commit 1904306

Please sign in to comment.