-
Notifications
You must be signed in to change notification settings - Fork 16
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
Updates __eq__
implementation on the data types
#445
Conversation
__slots__ = ("_version",) | ||
|
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.
such that a generic solution could be implemented that is equal for all classes in this module
def __eq__(self, other: Any) -> bool: | ||
"""Compare with another object.""" | ||
return ( | ||
isinstance(other, PackageId) | ||
and self.package_type == other.package_type | ||
and self.public_id == other.public_id | ||
) | ||
"""Check equality.""" | ||
if not isinstance(other, self.__class__): | ||
return NotImplemented # Delegate comparison to the other instance's __eq__. | ||
return all(getattr(self, s) == getattr(other, s) for s in self.__slots__) | ||
|
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.
open-aea/aea/configurations/data_types.py
Line 536 in 8e3ce14
__slots__ = ("_package_type", "_public_id") |
def __eq__(self, other: Any) -> bool: | ||
"""Compare with another object.""" | ||
return ( | ||
isinstance(other, Dependency) | ||
and self._name == other._name | ||
and self._version == other._version | ||
and self._index == other._index | ||
and self._git == other._git | ||
and self._ref == other._ref | ||
) | ||
"""Check equality.""" | ||
if not isinstance(other, self.__class__): | ||
return NotImplemented # Delegate comparison to the other instance's __eq__. | ||
return all(getattr(self, s) == getattr(other, s) for s in self.__slots__) | ||
|
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.
open-aea/aea/configurations/data_types.py
Line 764 in 8e3ce14
__slots__ = ("_name", "_version", "_index", "_git", "_ref") |
8e3ce14
to
7cd21b5
Compare
"""Check equality.""" | ||
if not isinstance(other, self.__class__): | ||
return NotImplemented # Delegate comparison to the other instance's __eq__. | ||
return all(getattr(self, s) == getattr(other, s) for s in self.__slots__[:-1]) |
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.
including the _package_hash
will affect the functionality in the following 4 places, which is why I chose not to include it now (it was not included in the original comparison either). We may choose to open an issue on this if we want to change this later.
eject
Lines 204 to 206 in 77474ff
reverse_reachable_dependencies = reachable_nodes( reverse_dependencies, {package_id.without_hash()} ) remove
Lines 193 to 226 in 77474ff
def get_item_dependencies_with_reverse_dependencies( self, item: PackageConfiguration, package_id: Optional[PackageId] = None ) -> Dict[PackageId, Set[PackageId]]: """ Get item dependencies. It's recursive and provides all the sub dependencies. :param item: the item package configuration :param package_id: the package id. :return: dict with PackageId: and set of PackageIds that uses this package """ result: defaultdict = defaultdict(set) for dep_package_id in self._get_item_requirements( item, self._ignore_non_vendor ): if package_id is None: _ = result[dep_package_id.without_hash()] # init default dict value else: result[dep_package_id.without_hash()].add(package_id.without_hash()) if not self.is_present_in_agent_config( dep_package_id.without_hash() ): # pragma: nocover continue dep_item = self.get_item_config(dep_package_id) for item_key, deps in self.get_item_dependencies_with_reverse_dependencies( dep_item, dep_package_id ).items(): result[item_key.without_hash()] = result[item_key].union(deps) return result check_packages
open-aea/aea/cli/check_packages.py
Lines 309 to 310 in 77474ff
def _add_package_type(package_type: PackageType, public_id_str: str) -> PackageId: return PackageId(package_type, PublicId.from_str(public_id_str)) registry/add
open-aea/aea/cli/registry/add.py
Lines 31 to 72 in 77474ff
def fetch_package(obj_type: str, public_id: PublicId, cwd: str, dest: str) -> Path: """ Fetch a package (connection/contract/protocol/skill) from Registry. :param obj_type: str type of object you want to fetch: 'connection', 'protocol', 'skill' :param public_id: str public ID of object. :param cwd: str path to current working directory. :param dest: destination where to save package. :return: package path """ logger.debug( "Fetching {obj_type} {public_id} from Registry...".format( public_id=public_id, obj_type=obj_type ) ) logger.debug( "Downloading {obj_type} {public_id}...".format( public_id=public_id, obj_type=obj_type ) ) package_meta = get_package_meta(obj_type, public_id) file_url = cast(str, package_meta["file"]) filepath = download_file(file_url, cwd) # next code line is needed because the items are stored in tarball packages as folders dest = os.path.split(dest)[0] logger.debug( "Extracting {obj_type} {public_id}...".format( public_id=public_id, obj_type=obj_type ) ) extract(filepath, dest) logger.debug( "Successfully fetched {obj_type} '{public_id}'.".format( public_id=public_id, obj_type=obj_type ) ) package_path = os.path.join(dest, public_id.name) return Path(package_path)
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.
Please open an issue for this and add a comment in code.
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.
No longer failing the following (was so after 3b27e78 - see CI run)
all remaining failures are those related to newly introduced tests in base PR #428
|
__eq__
__eq__
implementation on the data types
__eq__
implementation on the data types__eq__
implementation on the data types
__eq__
implementation on the data types__eq__
implementation on the data types
08025c6
to
24d3fd1
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## tests/test_data_types #445 +/- ##
========================================================
Coverage ? 97.31%
========================================================
Files ? 221
Lines ? 19540
Branches ? 0
========================================================
Hits ? 19016
Misses ? 524
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
LGTM
…nLike Fix/delegate `__lt__` to `PackageVersionLike`
Add deflection to custom `__lt__` and add `functools.total_ordering`
Proposed changes
Updating the implementation of custom
__eq__
methods on custom data types:PackageVersion
,PublicId
,PackageId
andDependency
.as per base PR description: #428
and for reference: googleapis/google-cloud-python#3455
Fixes
If it fixes a bug or resolves a feature request, be sure to link to that issue.
Types of changes
What types of changes does your code introduce to agents-aea?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply.develop
branch (left side). Also you should start your branch off ourdevelop
.Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...