Skip to content

23 convert to pygit2 - #24

Draft
uirmaksever wants to merge 9 commits into
mainfrom
23-convert-to-pygit2
Draft

23 convert to pygit2#24
uirmaksever wants to merge 9 commits into
mainfrom
23-convert-to-pygit2

Conversation

@uirmaksever

Copy link
Copy Markdown
Collaborator
  • All pull and push operations are handled via pygit2.
  • os.chdir() calls have been removed and file path operations handled via os.path.join calls with absolute paths.

Two changes have been made to test files:

  • ../demo/projects changed into demo/projects
  • selecting annotation collections in tests made with ac_name values instead of index of ac_name list, since gold annotation collection is empty for demo project.

@uirmaksever uirmaksever self-assigned this Aug 31, 2026

@ypislon ypislon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey Umut, thanks for the PR! The replacement of subprocess works for me and looks great already! I have found a few more places where we can do some work, e.g. use os.path.join and some spots where the error handling could be improved. I also had some questions, would be great if you can comment my review here :)

Comment thread gitma/_gold_annotation.py Outdated
subprocess.run(['git', 'add', '.'])
subprocess.run(['git', 'commit', '-m', 'new gold annotations'])
subprocess.run(['git', 'push', 'origin', 'HEAD:master'])
gold_ac.push_annotations(commit_message='new gold annotations')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could add a more specific message here for the commit. This way, users who inspect their repository could have a better overview. My suggestion would be:

gold_ac.push_annotations(commit_message=f'Added {copied_annotations} gold annotations into annotation collection '{gold_ac_name}'.)

Comment thread gitma/_gold_annotation.py Outdated
# os.chdir(f'{project.projects_directory}{project.uuid}/collections/{gold_uuid}')
# subprocess.run(['git', 'add', '.'])
# subprocess.run(['git', 'commit', '-m', 'new gold annotations'])
# subprocess.run(['git', 'push', 'origin', 'HEAD:master'])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was wondering if we can remove the lines with the calls to subprocess.

Comment thread gitma/_write_annotation.py Outdated
new_annotation_uuid = uuid_override

tag_relative_path = tag.path[tag.path.index('/')+1:tag.path.rindex('/')]
tag_relative_path = os.path.relpath(tag.path, project_path).replace('\\', '/')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this is a workaround to be able to work with both Linux and Windows filepaths, a short comment on why we replace the slashes would be great.

Comment thread gitma/_write_annotation.py Outdated
new_annotation_uuid = uuid_override

tag_relative_path = tag.path[tag.path.index('/')+1:tag.path.rindex('/')]
tag_relative_path = os.path.relpath(tag.path, project_path).replace('\\', '/')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What would happen if the tagset or tag doesn't exist? We could add a short error message to the find_tagset_by_name and find_tag_by_name methods and let the user know which tagsets/tags exist in the respective project/tagset.

Comment thread gitma/project.py Outdated
if repo.index.conflicts is not None:
for conflict in repo.index.conflicts:
print('Conflicts found in:', conflict[0].path)
raise AssertionError('Conflicts have been found, pull aborted. Please resolve conflicts.')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are we using the AssertionError error class here? Could we use a general error as well?

Comment thread gitma/annotation_collection.py
Comment thread gitma/_write_annotation.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could use os.path.join here as well.

Comment thread gitma/project.py Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we use os.path.join here as well to construct the path?

Comment thread gitma/tagset.py Outdated
self.path: str = os.path.join(project_uuid, 'tagsets', tagset_uuid)

try:
with open(self.path + '/header.json', 'r', encoding='utf-8', newline='') as header_input:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We could use os.path.join here as well.

@ypislon ypislon Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this file should be removed (or moved with the test_pygit2.ipynb notebook).

@ypislon
ypislon removed the request for review from maltem-za September 1, 2026 13:28
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.

2 participants