Skip to content

Commit 18e0e4e

Browse files
committed
Reodering to alphabetical for release, tested.
1 parent 4b74643 commit 18e0e4e

File tree

7 files changed

+573
-584
lines changed

7 files changed

+573
-584
lines changed

gitnet/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ class MergeError(gitnetException):
5959

6060
class GraphStatsError(gitnetException):
6161
"""
62-
Exception given when the statistics are not generated as expected.
62+
Exception given when the network graph statistics are not generated as expected.
6363
"""
6464
pass

gitnet/get_log.py

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,41 @@
1515
# *********************************************************************************************
1616

1717
import bash as sh
18+
import subprocess as sub
1819
import os
1920
import warnings
2021
from gitnet.exceptions import RepositoryError, ParseError, InputError
2122
from gitnet.commit_log import CommitLog
22-
import subprocess as sub
2323

24-
25-
def retrieve_commits(path, mode="stat"):
24+
def get_log(path, mode="stat", commit_source="local git"):
2625
"""
27-
Takes a file path string and a mode string and produces the git log for the
28-
specified directory. The default mode, "stat" retrieves the logs by running "git log --stat".
29-
Modes include: "basic" (git log), "raw" ("git log --raw"), and "stat" ("git log --stat").
26+
A function for gathering data from a local Git repository.
3027
3128
**Parameters** :
3229
3330
> *path* : `string`
3431
35-
>> A string identifying the path to the target git repository.
32+
>> A string containing the path of the Git repository.
3633
3734
> *mode* : `string`
3835
39-
>> A string identifying the git log mode to be retrieved. Default mode is "stat".
36+
>> The retrieval mode. Modes currently implemented: "basic", "raw", "stat".
4037
41-
**Return** :
38+
> *commit_source* : `string`
4239
43-
> Returns a large string containing the raw output from the repository's git log.
40+
>> The source of the Git repository, local is currently the only option.
4441
45-
"""
46-
print("Attempting local git log retrieval...")
47-
# Log command modes, referenced by "mode" input.
48-
log_commands = {"basic": "git log", "raw": "git log --raw", "stat":"git log --stat"}
49-
if mode not in log_commands.keys():
50-
raise InputError("{} is not a valid retrieval mode.".format(mode))
51-
# Save the current directory. Navigate to new directory. Retrieve logs. Return to original directory.
52-
work_dir = os.getcwd()
53-
os.chdir(path)
54-
raw_logs = sh.bash(log_commands[mode]).stdout.decode("utf-8")
55-
os.chdir(work_dir)
56-
# If the retrieval was unsuccessful, raise an error.
57-
if len(raw_logs) == 0:
58-
print("Raising error.")
59-
if "true" in str(sh.bash("git rev-parse --is-inside-work-tree").stdout):
60-
raise RepositoryError("{} is not a Git repository.".format(path))
61-
else:
62-
raise RepositoryError("{} has no commits.".format(path))
63-
# If the retrieval was successful, print a summary."
64-
print("Got {} characters from: {}".format(len(raw_logs), path))
65-
# Record the retrieval mode.
66-
raw_logs = "Mode =\n{}\n".format(mode) + raw_logs
67-
return raw_logs
42+
**Returns** : `Commitlog`
6843
44+
"""
45+
if commit_source == "local git":
46+
detect_key = "hash"
47+
else:
48+
detect_key = "unknown"
49+
return CommitLog(dofd=parse_commits(retrieve_commits(path, mode)),
50+
source=commit_source,
51+
path=path,
52+
key_type=detect_key)
6953

7054
def identify(s):
7155
"""
@@ -117,7 +101,6 @@ def identify(s):
117101
" so was identified as 'other'.".format(s))
118102
return "none"
119103

