Skip to content

Commit 2fc249b

Browse files
committed
Updated documentation to reflect changes in nbgitpuller
This syncs the documentation to changes made to the signature of the handle_files function in nbgitpuller.
1 parent 312ecde commit 2fc249b

File tree

3 files changed

+32
-42
lines changed

3 files changed

+32
-42
lines changed

docs/topic/nbgitpuller-downloder-plugins.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,48 @@ For example:
1818
```
1919

2020
2. The file referenced for use by nbgitpuller in the plug-in (the above example is looking for the
21-
file, dropbox_downloader) must implement the function handle_files(query_line_args) and be decorated with `@hookimpl`.
21+
file, dropbox_downloader) must implement the function
22+
`handle_files(helper_args, query_line_args)` and be decorated with `@hookimpl`.
2223
3. As a consequence of this, the following must be imported:
23-
- `from nbgitpuller.hookspecs import hookimpl`
24+
- `from nbgitpuller.plugin_hook_specs import hookimpl`
2425
4. The implementation of the handle_files function in your plugin needs to return
2526
two pieces of information:
26-
- the name of the folder, the archive is in after decompression
27+
- the name of the folder, the archive is in after decompression.
2728
- the path to the local git repo mimicking a remote origin repo
2829

29-
nbgitpuller provides a function in plugin_helper.py called handle_files_helper that handles the downloading
30+
nbgitpuller provides a function in plugin_helper.py called `handle_files_helper` that handles the downloading
3031
and returning of the correct information if given a URL, the extension of the
3132
file to decompress(zip or tar) and the progress function(I will describe that
32-
more later) but you are welcome to implement the functionality of handle_files_helper in your
33+
more later) but you are welcome to implement the functionality of `handle_files_helper` in your
3334
plug-in. There may be use cases not covered by the currently available plugins like needing to authenticate against
3435
the webserver or service where your archive is kept. Either way, it behooves you
35-
to study the handle_files_helper function in nbgitpuller to get a sense of how this function
36+
to study the `handle_files_helper` function in nbgitpuller to get a sense of how this function
3637
is implemented.
3738

3839
For the rest of the steps, I refer you to the [nbgitpuller-downloader-dropbox](https://github.com/jupyterhub/nbgitpuller-downloader-dropbox) plugin.
3940

4041
```python
4142
@hookimpl
42-
def handle_files(query_line_args):
43+
def handle_files(helper_args, query_line_args):
4344
query_line_args["repo"] = query_line_args["repo"].replace("dl=0", "dl=1") # dropbox: dl set to 1
44-
ext = determine_file_extension(query_line_args["repo"])`
45-
query_line_args["extension"] = ext
4645
loop = asyncio.get_event_loop()
47-
tasks = handle_files_helper(query_line_args), query_line_args["progress_func"]()
46+
tasks = handle_files_helper(query_line_args), helper_args["wait_for_sync_progress_queue"]()
4847
result_handle, _ = loop.run_until_complete(asyncio.gather(*tasks))
4948
return result_handle
5049
```
5150

5251
The following pieces describe what happens in handle_files before, at least, in this case, we call
5352
the handle_files_helper function:
5453

