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

#46 git import #78

Merged
merged 23 commits into from
May 25, 2020
Merged

#46 git import #78

merged 23 commits into from
May 25, 2020

Conversation

evolverine
Copy link
Contributor

A few notes:

  • you can ignore the first four commits. I made them when I wasn't yet aware that Dulwich was already a dependency of this project, and I was including GitPython. This is reverted in d502c48
  • commit e72ef09 introduces a change in the directory structure that the repository is created in: instead of "CrowdAnki/repo_name/git" it uses "CrowdAnki/user_name/repo_name/". This is reverted in the last commits, but I do want to ask you about it, because I think it's much better to use the github username in the path, to avoid naming conflicts. What do you think, will this also impact on other parts of the add-on?
  • the feature we have now is that we clone a repository instead of downloading the zip (and pull if the repository exists). I have not yet implemented the remote addition, but I'm happy to do it next if the direction seems good.

Also, two questions:

  1. Instead of the Anki profile directory, shouldn't we now use the directory in the plugin settings to clone the repository?
  2. For everyone but the repository maintainers the initially-cloned repository will have to be converted into a fork if they want to contribute any changes. Maybe we can automate that within this add-on using hub?

crowd_anki/utils/uuid.py Outdated Show resolved Hide resolved
crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
def download_and_import(self, repo):
def download_and_import_git(self, github_repo):
repo_parts = github_repo.split("/")
repo_dir = Path(self.collection.media.dir()).joinpath("..", "CrowdAnkiGit", repo_parts[-1], "git")
Copy link
Owner

Choose a reason for hiding this comment

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

For the directory I think the ideal option would be to clone things into the place where snapshots go (it's available in config). The format there is snapshot_dir/<anki profile name>/<deck name>

Deck name is a bit tricky - if you follow the convention of naming the repo with the CrowdAnki deck name like here https://github.com/Stvad/Software_Engineering__git then you can use that, but I suspect you don't (being not a fun of those names & all :p)

So another option can be is storing the snapshot destination on per deck basis. Something like:

  • If you're importing deck from git repo -> set snapshot destination to the original import directory
  • If it's not set -> set it to the default one
  • Use these names on snapshot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll admit that I didn't understand very well what you meant by the three bullet points above. Please see the commits I just pushed, and how they relate to what you suggest, thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have you had a chance to take a look? Thanks.

Copy link
Owner

Choose a reason for hiding this comment

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

Should be able to take a closer look today/tomorrow.

What the comment above was getting at that if the name of repository does not match the name of the deck - then initial import would work but subsequent snapshots will go to a different directory which is problematic. I proposed a way to solve that by changing how we determine the snapshot directory for deck

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But the name of the repository does not determine the name of the deck: when importing from github, the deck name is taken from deck.json So even if I import the "covid-19-anki-deck, the deck I see in Anki is "COVID-19" (in fact, I see "COVID-19_2", "COVID-19_3", etc, but right now that's beyond the point). Indeed, though, the name of the imported repository directory will be covid-19-anki-deck, so I see your point.

Nevertheless, the user can rename the deck to something wildly different, and they can also move the cards in and out of it at will. Being driven by the deck name will lead to a multitude of issues.

The way it would make the most sense for me for all this to happen is if each deck had a property called remote_url or something like that, which pointed to (either the original, or to the forked) remote repository. Then we'd use this property to determine the directory names for the repositories.
I'm not familiar enough with the Anki codebase to know whether that's something that could be implemented?

crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
@Stvad
Copy link
Owner

Stvad commented Mar 30, 2020

Integrating with github to create forks/etc - In general seems like a good idea for simplifying the flow, we should discuss how interaction would look like before going there though. And should be a separate CR.

Also using the actual cli tool really makes life harder distribution-wise, I imagine there is python lib out there for talking to Github API, which would be a better choice

@evolverine
Copy link
Contributor Author

agreed, a python library would be great for that.

self.addon_manager = addon_manager or mw.addonManager
self._config = init_values or addon_manager.getConfig(__name__)
self._window = window
Copy link
Owner

Choose a reason for hiding this comment

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

this should be initialized similar to the addon_manage (i.e. be assigned mw by default) also probably should be a more specific dependency - does pm stands for something like profile_manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like this? (see the latest commit)

crowd_anki/config/config_settings.py Outdated Show resolved Hide resolved
crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
crowd_anki/github/github_importer.py Show resolved Hide resolved
crowd_anki/github/github_importer.py Outdated Show resolved Hide resolved
@katrinleinweber
Copy link
Contributor

[…] python lib […] for talking to Github API

[…] would be great for that.

Have you found developer.github.com/v3/libraries? It has a Python section, of which PyGithub seems to be quite API-complete :-)

@evolverine
Copy link
Contributor Author

Thanks @katrinleinweber for researching the libraries. Can't wait to have this implemented. For now, let's finalize this pull request.

@evolverine
Copy link
Contributor Author

@Stvad did you have a chance to take a look at the commits? Thanks.

@Stvad
Copy link
Owner

Stvad commented May 6, 2020

@evolverine I apologize for the delay, I thought I did, but I missed the latest batch. I'll take a look in the next few days!

@Stvad
Copy link
Owner

Stvad commented May 9, 2020

Looks good to me besides the small nit that I've noted!

@evolverine
Copy link
Contributor Author

great. And check out the last commit as well, where I made improvements in the way the repository URL is parsed. If that looks good, on my side it's all done (otherwise let me know if any changes are in order).

@@ -8,6 +8,16 @@

BRANCH_NAME = "master"


def get_repository_name(repository_url):
repo_url_path = urlparse(repository_url).path
Copy link
Owner

Choose a reason for hiding this comment

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

what does using urlparse give us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, not much. I thought it could help in cases when the URL contains query parameters, but nothing in github seems to.

Comment on lines 16 to 17
if repo_name.find(" ") != -1:
raise ValueError("repository name in URL should not contain spaces")
Copy link
Owner

Choose a reason for hiding this comment

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

that's seems like an oddly specific thing to check for. should we just strip the string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took it out as well. I think the reason I was trying to validate the input so much was that Dulwich does create a folder and empty repository even when the URL is not correct, or does not contain a git repository. But we can handle that in other ways, perhaps.

…ameters. Also, checking for the space wasn't useful either; in that case, Dulwich will report an error

Signed-off-by: Mihai Chira <mihai.chira@gmail.com>
@evolverine
Copy link
Contributor Author

Heya, did you have a chance to look at the latest changes? Thanks!

@Stvad
Copy link
Owner

Stvad commented May 25, 2020

Hey, thank you for a reminder, been a bit swamped recently =. Will take a look today

@Stvad
Copy link
Owner

Stvad commented May 25, 2020

Looks good! Thank you for working on this! Sorry for a slow turn-around

@Stvad Stvad merged commit a42041f into Stvad:master May 25, 2020
@evolverine
Copy link
Contributor Author

Yaay! Calls for a celebration 😃️🎉️

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