-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add processor to workspace state #730
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.mise.toml | ||
|
||
.vunnel.yaml | ||
.grype-db.yaml | ||
.grype.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"title": "provider-workspace-state", | ||
"description": "describes the filesystem state of a provider workspace directory", | ||
"properties": { | ||
"provider": { | ||
"type": "string" | ||
}, | ||
"urls": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"store": { | ||
"type": "string" | ||
}, | ||
"timestamp": { | ||
"type": "string" | ||
}, | ||
"listing": { | ||
"type": "object", | ||
"properties": { | ||
"digest": { | ||
"type": "string" | ||
}, | ||
"path": { | ||
"type": "string" | ||
}, | ||
"algorithm": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"digest", | ||
"path", | ||
"algorithm" | ||
] | ||
}, | ||
"version": { | ||
"type": "integer", | ||
"description": "version describing the result data shape + the provider processing behavior semantics" | ||
}, | ||
"distribution_version": { | ||
"type": "integer", | ||
"description": "version describing purely the result data shape" | ||
}, | ||
"processor": { | ||
"type": "string", | ||
"description": "the application that created the workspace, formatted as 'name@version'" | ||
}, | ||
Comment on lines
+51
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what was added relative to the last schema |
||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"version": { | ||
"type": "string" | ||
}, | ||
"url": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"version", | ||
"url" | ||
] | ||
}, | ||
"stale": { | ||
"type": "boolean", | ||
"description": "set to true if the workspace is stale and cannot be used for an incremental update" | ||
} | ||
}, | ||
"required": [ | ||
"provider", | ||
"urls", | ||
"store", | ||
"timestamp", | ||
"listing", | ||
"version", | ||
"schema" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
from vunnel.utils import hasher | ||
|
||
if TYPE_CHECKING: | ||
import types | ||
from collections.abc import Generator | ||
|
||
METADATA_FILENAME = "metadata.json" | ||
|
@@ -38,10 +39,31 @@ class State(DataClassDictMixin): | |
timestamp: datetime.datetime | ||
version: int = 1 | ||
distribution_version: int = 1 | ||
processor: str | None = None | ||
listing: Optional[File] = None # noqa:UP007 # why use Optional? mashumaro does not support this on python 3.9 | ||
schema: schema_def.Schema = field(default_factory=schema_def.ProviderStateSchema) | ||
stale: bool = False | ||
|
||
def __post_init__(self) -> None: | ||
if not self.processor: | ||
metadata: types.ModuleType | ||
package_name = "vunnel" | ||
version = "dev" | ||
try: | ||
from importlib import metadata | ||
except ImportError: | ||
# Python < 3.8 | ||
import importlib_metadata as metadata | ||
|
||
try: | ||
if not metadata: | ||
raise metadata.PackageNotFoundError | ||
version = metadata.version(package_name) | ||
Comment on lines
+52
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is how you can reflect package version information rather than use hard coded strings |
||
except metadata.PackageNotFoundError: | ||
version = "unknown" | ||
|
||
self.processor = f"{package_name}@{version}" | ||
|
||
@staticmethod | ||
def read(root: str) -> State: | ||
metadata_path = os.path.join(root, METADATA_FILENAME) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was getting strong deprecation warnings from the pre-commit tooling on this (and there was an auto migration command, which was rather nice of them to have)