Repository: git-big-picture/git-big-picture (language: python)

Issue:
Fix variable mix-up



Discussion / hints:

Fix patch:
diff --git a/MANIFEST.in b/MANIFEST.in
deleted file mode 100644
index d77f37c..0000000
--- a/MANIFEST.in
+++ /dev/null
@@ -1,3 +0,0 @@
-include README.rst
-include COPYING
-include git_big_picture.py
diff --git a/README.rst b/README.rst
index eed4f33..c66adb5 100644
--- a/README.rst
+++ b/README.rst
@@ -109,35 +109,34 @@ https://pypi.org/project/git-big-picture/
 
    $ pip install git-big-picture
 
-Alternatively, Just run it straight from a clone or download:
+Alternatively, just run it straight from a Git clone:
 
 .. code:: console
 
     $ git clone git://github.com/git-big-picture/git-big-picture.git
     $ cd git-big-picture
-    $ ./git-big-picture --help
-
-    $ wget https://raw.github.com/git-big-picture/git-big-picture/master/git-big-picture
-    $ chmod 755 git-big-picture
-    $ ./git-big-picture -h
+    $ python3 -m venv venv      # creates a virtualenv
+    $ source venv/bin/activate  # activates the virtualenv
+    $ pip install -e .          # installs to the virtualenv
+    $ git-big-picture --help
 
-Alternatively, use the standard ``setup.py`` script to install it system wide
+Alternatively, use pip to install it system wide
 or just for the user.
 
 .. code:: console
 
-    $ ./setup.py install
+    $ pip install .
     (may need root privileges)
-    $ ./setup.py install --user
+    $ pip install --user .
 
 Git Integration
 ---------------
 
-You can easily integrate this script as a regular Git command, by making the
-script ``git-big-picture`` available on the ``$PATH``. For instance: using
-``./setup.py install`` method, as described above should do the trick.
-Alternatively symlink or copy ``git-big-picture`` into a directory listed in
-your ``$PATH``, for example ``$HOME/bin``.
+After installation using pip,
+you can easily integrate this script as a regular Git command, by making
+sure that executable ``git-big-picture`` is found during ``${PATH}`` lookup.
+E.g. you could append a line like ``export PATH="${HOME}/.local/bin:${PATH}"``
+to your ``~/.bashrc`` if you are using Bash.
 
 You may then use ``git big-picture`` (w/o the first dash) as you would any other Git command:
 
