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

Adding GitImplementation of Ground and tests #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

avinash-arjavalingam
Copy link

Added the ground.py file, originally from https://github.com/ucbrise/jarvis, now with all datatypes implemented and all the GitImplementation methods completed, as well as adding unimplemented methods for the GroundAPI abstract class, and making some minor fixes along the way. Also, the testing file test_ground.py was added, which can be run from the command line with python 2 as 'python test_ground.py'. It contains comprehensive testing for the datatypes and GitImplementation.

Copy link
Member

@vsreekanti vsreekanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these files shouldn't be in the home directory. They should be organized under the python directory in this repo.

I think we need to chat about this a little more. I don't see anything in the code that uses the commit method or the git library imported at the top. Everything is being stored in memory, which defeats the purpose of using git. Let me know if I'm misreading how this works.

ground.py Outdated
from shutil import copyfile


class Node:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these classes are already implemented in python/ground/common/model. We shouldn't duplicate them.

ground.py Outdated
if (nodeId in self.graph.nodes):
node = self.graph.nodes[nodeId]
nodeVersion = NodeVersion(node, reference, referenceParameters, tags, structureVersionId, parentIds)
# else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Jarvis specific stuff. We should remove this.

ground.py Outdated

### EDGES ###

def createEdge(self, sourceKey, fromNodeId, toNodeId, name="null", tags=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but none of these methods are actually using git commands. We're returning heap objects which won't persist across multiple API calls.

ground.py Outdated
def getLineageGraphVersion(self, lineageGraphVersionId):
return self.graph.lineageGraphVersions[lineageGraphVersionId]

def commit(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't see this commit method used anywhere.

Copy link
Member

@vsreekanti vsreekanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good. Most of my questions are about code cleanup and style. One more quick revision should do the trick!

from shutil import copyfile
# noinspection PyUnresolvedReferences
from ground.common.model.core.node import Node
# noinspection PyUnresolvedReferences
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these comments?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are just for my IDE, PyCharm, so it doesn't stop a run for errors. For whatever reason, PyCharm doesn't recognize the importing of local packages, so it will show an error that is not really there. I can remove those if that is preferable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please remove them from the code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump on this.

"""
Abstract class: do not instantiate
"""

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Extra whitespace.


class GitImplementation(GroundAPI):
def __init__(self):
#self.nodes = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is unnecessary, we should remove.

def _gen_id(self):
with open(self.path + 'ids.json', 'r') as f:
ids = json.loads(f.read())
newid = len(ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just store an integer?

f2.write(json.dumps(ids))
return newid

def _write_files(self, id, body):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reuse this fn in _gen_id?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And _read_files below.)

return str(output, 'UTF-8')

def _check_init(self):
if(not self.initialized):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I created a repo a long time ago and am reusing it now? How do I know that it's been initialized?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .init() method will automatically check for previous initialization and will call init again which is safe but will not replace the repo and your existing work. The ids will carry on with the highest id and continue, not replacing older files. However, this implementation does not handle the case where the folder has been previously manually created, then initialized to some other repo with previous commits that have no relation to the ground objects, it will just continue to commit to that initial repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine for now. Let's add a README.md to the directory with documentation like this.

body["toNodeId"] = toNodeId
edge = Edge(body)
edgeId = edge.get_id()
#self.edges[sourceKey] = edge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Cleanup commented out code.

def createNode(self, sourceKey, name="null", tags=None):
self._check_init()
if not self._find_file(sourceKey, Node.__name__):
body = self._create_item(Node.__name__, sourceKey, name, tags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to be reusing the class names a lot here. Not necessarily a bad thing, but can we think of a more efficient solution?

self._check_init()
return self._read_version(lineageGraphVersionId, LineageGraphVersion.__name__)

"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit about commented code.

os.chdir('../' + str(int(prevDir) + 1))
"""

class GroundImplementation(GroundAPI):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holdover from the file in jarvis, unnecessary and will delete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants