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

replace distutils.version with packaging.version #421

Merged
merged 1 commit into from
Mar 15, 2022
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
4 changes: 2 additions & 2 deletions bioimageio/spec/collection/v0_2/raw_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
serialization and deserialization are defined in schema:
RDF <--schema--> raw nodes
"""
import distutils.version
import packaging.version
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Dict, List, NewType, Union
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(
format_version: FormatVersion,
name: str,
type: str = missing,
version: Union[_Missing, distutils.version.StrictVersion] = missing,
version: Union[_Missing, packaging.version.Version] = missing,
# RDF
attachments: Union[_Missing, Dict[str, Any]] = missing,
authors: Union[_Missing, List[Author]] = missing,
Expand Down
8 changes: 4 additions & 4 deletions bioimageio/spec/model/v0_3/raw_nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import distutils.version
import packaging.version
from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -95,7 +95,7 @@ class _WeightsEntryBase(RawNode):
@dataclass
class KerasHdf5WeightsEntry(_WeightsEntryBase):
weights_format_name = "Keras HDF5"
tensorflow_version: Union[_Missing, distutils.version.StrictVersion] = missing
tensorflow_version: Union[_Missing, packaging.version.Version] = missing


@dataclass
Expand All @@ -117,13 +117,13 @@ class PytorchScriptWeightsEntry(_WeightsEntryBase):
@dataclass
class TensorflowJsWeightsEntry(_WeightsEntryBase):
weights_format_name = "Tensorflow.js"
tensorflow_version: Union[_Missing, distutils.version.StrictVersion] = missing
tensorflow_version: Union[_Missing, packaging.version.Version] = missing


@dataclass
class TensorflowSavedModelBundleWeightsEntry(_WeightsEntryBase):
weights_format_name = "Tensorflow Saved Model"
tensorflow_version: Union[_Missing, distutils.version.StrictVersion] = missing
tensorflow_version: Union[_Missing, packaging.version.Version] = missing
# tag: Union[_Missing, str] = missing # todo: do we need the tag??


Expand Down
6 changes: 3 additions & 3 deletions bioimageio/spec/model/v0_3/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def raise_on_weights_format_mismatch(self, raw_node, **kwargs):
class KerasHdf5WeightsEntry(_WeightsEntryBase):
bioimageio_description = "Keras HDF5 weights format"
weights_format = fields.String(validate=field_validators.Equal("keras_hdf5"), required=True, load_only=True)
tensorflow_version = fields.StrictVersion()
tensorflow_version = fields.Version()


class OnnxWeightsEntry(_WeightsEntryBase):
Expand All @@ -427,15 +427,15 @@ class PytorchScriptWeightsEntry(_WeightsEntryBase):
class TensorflowJsWeightsEntry(_WeightsEntryBase):
bioimageio_description = "Tensorflow Javascript weights format"
weights_format = fields.String(validate=field_validators.Equal("tensorflow_js"), required=True, load_only=True)
tensorflow_version = fields.StrictVersion()
tensorflow_version = fields.Version()


class TensorflowSavedModelBundleWeightsEntry(_WeightsEntryBase):
bioimageio_description = "Tensorflow Saved Model Bundle weights format"
weights_format = fields.String(
validate=field_validators.Equal("tensorflow_saved_model_bundle"), required=True, load_only=True
)
tensorflow_version = fields.StrictVersion()
tensorflow_version = fields.Version()


WeightsEntry = typing.Union[
Expand Down
6 changes: 3 additions & 3 deletions bioimageio/spec/model/v0_4/raw_nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import distutils.version
import packaging.version
from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -78,7 +78,7 @@ class PytorchStateDictWeightsEntry(_WeightsEntryBase):
architecture: ImportableSource = missing
architecture_sha256: Union[_Missing, str] = missing
kwargs: Union[_Missing, Dict[str, Any]] = missing
pytorch_version: Union[_Missing, distutils.version.StrictVersion] = missing
pytorch_version: Union[_Missing, packaging.version.Version] = missing


@dataclass
Expand All @@ -94,7 +94,7 @@ class TensorflowSavedModelBundleWeightsEntry(_WeightsEntryBase, TensorflowSavedM
@dataclass
class TorchscriptWeightsEntry(_WeightsEntryBase):
weights_format_name = "Torchscript"
pytorch_version: Union[_Missing, distutils.version.StrictVersion] = missing
pytorch_version: Union[_Missing, packaging.version.Version] = missing


WeightsEntry = Union[
Expand Down
4 changes: 2 additions & 2 deletions bioimageio/spec/model/v0_4/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class PytorchStateDictWeightsEntry(_WeightsEntryBase):
kwargs = fields.Kwargs(
bioimageio_description="Keyword arguments for the implementation specified by `architecture`."
)
pytorch_version = fields.StrictVersion()
pytorch_version = fields.Version()

@validates_schema
def sha_for_source_code_file(self, data, **kwargs):
Expand Down Expand Up @@ -253,7 +253,7 @@ class TorchscriptWeightsEntry(_WeightsEntryBase):

bioimageio_description = "Torchscript weights format"
weights_format = fields.String(validate=field_validators.Equal("torchscript"), required=True, load_only=True)
pytorch_version = fields.StrictVersion()
pytorch_version = fields.Version()


WeightsEntry = typing.Union[
Expand Down
4 changes: 2 additions & 2 deletions bioimageio/spec/rdf/v0_2/raw_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RDF <--schema--> raw nodes
"""
import dataclasses
import distutils.version
import packaging.version
import warnings
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(
format_version: FormatVersion,
name: str,
type: str = missing,
version: Union[_Missing, distutils.version.StrictVersion] = missing,
version: Union[_Missing, packaging.version.Version] = missing,
# RDF
attachments: Union[_Missing, Dict[str, Any]] = missing,
authors: Union[_Missing, List[Author]] = missing,
Expand Down
2 changes: 1 addition & 1 deletion bioimageio/spec/rdf/v0_2/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def validate_type(self, value):
if value != schema_type:
self.warn("type", f"Unrecognized type '{value}'. Validating as {schema_type}.")

version = fields.StrictVersion(
version = fields.Version(
bioimageio_description="The version number of the model. The version number format must be a string in "
"`MAJOR.MINOR.PATCH` format following the guidelines in Semantic Versioning 2.0.0 (see https://semver.org/), "
"e.g. the initial version number should be `0.1.0`."
Expand Down
6 changes: 3 additions & 3 deletions bioimageio/spec/shared/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""fields to be used in the versioned schemas (may return shared raw nodes on `deserialize`"""
import datetime
import distutils.version
import packaging.version
import logging
import pathlib
import typing
Expand Down Expand Up @@ -513,15 +513,15 @@ def _deserialize(self, *args, **kwargs):
return value_str


class StrictVersion(String):
class Version(String):
def _deserialize(
self,
value: typing.Any,
attr: typing.Optional[str],
data: typing.Optional[typing.Mapping[str, typing.Any]],
**kwargs,
):
return distutils.version.StrictVersion(str(value))
return packaging.version.Version(str(value))


class URI(String):
Expand Down
4 changes: 2 additions & 2 deletions bioimageio/spec/shared/raw_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RDF <--schema--> raw nodes
"""
import dataclasses
import distutils.version
import packaging.version
import pathlib
from dataclasses import dataclass
from typing import ClassVar, List, Optional, Sequence, Union
Expand Down Expand Up @@ -47,7 +47,7 @@ class ResourceDescription(RawNode):
format_version: str = missing
name: str = missing
type: str = missing
version: Union[_Missing, distutils.version.StrictVersion] = missing
version: Union[_Missing, packaging.version.Version] = missing
root_path: pathlib.Path = pathlib.Path() # note: `root_path` is not officially part of the spec,
# but any RDF has it as it is the folder containing the rdf.yaml

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"marshmallow-union",
"marshmallow>=3.6.0,<4.0",
"numpy",
"packaging>=17.0",
"requests;platform_system!='Emscripten'",
"ruamel.yaml;platform_system!='Emscripten'",
"tqdm;platform_system!='Emscripten'",
Expand Down