55-
1) The parameter, query_line_args, is all the query line arguments you include on the nbgitpuller link. This means you
54+
1) The parameter, helper_args, includes the progress function used to monitor the download_q
55+
for messages; messages in the download_q are written to the UI so users can see the progress and
56+
steps being taken to download their archives. You will notice the progress function is passed into
57+
handle_files_helper and accessed like this:
58+
```python
59+
helper_args["wait_for_sync_progress_queue"]
60+
helper_args["download_q"]
61+
```
62+
2) The parameter, query_line_args, is all the query line arguments you include on the nbgitpuller link. This means you
5663
can put keyword arguments into your nbgitpuller links and have access to these arguments in the handle_files
5764
function.
5865
For example, you might set up a link like this:
@@ -63,33 +70,22 @@ the handle_files_helper function:
6370
query_line_args["keyword1"]
6471
query_line_args["keyword2"]
6572
```
66-
2) The query_line_args parameter also includes the progress function used to monitor the download_q
67-
for messages; messages in the download_q are written to the UI so users can see the progress and
68-
steps being taken to download their archives. You will notice the progress function is passed into
69-
handle_files_helper and accessed like this:
70-
```python
71-
query_line_args["progress_func"]
72-
query_line_args["download_q"]
73-
```
7473
3) The first line of the handle_files function for the dropbox downloader is specific to DropBox. The URL to a file
7574
in DropBox contains one URL query parameter(dl=0). This parameter indicates to Dropbox whether to download the
7675
file or open it in their browser-based file system. In order to download the file, this parameter
77-
needs to be changed to dl=1.
78-
4) The next line determines the file extension (zip, tar.gz, etc).
79-
This is added to the query_lines_args map and passed off to the handle_files_helper to
80-
help the application know which utility to use to decompress the archive -- unzip or tar -xzf.
81-
5) Since we don't want the user to have to wait while the download process finishes, we have made
76+
needs to be changed to dl=1.
77+
4) Since we don't want the user to have to wait while the download process finishes, we have made
8278
downloading of the archive a non-blocking process using the package asyncio. Here are the steps:
8379
- get the event loop
8480
- setup two tasks:
8581
- a call to the handle_files_helper with our arguments
8682
- the progress_loop function
8783
- execute the two tasks in the event loop.
88-
6) The function returns two pieces of information to nbgitpuller:
89-
- the directory name of the decompressed archive
84+
5) The function returns two pieces of information to nbgitpuller:
85+
- the directory name of the decompressed archive, output_dir
9086
- the local_origin_repo path.
9187

92-
The details of what happens in handle_files_helper can be found by studying the function. Essentially, the archive is downloaded, decompressed, and set up in a file
93-
system to act as a remote repository(e.g. the local_origin_repo path).
94-
95-
88+
The plugin_helper.py's `handle_files_helper` function does the following:
89+
- the archive is downloaded,
90+
- decompressed, and
91+
- set up in a file system to act as a remote repository(e.g. the local_origin_repo path).

nbgitpuller/pull.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,13 @@ def main():
304304
parser = argparse.ArgumentParser(description='Synchronizes a github repository with a local repository.')
305305
parser.add_argument('git_url', help='Url of the repo to sync')
306306
parser.add_argument('branch_name', default=None, help='Branch of repo to sync', nargs='?')
307-
parser.add_argument('--target-dir', default='.', help='Path to clone repo under')
308-
307+
parser.add_argument('repo_dir', default='.', help='Path to clone repo under', nargs='?')
309308
args = parser.parse_args()
310309

311310
for line in GitPuller(
312311
args.git_url,
313-
args.target_dir,
314-
branch=args.branch_name
312+
args.repo_dir,
313+
branch=args.branch_name if args.branch_name else None
315314
).pull():
316315
print(line)
317316

tests/test_gitpuller.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ def test_initialize():
9999
def command_line_test_helper(remote_path, branch, pusher_path):
100100
work_dir = "/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1]) + "/nbgitpuller"
101101
try:
102-
cmd = ['python3', 'pull.py', remote_path]
103-
if branch is not None:
104-
cmd += [branch]
105-
if pusher_path is not None:
106-
cmd += ['--target-dir', pusher_path]
102+
cmd = ['python3', 'pull.py', remote_path, branch, pusher_path]
107103
sp.check_output(
108104
cmd,
109105
cwd=work_dir
@@ -123,9 +119,8 @@ def test_command_line_existing_branch():
123119
assert subprocess_result
124120

125121

126-
def test_command_line_no_branch_passed():
127-
# so it should use the default branch
128-
branch = None
122+
def test_command_line_default_branch():
123+
branch = ""
129124
with Remote() as remote, Pusher(remote) as pusher:
130125
pusher.push_file('README.md', '1')
131126
remotepath = "file://%s" % os.path.abspath(remote.path)

0 commit comments

Comments
 (0)