Skip to content

Commit

Permalink
bump version, merge branch 'devel'
Browse files Browse the repository at this point in the history
- fix author chunks counting as one loc (closes #15)
- move manpages to package_data
- add `--manpath` option
- add unit tests
- minor documentation updates
- fix CI py26
  • Loading branch information
casperdcl committed Nov 27, 2018
2 parents 7934b01 + b7f4c28 commit 4ec3568
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion git-fame.1.md → .git-fame.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git-fame - Pretty-print `git` repository collaborators sorted by contributions.

# SYNOPSIS

gitfame [--help | *options*] [<*gitdir*>]
gitfame [\--help | *options*] [<*gitdir*>]

# DESCRIPTION

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ none:
run:
python -Om gitfame

git-fame.1: git-fame.1.md
gitfame/git-fame.1: .git-fame.1.md
python -m gitfame --help | tail -n+9 | head -n-2 | cat "$<" - |\
sed -r 's/^ (--\S+) (\S+)\s*(.*)$$/\n\\\1=*\2*\n: \3/' |\
sed -r 's/^ (-\S+, -\S+)\s*/\n\1\n: /' |\
sed -r 's/^ (-\S+, )(-\S+)\s*/\n\\\1\\\2\n: /' |\
pandoc -o "$@" -s -t man
28 changes: 21 additions & 7 deletions gitfame/_gitfame.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
came from [default: False].
-M Detect intra-file line moves and copies [default: False].
-C Detect inter-file line moves and copies [default: False].
--manpath=<path> Directory in which to install git-fame man pages.
--log=<lvl> FATAL|CRITICAL|ERROR|WARN(ING)|[default: INFO]|DEBUG|NOTSET.
"""
from __future__ import print_function
Expand All @@ -52,7 +53,7 @@
__license__ = __licence__ # weird foreign language


RE_AUTHS = re.compile('^author (.+)$', flags=re.M)
RE_AUTHS = re.compile('^\w+ \d+ \d+ (\d+)\nauthor (.+)$', flags=re.M)
# finds all non-escaped commas
# NB: does not support escaping of escaped character
RE_CSPILT = re.compile(r'(?<!\\),')
Expand Down Expand Up @@ -218,23 +219,25 @@ def run(args):
log.warn(fname + ':' + str(e))
continue
log.log(logging.NOTSET, blame_out)
auths = RE_AUTHS.findall(blame_out)
loc_auths = RE_AUTHS.findall(blame_out)

for auth in map(_str, auths):
for loc, auth in loc_auths: # for each chunk
loc = int(loc)
auth = _str(auth)
try:
auth_stats[auth]["loc"] += 1
auth_stats[auth]["loc"] += loc
except KeyError:
auth_stats[auth] = {"loc": 1, "files": set([fname])}
auth_stats[auth] = {"loc": loc, "files": set([fname])}
else:
auth_stats[auth]["files"].add(fname)

if args.bytype:
fext_key = ("." + fext(fname)) if fext(fname) else "._None_ext"
# auth_stats[auth].setdefault(fext_key, 0)
try:
auth_stats[auth][fext_key] += 1
auth_stats[auth][fext_key] += loc
except KeyError:
auth_stats[auth][fext_key] = 1
auth_stats[auth][fext_key] = loc

log.log(logging.NOTSET, "authors:" + '; '.join(auth_stats.keys()))
auth_commits = check_output(
Expand Down Expand Up @@ -283,6 +286,17 @@ def main(args=None):
log = logging.getLogger(__name__)

log.debug(args)
if args.manpath is not None:
from os import path
from shutil import copyfile
from pkg_resources import resource_filename, Requirement
import sys
fi = resource_filename(Requirement.parse('git-fame'), 'gitfame/git-fame.1')
fo = path.join(args.manpath, 'git-fame.1')
copyfile(fi, fo)
log.info("written:" + fo)
sys.exit(0)

run(args)


Expand Down
2 changes: 1 addition & 1 deletion gitfame/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__all__ = ["__version__"]

# major, minor, patch, -extra
version_info = 1, 5, 0
version_info = 1, 6, 0

# Nice string for the version
__version__ = '.'.join(map(str, version_info))
Expand Down
4 changes: 2 additions & 2 deletions git-fame.1 → gitfame/git-fame.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 1.19.2.1
.\" Automatically generated by Pandoc 2.3.1
.\"
.TH "GIT\-FAME" "1" "2016\-2018" "git\-fame User Manuals" ""
.hy
Expand Down Expand Up @@ -97,7 +97,7 @@ Can be absoulte (eg: 1970\-01\-31) or relative to now (eg: 3.weeks).
.RE
.TP
.B \-v, \-\-version
show program\[aq]s version number and exit
show program's version number and exit
.RS
.RE
.TP
Expand Down
16 changes: 16 additions & 0 deletions gitfame/tests/tests_gitfame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import unicode_literals

import sys
from os import path
from shutil import rmtree
from tempfile import mkdtemp
# import re
# from nose import with_setup
# from nose.plugins.skip import SkipTest
Expand Down Expand Up @@ -99,4 +102,17 @@ def test_main():
]:
main(['-s'] + params)

# test --manpath
tmp = mkdtemp()
man = path.join(tmp, "git-fame.1")
assert not path.exists(man)
try:
main(['--manpath', tmp])
except SystemExit:
pass
else:
raise SystemExit("Expected system exit")
assert path.exists(man)
rmtree(tmp, True)

sys.argv, sys.stdout, sys.stderr = _SYS_AOE
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def cythonize(*args, **kwargs):
__author__ = None
__licence__ = None
__version__ = None
main_file = os.path.join(os.path.dirname(__file__), 'gitfame', '_gitfame.py')
src_dir = os.path.abspath(os.path.dirname(__file__))
main_file = os.path.join(src_dir, 'gitfame', '_gitfame.py')
for l in io_open(main_file, mode='r'):
if any(l.startswith(i) for i in ('__author__', '__licence__')):
exec(l)
version_file = os.path.join(os.path.dirname(__file__), 'gitfame', '_version.py')
version_file = os.path.join(src_dir, 'gitfame', '_version.py')
with io_open(version_file, mode='r') as fd:
exec(fd.read())

Expand Down Expand Up @@ -135,8 +136,7 @@ def execute_makefile_commands(commands, alias, verbose=False):
if verbose:
print("Running command: " + cmd)
# Launch the command and wait to finish (synchronized call)
check_call(parsed_cmd,
cwd=os.path.dirname(os.path.abspath(__file__)))
check_call(parsed_cmd, cwd=src_dir)


# Main setup.py config #
Expand All @@ -145,7 +145,7 @@ def execute_makefile_commands(commands, alias, verbose=False):
# Executing makefile commands if specified
if sys.argv[1].lower().strip() == 'make':
# Filename of the makefile
fpath = os.path.join(os.path.dirname(__file__), 'Makefile')
fpath = os.path.join(src_dir, 'Makefile')
# Parse the makefile, substitute the aliases and extract the commands
commands = parse_makefile_aliases(fpath)

Expand Down Expand Up @@ -175,7 +175,7 @@ def execute_makefile_commands(commands, alias, verbose=False):
# Python package config #

README_rst = ''
fndoc = os.path.join(os.path.dirname(__file__), 'README.rst')
fndoc = os.path.join(src_dir, 'README.rst')
with io_open(fndoc, mode='r', encoding='utf-8') as fd:
README_rst = fd.read()
setup(
Expand All @@ -194,13 +194,12 @@ def execute_makefile_commands(commands, alias, verbose=False):
provides=['gitfame'],
install_requires=['argopt>=0.3.5'],
entry_points={'console_scripts': ['git-fame=gitfame:main'], },
data_files=[('man/man1', ['git-fame.1'])],
package_data={'': ['LICENCE']},
package_data={'gitfame': ['LICENCE', 'git-fame.1']},
ext_modules=cythonize(["gitfame/_gitfame.py", "gitfame/_utils.py"],
nthreads=2),
classifiers=[
# Trove classifiers
# (https://pypi.python.org/pypi?%3Aaction=list_classifiers)
# (https://pypi.org/pypi?%3Aaction=list_classifiers)
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Environment :: MacOS X',
Expand Down
7 changes: 5 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ commands = {[extra]commands}

[testenv:py26]
deps =
{[coverage]deps}
{[core]deps}
coverage
coveralls==1.2.0
pycparser==2.18
tqdm
tabulate
commands = {[coverage]commands}
Expand All @@ -54,7 +57,7 @@ deps = {[extra]deps}
[testenv:flake8]
deps = flake8
commands =
flake8 --max-line-length=80 --ignore=E111,E114 --count --statistics --exit-zero .
flake8 --max-line-length=80 -j 8 --ignore=E111,E114 --count --statistics --exit-zero .

[testenv:setup.py]
deps =
Expand Down

0 comments on commit 4ec3568

Please sign in to comment.