Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: require version in dynamic if unset #74

Merged
merged 1 commit into from
Nov 29, 2023
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
11 changes: 5 additions & 6 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ class StandardMetadata:
gui_scripts: dict[str, str] = dataclasses.field(default_factory=dict)
dynamic: list[str] = dataclasses.field(default_factory=list)

def __post_init__(self) -> None:
self._update_dynamic(self.version)

@property
def canonical_name(self) -> str:
return packaging.utils.canonicalize_name(self.name)
Expand Down Expand Up @@ -229,6 +226,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 @@ -237,7 +238,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 @@ -258,8 +259,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
Loading