120-
121104
def parse_commits(commit_str):
122105
"""
123106
Parses a raw string containing a commit Log for a Git repository. It produces a dictionary
@@ -214,33 +197,46 @@ def parse_commits(commit_str):
214197
warnings.warn("Parser was unable to identify {}. Identity string <{}> not recognized".format(line,id))
215198
return collection
216199

217-
218-
def get_log(path, mode="stat", commit_source="local git"):
200+
def retrieve_commits(path, mode="stat"):
219201
"""
220-
A function for gathering data from a local Git repository.
202+
Takes a file path string and a mode string and produces the git log for the
203+
specified directory. The default mode, "stat" retrieves the logs by running "git log --stat".
204+
Modes include: "basic" (git log), "raw" ("git log --raw"), and "stat" ("git log --stat").
221205
222206
**Parameters** :
223207
224208
> *path* : `string`
225209
226-
>> A string containing the path of the Git repository.
210+
>> A string identifying the path to the target git repository.
227211
228212
> *mode* : `string`
229213
230-
>> The retrieval mode. Modes currently implemented: "basic", "raw", "stat".
231-
232-
> *commit_source* : `string`
214+
>> A string identifying the git log mode to be retrieved. Default mode is "stat".
233215
234-
>> The source of the Git repository, local is currently the only option.
216+
**Return** :
235217
236-
**Returns** : `Commitlog`
218+
> Returns a large string containing the raw output from the repository's git log.
237219
238220
"""
239-
if commit_source == "local git":
240-
detect_key = "hash"
241-
else:
242-
detect_key = "unknown"
243-
return CommitLog(dofd=parse_commits(retrieve_commits(path, mode)),
244-
source=commit_source,
245-
path=path,
246-
key_type=detect_key)
221+
print("Attempting local git log retrieval...")
222+
# Log command modes, referenced by "mode" input.
223+
log_commands = {"basic": "git log", "raw": "git log --raw", "stat":"git log --stat"}
224+
if mode not in log_commands.keys():
225+
raise InputError("{} is not a valid retrieval mode.".format(mode))
226+
# Save the current directory. Navigate to new directory. Retrieve logs. Return to original directory.
227+
work_dir = os.getcwd()
228+
os.chdir(path)
229+
raw_logs = sh.bash(log_commands[mode]).stdout.decode("utf-8")
230+
os.chdir(work_dir)
231+
# If the retrieval was unsuccessful, raise an error.
232+
if len(raw_logs) == 0:
233+
print("Raising error.")
234+
if "true" in str(sh.bash("git rev-parse --is-inside-work-tree").stdout):
235+
raise RepositoryError("{} is not a Git repository.".format(path))
236+
else:
237+
raise RepositoryError("{} has no commits.".format(path))
238+
# If the retrieval was successful, print a summary."
239+
print("Got {} characters from: {}".format(len(raw_logs), path))
240+
# Record the retrieval mode.
241+
raw_logs = "Mode =\n{}\n".format(mode) + raw_logs
242+
return raw_logs

gitnet/gitnet_tests/coverage_report.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ Name Stmts Miss Cover Missin
33
C:\Users\User\Desktop\gitnet\gitnet\__init__.py 6 0 100%
44
C:\Users\User\Desktop\gitnet\gitnet\commit_log.py 113 3 97% 107-108, 163
55
C:\Users\User\Desktop\gitnet\gitnet\exceptions.py 14 0 100%
6-
C:\Users\User\Desktop\gitnet\gitnet\get_log.py 103 14 86% 62, 111-118, 158, 160, 208-214, 242
6+
C:\Users\User\Desktop\gitnet\gitnet\get_log.py 103 14 86% 48, 95-102, 141, 143, 191-197, 237
77
test_commit_log.py 259 0 100%
88
test_get.py 91 1 99% 48
99
test_helpers.py 201 0 100%
1010
test_log.py 678 0 100%
1111
test_netgen.py 126 0 100%
12-
test_network.py 524 1 99% 659
13-
C:\Users\User\Desktop\gitnet\gitnet\helpers.py 132 2 98% 55, 385
14-
C:\Users\User\Desktop\gitnet\gitnet\log.py 383 13 97% 200, 248-250, 252, 445, 485, 692, 709, 820, 822, 826, 828
15-
C:\Users\User\Desktop\gitnet\gitnet\multigraph.py 201 4 98% 148-151, 254
12+
test_network.py 524 1 99% 657
13+
C:\Users\User\Desktop\gitnet\gitnet\helpers.py 132 2 98% 54, 378
14+
C:\Users\User\Desktop\gitnet\gitnet\log.py 383 13 97% 150, 236-238, 240, 499, 539, 722, 724, 728, 730, 801, 818
15+
C:\Users\User\Desktop\gitnet\gitnet\multigraph.py 203 2 99% 315, 478
1616
---------------------------------------------------------------------------------
17-
TOTAL 2831 38 99%
17+
TOTAL 2833 36 99%
1818

1919
## 9 lines will not be run with our tests:
2020
- log.py line 188,189,190,192

gitnet/gitnet_tests/test_log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def test_basic_fn(self):
487487
# Check that a file exists where expected
488488
self.assertTrue(os.path.exists(self.path))
489489
# Check a summary string is produced
490-
self.assertEqual("Data written to temp.tsv", self.tsv_str)
490+
self.assertIn("Data written to temp.tsv", self.tsv_str)
491491

492492
def test_basic_nofn(self):
493493
"""Is no file produced but a string given? """
@@ -506,7 +506,7 @@ def test_empty_cols(self):
506506
# Checking file is created
507507
self.assertTrue(os.path.exists(self.path))
508508
# Check a summary string is produced
509-
self.assertEqual("Data written to temp.tsv", tsv_str)
509+
self.assertIn("Data written to temp.tsv", tsv_str)
510510

511511
def test_warnings(self):
512512
# Warning occurs non string values are forced to strings

gitnet/helpers.py

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import re
1919
from gitnet.exceptions import InputError
2020

21-
2221
# Working with Git Log date strings
2322
def datetime_git(s):
2423
"""
@@ -56,7 +55,6 @@ def datetime_reference(s):
5655
"(e.g. 'Mon Apr 18 00:59:02 2016 -0400') or a datetime object.")
5756
return ref_date
5857