@@ -405,7 +404,8 @@ The command line interface is tested with `Scruf <https://gitlab.com/matthewhugh
 
 .. code:: console
 
-    $ PATH="${PWD}:${PATH}" ./test.scf
+    $ PATH="venv/bin:${PATH}" ./test.scf
+
 
 Debugging
 ---------
diff --git a/git_big_picture.py b/git_big_picture.py
deleted file mode 120000
index f213c29..0000000
--- a/git_big_picture.py
+++ /dev/null
@@ -1,1 +0,0 @@
-git-big-picture
\ No newline at end of file
diff --git a/git_big_picture/__init__.py b/git_big_picture/__init__.py
new file mode 100644
index 0000000..7cd22a8
--- /dev/null
+++ b/git_big_picture/__init__.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+#
+# This file is part of git-big-picture
+#
+# Copyright (C) 2020 Sebastian Pipping <sebastian@pipping.org>
+#
+# git-big-picture is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# git-big-picture is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with git-big-picture.  If not, see <http://www.gnu.org/licenses/>.
+
+from ._main import __version__  # noqa: F401
diff --git a/git_big_picture/__main__.py b/git_big_picture/__main__.py
new file mode 100644
index 0000000..9e384c7
--- /dev/null
+++ b/git_big_picture/__main__.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#
+# This file is part of git-big-picture
+#
+# Copyright (C) 2020 Sebastian Pipping <sebastian@pipping.org>
+#
+# git-big-picture is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# git-big-picture is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with git-big-picture.  If not, see <http://www.gnu.org/licenses/>.
+
+from ._main import main as _main
+
+if __name__ == '__main__':
+    _main()
diff --git a/git-big-picture b/git_big_picture/_main.py
similarity index 99%
rename from git-big-picture
rename to git_big_picture/_main.py
index bee9e37..d2ba43b 100755
--- a/git-big-picture
+++ b/git_big_picture/_main.py
@@ -249,9 +249,6 @@ def create_parser():
     return parser
 
 
-PARSER = create_parser()
-
-
 def barf(message, exit_code):
     """ Abort execution with error message and exit code.
 
@@ -1026,7 +1023,7 @@ def innermost_main(opts):
 
 
 def inner_main():
-    opts = PARSER.parse_args()
+    opts = create_parser().parse_args()
 
     if opts.debug:
         global DEBUG
diff --git a/setup.py b/setup.py
index 4d309d8..8773283 100755
--- a/setup.py
+++ b/setup.py
@@ -19,7 +19,7 @@
 # You should have received a copy of the GNU General Public License
 # along with git-big-picture.  If not, see <http://www.gnu.org/licenses/>.
 
-from setuptools import setup
+from setuptools import find_packages, setup
 
 from git_big_picture import __version__ as VERSION
 
@@ -34,7 +34,12 @@
     url = 'https://github.com/git-big-picture/git-big-picture',
     license = 'GPL v3 or later',
     python_requires='>=3.6',
-    scripts = ['git-big-picture'],
+    packages=find_packages(),
+    entry_points={
+        'console_scripts': [
+            'git-big-picture = git_big_picture._main:main',
+        ],
+    },
     classifiers=[
         'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.6',


Test patch:
diff --git a/run-tests-with-coverage.sh b/run-tests-with-coverage.sh
index 9859a49..840ad22 100755
--- a/run-tests-with-coverage.sh
+++ b/run-tests-with-coverage.sh
@@ -52,6 +52,7 @@ cd "${temp_dir}"
 python3 -m venv ${venv}
 source ${venv}/bin/activate
 pip install --quiet --disable-pip-version-check -r "${source_dir}"/test_requirements.txt
+pip install --quiet --disable-pip-version-check -e "${source_dir}"
 sed "s,\./,${source_dir}/,g" "${source_dir}"/.coveragerc > .coveragerc
 cat <<SITECUSTOMIZE_PY_EOF > "$(ls -1d ${venv}/lib/python*)"/site-packages/sitecustomize.py
 try:
@@ -68,7 +69,7 @@ coverage erase
 
 coverage run ${venv}/bin/pytest "${source_dir}"/test.py \
     || exit_code=$?
-PATH="${source_dir}:${PATH}" COVERAGE_PROCESS_START=.coveragerc \
+PATH="${venv}/bin:${PATH}" COVERAGE_PROCESS_START=.coveragerc \
     coverage run ${venv}/bin/scruf "${source_dir}"/test.scf \
     || exit_code=$?
 
diff --git a/test.py b/test.py
index 74a296c..00aab7e 100755
--- a/test.py
+++ b/test.py
@@ -26,7 +26,7 @@
 import tempfile as tf
 import unittest as ut
 
-import git_big_picture as gbp
+import git_big_picture._main as gbp
 
 # The only reason these global commands work, is because we change the cwd of
 # the test script... ugly.
diff --git a/test.scf b/test.scf
index be87356..bafbde0 100755
--- a/test.scf
+++ b/test.scf
@@ -29,11 +29,16 @@ create a fake repo (i.e. global setup for all following tests)
     $ git commit -q --allow-empty -m "foo"
     $ git config big-picture.wait 0.01  # to speed up the test suite
 
-run without options
+run without options (entry point generated by setuptools)
     $ git-big-picture .
     2: fatal: Must provide an output option. Try '-h' for more information
     [8]
 
+run without options (__main__ module)
+    $ python -m git_big_picture .
+    2: fatal: Must provide an output option. Try '-h' for more information
+    [8]
+
 cover including commit messsages (smoke test)
     $ git-big-picture -c -g >/dev/null