Add gathering data from github #1

Open
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

No description provided.

Nice work! Thanks a lot.

I would like to keep in this repo only individual scripts, to leave people to get them and combine them to do their own stuff. So please remove the main, and leave it only on your repo. Also the init changes that you did to simplify the imports. Nothing wrong with them, just a personal preference of what to keep in this repo.

There is one thing I don't like about this. You are passing a dict that gets updated. That's called an output parameter, and sometimes it could be useful, but in general it should be avoided. The code is clearer, and simpler, if you just have one return value, and the caller takes care of using that value to update a variable, or something else.

Thank you!

README.md
+### Requirements:
+ * Python 2.7
+ * Urlparse
+ * Requests
@elopio

elopio Dec 5, 2017

Owner

This is just a collection of scripts that will be copied somewhere else. This README is great for your snapgatherer project, but it's not very useful here. What would be great here is to include the requirements on the header of each .py file. Nice job with this.

github/__init__.py
@@ -0,0 +1 @@
+from github.snapcraft import *
@elopio

elopio Dec 5, 2017

Owner

Please remove this from this pull request. Again, it's great for the tool you made from the scripts, not for this repo with just a bunch of scripts.

github/snapcraft.py
@@ -1,37 +1,122 @@
-#!/usr/bin/env python2
+#!/usr/bin/python2
@elopio

elopio Dec 5, 2017

Owner

Please revert this change. /usr/bin/env will support a python2 interpreter not installed in /usr/bin, like it happens with snaps.

github/snapcraft.py
- count[plugin] = 1
- snapcraft_yaml_file.close()
- return count
+_scriplets = ["prepare", "build", "install", "version-script"]
@elopio

elopio Dec 5, 2017

Owner

This is a constant, so it should be _SCRIPTLETS.
For consistency, please use only single quotes for strings, instead of double quotes.

github/snapcraft.py
-def _get_snapcraft_yaml_file(github_repo):
+def get_snapcraft_yaml_file(github_repo_url):
+ """
+ Extracts snapcraft file from reposutory
@elopio

elopio Dec 5, 2017

Owner

typo: repository

github/snapcraft.py
+ """
+ Extracts snapcraft file from reposutory
+ :param github_repo_url: string, url of the repository
+ :return:
@elopio

elopio Dec 5, 2017

Owner

Thanks for adding the comments. But you left that return incomplete, please document also the value returned..

github/snapcraft.py
- return urllib2.urlopen(url)
- except:
- pass
+ resp = requests.request("GET", url)
@elopio

elopio Dec 5, 2017

Owner

I prefer to use full words, because abbreviations are complex for non-native english speakers, like me. Please replace resp with response.

github/snapcraft.py
+ if resp.status_code == 200:
+ return resp.text
+
+def get_plugins(snapcraft_file, plugins=None):
@elopio

elopio Dec 5, 2017

Owner

I kind-of liked it better as get_plugins_count.

@DeniskaMazur

DeniskaMazur Dec 5, 2017

Should I also change it for the other functions?

github/snapcraft.py
+def _get_source_type_from_uri(source):
+ """
+ Detect source type of source
+ Shamelesly stolen from https://github.com/snapcore/snapcraft/tree/master/snapcraft
@elopio

elopio Dec 5, 2017

Owner

It's not stealing, it's called free software :D
These scripts have a gpl license, which is the same that snapcraft uses. So it would be nice to have a better comment here.
Something like: Code copied from the snapcraft project: https://github.com/snapcore/snapcraft

launchpad/snaps.py
-
-cache_dir = os.path.join(
@elopio

elopio Dec 5, 2017

Owner

why did you remove the cache dir here?

main.py
+scriplets = dict()
+sources = dict()
+
+def updates_dicts(sfile):
@elopio

elopio Dec 5, 2017

Owner

sfile should be snapcraft_file, for clarity.

main.py
+
+def updates_dicts(sfile):
+ """
+ Updates your snapfile dictianories
@elopio

elopio Dec 5, 2017

Owner

typo: dictianories/dictionaries

Understood, will fix it.

Updated code, squashed commits, waiting for your review :)

github/snapcraft.py
@@ -1,37 +1,126 @@
-#!/usr/bin/env python2
+#!/usr/bin/env/python2
@elopio

elopio Dec 6, 2017

Owner

This is a bogus change. You shouldn't modify it, so please change the / back to a space.

@elopio

elopio Dec 6, 2017

Owner

oh, wait, actually this python files has no main, so this shebang is not doing anything here.
You can just remove the line.

github/snapcraft.py
import urlparse
+import re
@elopio

elopio Dec 6, 2017

Owner

It's common to sort the python imports alphabetically, grouping them by type: first python libs, then external libs, then libs local to the project. So, this should be:

import re
import urlparse

import requests
github/snapcraft.py
- count[plugin] = 1
- snapcraft_yaml_file.close()
- return count
+_SCRIPLETS = ["prepare", "build", "install", "version-script"]
@elopio

elopio Dec 6, 2017

Owner

Please replace the " with '.

I've left a few minor comments, mostly about style because I value consistency and clarity above all. But this is very good, I will approve your code-in task while you make the minor changes. Thanks!

github/snapcraft.py
- return urllib2.urlopen(url)
- except:
- pass
+ response = requests.request("GET", url)
@elopio

elopio Dec 6, 2017

Owner

Please replace the " with '.

github/snapcraft.py
+
+ if response.status_code == 200:
+ return response.text
+
@elopio

elopio Dec 6, 2017

Owner

The spacing should be consistent. Top-level functions should be separated by two empty lines.

github/snapcraft.py
+ if response.status_code == 200:
+ return response.text
+
+def get_plugins_count(snapcraft_file, plugins=None):
@elopio

elopio Dec 6, 2017

Owner

Please remove this plugins output argument.

+ else:
+ plugins[plugin] = 1
+ return plugins
+
@elopio

elopio Dec 6, 2017

Owner

two empty lines between.

github/snapcraft.py
+ plugins[plugin] = 1
+ return plugins
+
+def get_scriplets_count(snapcraft_file, scriplets=None):
@elopio

elopio Dec 6, 2017

Owner

please remove this scriptlets output argument.

+ else:
+ scriplets[line] += 1
+ return scriplets
+
@elopio

elopio Dec 6, 2017

Owner

two empty lines.

github/snapcraft.py
+ scriplets[line] += 1
+ return scriplets
+
+def get_sources_count(snapcraft_file, sources=None):
@elopio

elopio Dec 6, 2017

Owner

Please remove this sources output argument.

+ else:
+ sources[src_type] = 1
+ return sources
+
@elopio

elopio Dec 6, 2017

Owner

two empty lines

updated, squashed

DeniskaMazur commented Dec 6, 2017

Forgot to fix some stuff, now done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment