From 6b56611aa98031191c0b02aadb30af5a203f8212 Mon Sep 17 00:00:00 2001 From: Max Vorobev Date: Tue, 26 Feb 2019 18:00:02 +0300 Subject: [PATCH] Fix package name and version (#16) ## What is the goal of this PR? Complying with CI/CD plan outlined [here](http://tinyurl.com/GraknCICDSpreadsheet), we're renaming `grakn` to `grakn-client` and are using updated `@graknlabs_bazel_distribution` which stamp the `git` version to snapshot packages ## What are the changes implemented in this PR? - rename `grakn` to `grakn-client` - update commit hash of `@graknlabs_bazel_distribution` - update commit hash of `@graknlabs_grakn_core` --- BUILD | 2 +- VERSION | 2 +- WORKSPACE | 7 +- grakn/__init__.py | 8 +-- .../Session/Concept/BaseTypeMapping.py | 8 +-- grakn/service/Session/Concept/Concept.py | 52 +++++++-------- .../service/Session/Concept/ConceptFactory.py | 6 +- grakn/service/Session/TransactionService.py | 8 +-- grakn/service/Session/util/RequestBuilder.py | 5 +- grakn/service/Session/util/ResponseReader.py | 4 +- tests/integration/test_concept.py | 66 +++++++++---------- tests/integration/test_grakn.py | 14 ++-- tests/notes.md | 2 +- 13 files changed, 90 insertions(+), 94 deletions(-) diff --git a/BUILD b/BUILD index d23d0f4c..b4fb98d5 100644 --- a/BUILD +++ b/BUILD @@ -51,7 +51,7 @@ py_library( deploy_pip( name = "deploy-pip", - package_name = "grakn", + package_name = "grakn-client", version_file = "//:VERSION", classifiers = [ "Programming Language :: Python", diff --git a/VERSION b/VERSION index c831dd27..d6553625 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.5.0.dev1 +1.5.0-SNAPSHOT diff --git a/WORKSPACE b/WORKSPACE index 9eb3d231..23cde7f7 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,7 +3,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") git_repository( name = "graknlabs_grakn_core", remote = "https://github.com/graknlabs/grakn", - commit = "ec41e803e3a12696cec731ad6071c26e90cea926" + commit = "2091602fbcca45823d2bc3d5062ce7cdb6b25b89" ) git_repository( @@ -28,7 +28,7 @@ python_grpc_compile() git_repository( name="graknlabs_bazel_distribution", remote="https://github.com/graknlabs/bazel-distribution", - commit="18d774e16187bd4148fe36842b68bafa46017d6f" + commit="3fff34b151afabaee5af7ffb35ed99e52747c932" ) pip_import( @@ -79,3 +79,6 @@ graql_dependencies() load("@stackb_rules_proto//java:deps.bzl", "java_grpc_compile") java_grpc_compile() + +load("@graknlabs_grakn_core//dependencies/docker:dependencies.bzl", "docker_dependencies") +docker_dependencies() diff --git a/grakn/__init__.py b/grakn/__init__.py index 7a8695b8..8a0832e2 100644 --- a/grakn/__init__.py +++ b/grakn/__init__.py @@ -166,10 +166,10 @@ def put_entity_type(self, label): return self._tx_service.put_entity_type(label) put_entity_type.__annotations__ = {'label': str} - def put_relationship_type(self, label): - """ Define a new relationship type with the given label """ - return self._tx_service.put_relationship_type(label) - put_relationship_type.__annotations__ = {'label': str} + def put_relation_type(self, label): + """ Define a new relation type with the given label """ + return self._tx_service.put_relation_type(label) + put_relation_type.__annotations__ = {'label': str} def put_attribute_type(self, label, data_type): """ Define a new attribute type with the given label and data type diff --git a/grakn/service/Session/Concept/BaseTypeMapping.py b/grakn/service/Session/Concept/BaseTypeMapping.py index 464aaee8..94e5faa1 100644 --- a/grakn/service/Session/Concept/BaseTypeMapping.py +++ b/grakn/service/Session/Concept/BaseTypeMapping.py @@ -21,8 +21,8 @@ # base type constant names -CONCEPTS = META_TYPE, ATTRIBUTE_TYPE, RELATIONSHIP_TYPE, ENTITY_TYPE, ENTITY, ATTRIBUTE, RELATIONSHIP, ROLE, RULE = \ - "META_TYPE", "ATTRIBUTE_TYPE", "RELATIONSHIP_TYPE", "ENTITY_TYPE", "ENTITY", "ATTRIBUTE", "RELATIONSHIP", "ROLE", "RULE" +CONCEPTS = META_TYPE, ATTRIBUTE_TYPE, RELATION_TYPE, ENTITY_TYPE, ENTITY, ATTRIBUTE, RELATION, ROLE, RULE = \ + "META_TYPE", "ATTRIBUTE_TYPE", "RELATION_TYPE", "ENTITY_TYPE", "ENTITY", "ATTRIBUTE", "RELATION", "ROLE", "RULE" """ NOTE: the string META_TYPE is the name of the programmatic type of @@ -39,12 +39,12 @@ grpc_base_type_to_name = { grpc_base_types.Value("META_TYPE"): META_TYPE, grpc_base_types.Value("ENTITY_TYPE"): ENTITY_TYPE, - grpc_base_types.Value("RELATION_TYPE"): RELATIONSHIP_TYPE, + grpc_base_types.Value("RELATION_TYPE"): RELATION_TYPE, grpc_base_types.Value("ATTRIBUTE_TYPE"): ATTRIBUTE_TYPE, grpc_base_types.Value("ROLE"): ROLE, grpc_base_types.Value("RULE"): RULE, grpc_base_types.Value("ENTITY"): ENTITY, - grpc_base_types.Value("RELATION"): RELATIONSHIP, + grpc_base_types.Value("RELATION"): RELATION, grpc_base_types.Value("ATTRIBUTE"): ATTRIBUTE } diff --git a/grakn/service/Session/Concept/Concept.py b/grakn/service/Session/Concept/Concept.py index ac98e9e8..912c8fb8 100644 --- a/grakn/service/Session/Concept/Concept.py +++ b/grakn/service/Session/Concept/Concept.py @@ -62,10 +62,10 @@ def is_entity_type(self): return isinstance(self, EntityType) is_entity_type.__annotations__ = {'return': bool} - def is_relationship_type(self): - """ Check if this concept is a RelationshipType concept """ - return isinstance(self, RelationshipType) - is_relationship_type.__annotations__ = {'return': bool} + def is_relation_type(self): + """ Check if this concept is a RelationType concept """ + return isinstance(self, RelationType) + is_relation_type.__annotations__ = {'return': bool} def is_role(self): """ Check if this concept is a Role """ @@ -87,10 +87,10 @@ def is_entity(self): return isinstance(self, Entity) is_entity.__annotations__ = {'return': bool} - def is_relationship(self): - """ Check if this concept is a Relationship concept """ - return isinstance(self, Relationship) - is_relationship.__annotations__ = {'return': bool} + def is_relation(self): + """ Check if this concept is a Relation concept """ + return isinstance(self, Relation) + is_relation.__annotations__ = {'return': bool} class SchemaConcept(Concept): @@ -351,20 +351,17 @@ def regex(self, pattern=None): regex.__annotations__ = {'pattern': str} -class RelationshipType(Type): - - # NOTE: `relation` not `relationship` used in RequestBuilder already - +class RelationType(Type): def create(self): - """ Create an instance of a relationship with this type """ + """ Create an instance of a relation with this type """ create_rel_inst_req = RequestBuilder.ConceptMethod.RelationType.create() method_response = self._tx_service.run_concept_method(self.id, create_rel_inst_req) - grpc_relationship_concept = method_response.relationType_create_res.relation + grpc_relation_concept = method_response.relationType_create_res.relation from grakn.service.Session.Concept import ConceptFactory - return ConceptFactory.create_concept(self._tx_service, grpc_relationship_concept) + return ConceptFactory.create_concept(self._tx_service, grpc_relation_concept) def roles(self): - """ Retrieve roles in this relationship schema type """ + """ Retrieve roles in this relation schema type """ get_roles = RequestBuilder.ConceptMethod.RelationType.roles() method_response = self._tx_service.run_concept_method(self.id, get_roles) from grakn.service.Session.util import ResponseReader @@ -379,13 +376,13 @@ def roles(self): def relates(self, role): - """ Set a role in this relationship schema type """ + """ Set a role in this relation schema type """ relates_req = RequestBuilder.ConceptMethod.RelationType.relates(role) method_response = self._tx_service.run_concept_method(self.id, relates_req) return self def unrelate(self, role): - """ Remove a role in this relationship schema type """ + """ Remove a role in this relation schema type """ unrelate_req = RequestBuilder.ConceptMethod.RelationType.unrelate(role) method_response = self._tx_service.run_concept_method(self.id, unrelate_req) return self @@ -420,9 +417,8 @@ def get_then(self): class Role(SchemaConcept): - def relationships(self): - """ Retrieve relationships that this role participates in, as an iterator """ - # NOTE: relations vs relationships here + def relations(self): + """ Retrieve relations that this role participates in, as an iterator """ relations_req = RequestBuilder.ConceptMethod.Role.relations() method_response = self._tx_service.run_concept_method(self.id, relations_req) from grakn.service.Session.util import ResponseReader @@ -464,9 +460,8 @@ def type(self): from grakn.service.Session.Concept import ConceptFactory return ConceptFactory.create_concept(self._tx_service, method_response.thing_type_res.type) - def relationships(self, *roles): - """ Get iterator this Thing's relationships, filtered to the optionally provided roles """ - # NOTE `relations` rather than `relationships` + def relations(self, *roles): + """ Get iterator this Thing's relations, filtered to the optionally provided roles """ relations_req = RequestBuilder.ConceptMethod.Thing.relations(roles) method_response = self._tx_service.run_concept_method(self.id, relations_req) from grakn.service.Session.util import ResponseReader @@ -558,12 +553,11 @@ def owners(self): ConceptFactory.create_concept(tx_service, iter_res.conceptMethod_iter_res.attribute_owners_iter_res.thing) ) -class Relationship(Thing): - # NOTE `relation` has replaced `relationship` in ResponseBuilder +class Relation(Thing): def role_players_map(self): - """ Retrieve dictionary {role : set(players)} for this relationship """ + """ Retrieve dictionary {role : set(players)} for this relation """ role_players_map_req = RequestBuilder.ConceptMethod.Relation.role_players_map() method_response = self._tx_service.run_concept_method(self.id, role_players_map_req) @@ -616,13 +610,13 @@ def role_players(self, *roles): def assign(self, role, thing): - """ Assign an entity to a role on this relationship instance """ + """ Assign an entity to a role on this relation instance """ assign_req = RequestBuilder.ConceptMethod.Relation.assign(role, thing) method_response = self._tx_service.run_concept_method(self.id, assign_req) return self def unassign(self, role, thing): - """ Un-assign an entity from a role on this relationship instance """ + """ Un-assign an entity from a role on this relation instance """ unassign_req = RequestBuilder.ConceptMethod.Relation.unassign(role, thing) method_response = self._tx_service.run_concept_method(self.id, unassign_req) return self diff --git a/grakn/service/Session/Concept/ConceptFactory.py b/grakn/service/Session/Concept/ConceptFactory.py index 7d6426ce..d0813185 100644 --- a/grakn/service/Session/Concept/ConceptFactory.py +++ b/grakn/service/Session/Concept/ConceptFactory.py @@ -18,19 +18,19 @@ # from grakn.service.Session.Concept import BaseTypeMapping -from grakn.service.Session.Concept.Concept import EntityType, RelationshipType, AttributeType, Role, Rule, Entity, Relationship, Attribute, Type +from grakn.service.Session.Concept.Concept import EntityType, RelationType, AttributeType, Role, Rule, Entity, Relation, Attribute, Type # map names to ConceptHierarchy types name_to_object = { BaseTypeMapping.META_TYPE: Type, BaseTypeMapping.ENTITY_TYPE: EntityType, - BaseTypeMapping.RELATIONSHIP_TYPE: RelationshipType, + BaseTypeMapping.RELATION_TYPE: RelationType, BaseTypeMapping.ATTRIBUTE_TYPE: AttributeType, BaseTypeMapping.ROLE: Role, BaseTypeMapping.RULE: Rule, BaseTypeMapping.ENTITY: Entity, - BaseTypeMapping.RELATIONSHIP: Relationship, + BaseTypeMapping.RELATION: Relation, BaseTypeMapping.ATTRIBUTE: Attribute } diff --git a/grakn/service/Session/TransactionService.py b/grakn/service/Session/TransactionService.py index 79252b60..e2d5966f 100644 --- a/grakn/service/Session/TransactionService.py +++ b/grakn/service/Session/TransactionService.py @@ -86,11 +86,11 @@ def put_entity_type(self, label): return ResponseReader.ResponseReader.put_entity_type(self, response.putEntityType_res) put_entity_type.__annotations__ = {'label': str} - def put_relationship_type(self, label): - request = RequestBuilder.put_relationship_type(label) + def put_relation_type(self, label): + request = RequestBuilder.put_relation_type(label) response = self._communicator.send(request) - return ResponseReader.ResponseReader.put_relationship_type(self, response.putRelationType_res) - put_relationship_type.__annotations__ = {'label': str} + return ResponseReader.ResponseReader.put_relation_type(self, response.putRelationType_res) + put_relation_type.__annotations__ = {'label': str} def put_attribute_type(self, label, data_type): request = RequestBuilder.put_attribute_type(label, data_type) diff --git a/grakn/service/Session/util/RequestBuilder.py b/grakn/service/Session/util/RequestBuilder.py index 96e65918..874595f7 100644 --- a/grakn/service/Session/util/RequestBuilder.py +++ b/grakn/service/Session/util/RequestBuilder.py @@ -118,8 +118,7 @@ def put_entity_type(label): return transaction_req @staticmethod - def put_relationship_type(label): - # NOTE: Relation vs relationship + def put_relation_type(label): put_relation_type_req = transaction_messages.Transaction.PutRelationType.Req() put_relation_type_req.label = label transaction_req = transaction_messages.Transaction.Req() @@ -582,7 +581,7 @@ def unhas(attribute_concept): return concept_method_req class Relation(object): - """ Generates Relation (aka Relationship) method messages """ + """ Generates Relation method messages """ @staticmethod def role_players_map(): diff --git a/grakn/service/Session/util/ResponseReader.py b/grakn/service/Session/util/ResponseReader.py index 0dddecb5..3d71d32e 100644 --- a/grakn/service/Session/util/ResponseReader.py +++ b/grakn/service/Session/util/ResponseReader.py @@ -69,8 +69,8 @@ def put_entity_type(tx_service, grpc_put_entity_type): return ConceptFactory.create_concept(tx_service, grpc_put_entity_type.entityType) @staticmethod - def put_relationship_type(tx_service, grpc_put_relationship_type): - return ConceptFactory.create_concept(tx_service, grpc_put_relationship_type.relationType) + def put_relation_type(tx_service, grpc_put_relation_type): + return ConceptFactory.create_concept(tx_service, grpc_put_relation_type.relationType) @staticmethod def put_attribute_type(tx_service, grpc_put_attribute_type): diff --git a/tests/integration/test_concept.py b/tests/integration/test_concept.py index b2ef7042..98b10ac6 100644 --- a/tests/integration/test_concept.py +++ b/tests/integration/test_concept.py @@ -48,7 +48,7 @@ def setUpClass(cls): "person sub entity, has age, has gender, plays parent, plays child, plays mother, plays son; " "age sub attribute, datatype long; " "gender sub attribute, datatype string; " - "parentship sub relationship, relates parent, relates child, relates mother, relates son;") + "parentship sub relation, relates parent, relates child, relates mother, relates son;") except GraknError as ce: print(ce) @@ -102,19 +102,19 @@ def test_is_each_schema_type(self): car = car_type.create() self.assertTrue(car.is_entity()) self.assertFalse(car.is_attribute()) - self.assertFalse(car.is_relationship()) + self.assertFalse(car.is_relation()) - rel_type = self.tx.put_relationship_type("owner") + rel_type = self.tx.put_relation_type("owner") owner = rel_type.create() self.assertFalse(owner.is_entity()) self.assertFalse(owner.is_attribute()) - self.assertTrue(owner.is_relationship()) + self.assertTrue(owner.is_relation()) attr_type = self.tx.put_attribute_type("age", grakn.DataType.LONG) age = attr_type.create(50) self.assertFalse(age.is_entity()) self.assertTrue(age.is_attribute()) - self.assertFalse(age.is_relationship()) + self.assertFalse(age.is_relation()) class test_SchemaConcept(test_concept_Base): """ Test methods available on all SchemaConcepts """ @@ -346,26 +346,26 @@ def test_regex(self): self.assertEqual(regex, "(good|bad)-dog") -class test_RelationshipType(test_concept_Base): +class test_RelationType(test_concept_Base): def test_create(self): - rel_type = self.tx.put_relationship_type("owner") + rel_type = self.tx.put_relation_type("owner") rel = rel_type.create() - self.assertTrue(rel.is_relationship()) - self.assertTrue(rel_type.is_relationship_type()) + self.assertTrue(rel.is_relation()) + self.assertTrue(rel_type.is_relation_type()) def test_relates(self): - """ Test get/relate/unrelate roles for a relationship type """ - ownership = self.tx.put_relationship_type("ownership") + """ Test get/relate/unrelate roles for a relation type """ + ownership = self.tx.put_relation_type("ownership") role_owner = self.tx.put_role("owner") role_owned = self.tx.put_role("owned") with self.subTest(i=0): - # currently no roles in the new relationship + # currently no roles in the new relation roles = list(ownership.roles()) self.assertEqual(len(roles), 0) with self.subTest(i=1): - # set roles in relationship + # set roles in relation ownership.relates(role_owner) ownership.relates(role_owned) roles = list(ownership.roles()) @@ -399,17 +399,17 @@ def test_none_when_then(self): class test_Role(test_concept_Base): - def test_relationships(self): - """ Test retrieving relationships of a role """ + def test_relations(self): + """ Test retrieving relations of a role """ # parent role, parentship already exist result = self.tx.query("match $x type parent; get;").collect_concepts() parent_role = result[0] self.assertEqual(parent_role.base_type, "ROLE") - relationships = list(parent_role.relationships()) - self.assertEqual(len(relationships), 1) - self.assertEqual(relationships[0].base_type, "RELATIONSHIP_TYPE") - self.assertEqual(relationships[0].label(), "parentship") + relations = list(parent_role.relations()) + self.assertEqual(len(relations), 1) + self.assertEqual(relations[0].base_type, "RELATION_TYPE") + self.assertEqual(relations[0].label(), "parentship") def test_players(self): """ Test retrieving entity types playing this role """ @@ -437,48 +437,48 @@ def test_type(self): self.assertEqual(p_type.id, person_type.id) # same schema concept self.assertTrue(p_type.is_type()) - def test_relationships(self): - """ Test retrieve relationships narrowed optionally by roles """ - # create a first relationship - sibling_type = self.tx.put_relationship_type('sibling') + def test_relations(self): + """ Test retrieve relations narrowed optionally by roles """ + # create a first relation + sibling_type = self.tx.put_relation_type('sibling') brother_role = self.tx.put_role("brother") sibling_type.relates(brother_role) person = self.tx.get_schema_concept("person") - # create a second relationship - ownership_type = self.tx.put_relationship_type("ownership") + # create a second relation + ownership_type = self.tx.put_relation_type("ownership") owner_role = self.tx.put_role("owner") ownership_type.relates(owner_role) person.plays(owner_role) - # connect entities/relationship instances + # connect entities/relation instances sibling = sibling_type.create() ownership = ownership_type.create() son = person.create() sibling.assign(brother_role, son) # assign son to sibling rel ownership.assign(owner_role, son) # attach son to owner rel - # retrieve all relationships - rels = list(son.relationships()) + # retrieve all relations + rels = list(son.relations()) self.assertEqual(len(rels), 2) rel_ids = [rel.id for rel in rels] self.assertTrue(sibling.id in rel_ids and ownership.id in rel_ids) # retrieve filtered by only the owner role - filtered_rels = list(son.relationships(owner_role)) + filtered_rels = list(son.relations(owner_role)) self.assertEqual(len(filtered_rels), 1) self.assertEqual(filtered_rels[0].id, ownership.id) def test_roles(self): - # create a relationship - ownership_type = self.tx.put_relationship_type("ownership") + # create a relation + ownership_type = self.tx.put_relation_type("ownership") owner_role = self.tx.put_role("owner") ownership_type.relates(owner_role) person_type = self.tx.get_schema_concept("person") person_type.plays(owner_role) - # connect entities/relationship instances + # connect entities/relation instances ownership = ownership_type.create() person = person_type.create() ownership.assign(owner_role, person) # attach son to owner rel @@ -621,7 +621,7 @@ def test_owners(self): self.assertTrue(person.id in labels and animal.id in labels) -class test_Relationship(test_concept_Base): +class test_Relation(test_concept_Base): def test_role_players_2_roles_1_player(self): """ Test role_players_map and role_players with 2 roles and 1 player each """ diff --git a/tests/integration/test_grakn.py b/tests/integration/test_grakn.py index 38f6b56b..f413e2ac 100644 --- a/tests/integration/test_grakn.py +++ b/tests/integration/test_grakn.py @@ -117,7 +117,7 @@ def setUpClass(cls): "person sub entity, has age, has gender, plays parent, plays child, plays mother, plays son; " "age sub attribute, datatype long; " "gender sub attribute, datatype string; " - "parentship sub relationship, relates parent, relates child, relates mother, relates son;") + "parentship sub relation, relates parent, relates child, relates mother, relates son;") except GraknError as ce: print(ce) @@ -190,7 +190,7 @@ def test_aggr_count_empty_graph_anwer_Value(self): @staticmethod def _build_parentship(tx): """ Helper to set up some state to test answers in a tx/keyspace """ - parentship_type = tx.put_relationship_type("parentship") + parentship_type = tx.put_relation_type("parentship") parentship = parentship_type.create() parent_role = tx.put_role("parent") child_role = tx.put_role("child") @@ -373,11 +373,11 @@ def test_put_entity_type(self): self.assertTrue(dog_entity_type.is_entity_type()) - def test_put_relationship_type(self): - """ Test putting a schema relationship type """ - marriage_type = self.tx.put_relationship_type('marriage') + def test_put_relation_type(self): + """ Test putting a schema relation type """ + marriage_type = self.tx.put_relation_type('marriage') self.assertTrue(marriage_type.is_schema_concept()) - self.assertTrue(marriage_type.is_relationship_type()) + self.assertTrue(marriage_type.is_relation_type()) def test_put_attribute_type(self): """ Test putting a new attribtue type in schema """ @@ -394,7 +394,7 @@ def test_put_role(self): def test_put_rule(self): """ Test adding a rule for genderized parentship""" - # create a role which creates a trivial "ancestor" relationship + # create a role which creates a trivial "ancestor" relation label = "genderizedparentship" when = "{ (parent: $p, child: $c) isa parentship; $p has gender 'female'; $c has gender 'male'; };" then = "{ (mother: $p, son: $c) isa parentship; };" diff --git a/tests/notes.md b/tests/notes.md index 2f99cf2b..81aead82 100644 --- a/tests/notes.md +++ b/tests/notes.md @@ -22,7 +22,7 @@ SessionTest(): -- setup -- * define simple schema -* insert a couple of entities/attributes/relationships +* insert a couple of entities/attributes/relations TransactionTest():