Skip to content

Commit 36e857a

Browse files
author
HR
committed
Make pip compatible
1 parent 82a4d66 commit 36e857a

5 files changed

Lines changed: 71 additions & 82 deletions

File tree

Pipfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 62 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# GitHub clone
2-
Git clone sub-directories of a GitHub repository (at any reference) without having to clone the entire repository.
2+
Git clone any sub-directories of any GitHub repository (at any reference) without having to clone the entire repository.
33
Uses the GitHub API to recursively clone the sub-directories tree and files.
44

55
# Rate limit

ghclone.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8
13
"""
24
GitHub clone (git.io/ghclone)
35
@@ -22,23 +24,22 @@
2224
"""
2325
import requests
2426
import re
25-
import sys
2627
import os
2728
import errno
29+
from sys import exit
2830
from docopt import docopt
2931

30-
VERSION = '1.0.0'
32+
__version__ = '1.0.0'
3133
GH_API_BASE_URL = 'https://api.github.com'
3234
GH_REPO_CONTENTS_ENDPOINT = GH_API_BASE_URL + '/repos/{}/{}/contents'
3335
BASE_NORMALIZE_REGEX = re.compile(r'.*github\.com\/')
3436

35-
verbose = False
3637
req = requests.Session()
37-
req.headers.update({'User-Agent': 'git.io/ghclone '+VERSION})
38+
req.headers.update({'User-Agent': 'git.io/ghclone '+__version__})
3839

3940
def exit_with_m(m='An error occured'):
4041
print(m)
41-
sys.exit(1)
42+
exit(1)
4243

4344
def mkdir_p(path):
4445
try:
@@ -94,11 +95,11 @@ def clone(base_url, path=None, ref=None):
9495
###
9596
# Main
9697
###
97-
if __name__ == '__main__':
98+
def main():
9899
arguments = docopt(__doc__)
99100
if arguments['--version']:
100-
print(VERSION)
101-
sys.exit(0)
101+
print(__version__)
102+
exit(0)
102103

103104
# Get params
104105
gh_url = arguments['<url>']
@@ -114,4 +115,7 @@ def clone(base_url, path=None, ref=None):
114115
api_req_url = GH_REPO_CONTENTS_ENDPOINT.format(user, repo)
115116
print("Cloning into '%s'..." % path)
116117
clone(api_req_url, path, ref)
117-
print("done.")
118+
print("done.")
119+
120+
if __name__ == '__main__':
121+
main()

setup.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
import codecs
5+
import os
6+
import re
7+
from setuptools import find_packages, setup
8+
9+
10+
version_regex = r'__version__ = ["\']([^"\']*)["\']'
11+
with open('ghclone.py',) as f:
12+
text = f.read()
13+
match = re.search(version_regex, text)
14+
15+
if match:
16+
version = match.group(1)
17+
else:
18+
raise RuntimeError("No version number found!")
19+
20+
21+
def local_file(name):
22+
return os.path.relpath(os.path.join(os.path.dirname(__file__), name))
23+
24+
25+
README = local_file('README.md')
26+
long_description = codecs.open(README, encoding='utf-8').read()
27+
28+
29+
setup(
30+
name='ghclone',
31+
version=version,
32+
description='A script for cloning any sub-directories of any GitHub repository',
33+
long_description=long_description,
34+
url='https://github.com/HR/github-clone',
35+
author='Habib Rehman',
36+
author_email='h@rehman.email',
37+
license='Apache 2.0',
38+
classifiers=[
39+
'Development Status :: 5 - Production/Stable',
40+
'Environment :: Console',
41+
'Intended Audience :: Developers',
42+
'License :: OSI Approved :: Apache Software License',
43+
'Programming Language :: Python :: 3',
44+
'Programming Language :: Python :: 3.3',
45+
'Programming Language :: Python :: 3.4',
46+
'Programming Language :: Python :: 3.5',
47+
],
48+
install_requires=[
49+
'requests>=2.20.0',
50+
'docopt>=0.6.2',
51+
],
52+
entry_points={
53+
'console_scripts': [
54+
'ghclone=ghclone:main',
55+
],
56+
},
57+
)

0 commit comments

Comments
 (0)