Skip to content

Commit

Permalink
Organize Python code in a source directory and a bin directory
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-c committed Jun 26, 2019
1 parent 070ddc9 commit a5b3654
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 51 deletions.
Empty file added bin/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions bin/microannotate-generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import os

from microannotate import generator

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"repository_dir", help="Path to the input repository", action="store"
)
parser.add_argument(
"repository_out_dir", help="Path to the output repository", action="store"
)
parser.add_argument(
"--rev-start",
help="Which revision to start with (0 by default)",
action="store",
default="0",
)
parser.add_argument(
"--rev-end",
help="Which revision to end with (tip by default)",
action="store",
default="tip",
)
args = parser.parse_args()

repo_out_dir = os.path.realpath(args.repository_out_dir)

generator.generate(args.repository_dir, repo_out_dir, args.rev_start, args.rev_end)
22 changes: 22 additions & 0 deletions bin/microannotate-view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse

from microannotate import viewer

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("repository_dir", help="Path to the repository", action="store")
parser.add_argument(
"path", help="Path to the file in the repository", action="store"
)
parser.add_argument(
"rev", help="Start annotating from this revision", action="store"
)
args = parser.parse_args()

viewer.html(args.repository_dir, args.rev, args.path)
1 change: 1 addition & 0 deletions microannotate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
2 changes: 1 addition & 1 deletion annotatehelper.py → microannotate/annotatehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import collections

import utils
from microannotate import utils


class Commit(object):
Expand Down
32 changes: 2 additions & 30 deletions microannotate-generate.py → microannotate/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import concurrent.futures
import itertools
import os
Expand All @@ -13,7 +12,7 @@
import pygit2
from tqdm import tqdm

import utils
from microannotate import utils


class Commit:
Expand Down Expand Up @@ -166,7 +165,7 @@ def get_revs(hg, rev_start=0, rev_end="tip"):
return x.splitlines()


def download_commits(repo_dir, repo_out_dir, rev_start=0, rev_end="tip"):
def generate(repo_dir, repo_out_dir, rev_start=0, rev_end="tip"):
if os.path.exists(repo_out_dir):
repo = pygit2.Repository(repo_out_dir)
last_commit_hash = utils.get_original_hash(repo, "HEAD")
Expand Down Expand Up @@ -208,30 +207,3 @@ def download_commits(repo_dir, repo_out_dir, rev_start=0, rev_end="tip"):
convert(repo, commit)
except Exception:
f.write(f"{commit.node} - {commit.parents}\n")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"repository_dir", help="Path to the input repository", action="store"
)
parser.add_argument(
"repository_out_dir", help="Path to the output repository", action="store"
)
parser.add_argument(
"--rev-start",
help="Which revision to start with (0 by default)",
action="store",
default="0",
)
parser.add_argument(
"--rev-end",
help="Which revision to end with (tip by default)",
action="store",
default="tip",
)
args = parser.parse_args()

repo_out_dir = os.path.realpath(args.repository_out_dir)

download_commits(args.repository_dir, repo_out_dir, args.rev_start, args.rev_end)
File renamed without changes.
22 changes: 3 additions & 19 deletions microannotate.py → microannotate/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import argparse
import collections
import os
import random
Expand All @@ -12,11 +11,10 @@
import hglib
import pygit2

import annotatehelper
import utils
from microannotate import annotatehelper, utils


def go(repository_dir, rev, path):
def html(repository_dir, rev, path):
repository_dir = os.path.realpath(repository_dir)

repo = pygit2.Repository(repository_dir)
Expand Down Expand Up @@ -102,18 +100,4 @@ def go(repository_dir, rev, path):
</html>
"""

print(html)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("repository_dir", help="Path to the repository", action="store")
parser.add_argument(
"path", help="Path to the file in the repository", action="store"
)
parser.add_argument(
"rev", help="Start annotating from this revision", action="store"
)
args = parser.parse_args()

go(args.repository_dir, args.rev, args.path)
return html
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def read_requirements(file_):
packages=find_packages(exclude=["contrib", "docs", "tests"]),
include_package_data=True,
license="MPL2",
scripts=["microannotate-generate.py", "microannotate.py"],
scripts=["bin/microannotate-generate.py", "bin/microannotate-view.py"],
classifiers=[
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3 :: Only",
Expand Down

0 comments on commit a5b3654

Please sign in to comment.