59-
6058
# Filtering functions.
6159
def filter_since(s, match):
6260
"""
@@ -207,8 +205,30 @@ def filter_has(x,match):
207205
except TypeError:
208206
return False
209207

208+
def list_to_scd(lst):
209+
"""
210+
Produces a string which joins the items of the list by semicolons. Non-string items are converted to strings
211+
prior to joining.
212+
213+
**Parameters**
214+
215+
>*lst* : `list`
216+
>> A list of items which are either strings or objects which can be converted to strings using `str()`
217+
218+
**Return** `str`
219+
> A String which includes each item within `lst`, separated by semicolons.
220+
"""
221+
new_lst = []
222+
for i in lst:
223+
if not isinstance(i, str):
224+
new_lst.append(str(i))
225+
else:
226+
new_lst.append(i)
227+
228+
string = ';'.join(new_lst)
229+
230+
return string
210231

211-
# Working with lists.
212232
def most_common(lst, n=1):
213233
"""
214234
Produces a list containing the n most common entries (occurring more than once) in a list. If the nth most common
@@ -257,7 +277,6 @@ def most_common(lst, n=1):
257277

258278
return sorted(ret_list, reverse=True)
259279

260-
261280
def most_occurrences(lst):
262281
"""
263282
Produces the number of times the most common value appears.
@@ -285,32 +304,6 @@ def most_occurrences(lst):
285304
m_common.append(i)
286305
return max
287306

288-
289-
def list_to_scd(lst):
290-
"""
291-
Produces a string which joins the items of the list by semicolons. Non-string items are converted to strings
292-
prior to joining.
293-
294-
**Parameters**
295-
296-
>*lst* : `list`
297-
>> A list of items which are either strings or objects which can be converted to strings using `str()`
298-
299-
**Return** `str`
300-
> A String which includes each item within `lst`, separated by semicolons.
301-
"""
302-
new_lst = []
303-
for i in lst:
304-
if not isinstance(i, str):
305-
new_lst.append(str(i))
306-
else:
307-
new_lst.append(i)
308-
309-
string = ';'.join(new_lst)
310-
311-
return string
312-
313-
314307
# Network Edge Generator Functions
315308
def net_edges_simple(v1, v2, record, keep):
316309
"""
@@ -386,7 +379,6 @@ def net_edges_changes(v1, v2, record, keep):
386379
properties["weight"] = int(weight)
387380
return (v1, v2, properties)
388381

389-
390382
# Network Attribute Helper Functions
391383
def node_colours(d):
392384
"""

0 commit comments

Comments
 (0)