Repository: coala/coala-bears

Issue:
Move generate_package.py to a helper script
As noted on https://github.com/coala/coala-bears/issues/1000 , there is not much in "bears" except plugins.  If we can empty out "bears" of everything not loaded via setuptools entry points, all dependencies belong to each plugin, and there is no developer API in "bears", so no need for API backwards compatibility, only user settings backwards compatibility.

Removing all python files from the top bears directory is also necessary for adopting [PEP 420 -- Implicit Namespace Packages](https://www.python.org/dev/peps/pep-0420/).  

This should probably be done after https://github.com/coala/coala-bears/pull/617 .


Discussion:
Note that we also need https://github.com/coala/coala-bears/blob/master/bears/setup.py.in and https://github.com/coala/coala-bears/blob/master/bears/requirements.txt (re)moved as part of this.
@anctartica , I just checked, and that `bears/requirements.txt` is completely unused.
tests pass without it. https://travis-ci.org/jayvdb/coala-bears/jobs/413495418

Resolving patch:
diff --git a/bears/generate_package.py b/.ci/generate_package.py
similarity index 95%
rename from bears/generate_package.py
rename to .ci/generate_package.py
--- a/bears/generate_package.py
+++ b/.ci/generate_package.py
@@ -89,13 +89,17 @@ def create_upload_parser():
                         action='store_true')
     parser.add_argument('-u', '--upload', help='Upload the packages on PyPi',
                         action='store_true')
+    parser.add_argument('bears',
+                        help='Path to bears directory')
+    parser.add_argument('template', metavar='setup.py.in',
+                        help='Path to setup.py.in template file')
     return parser
 
 
 def main():
     args = create_upload_parser().parse_args()
 
-    os.chdir(os.path.join(os.path.dirname(__file__), '..'))
+    os.chdir(os.path.join(args.bears, '..'))
     os.makedirs(os.path.join('bears', 'upload'), exist_ok=True)
 
     bear_version = VERSION
@@ -145,7 +149,7 @@ def main():
                                  'BEAR_NAME': bear_name,
                                  'ENTRY': 'coala' + bear_name}
 
-            create_file_from_template(os.path.join('bears', 'setup.py.in'),
+            create_file_from_template(args.template,
                                       os.path.join('bears', 'upload',
                                                    bear_name, 'setup.py'),
                                       substitution_dict)


Test patch:
diff --git a/tests/generate_packageTest.py b/tests/generate_packageTest.py
--- a/tests/generate_packageTest.py
+++ b/tests/generate_packageTest.py
@@ -5,10 +5,10 @@
 from pathlib import Path
 from unittest.mock import patch
 
-from bears.generate_package import (VERSION, create_file_from_template,
-                                    create_file_structure_for_packages,
-                                    perform_register, perform_upload, main,
-                                    create_upload_parser)
+from generate_package import (VERSION, create_file_from_template,
+                              create_file_structure_for_packages,
+                              perform_register, perform_upload, main,
+                              create_upload_parser)
 
 
 class TouchTest(unittest.TestCase):
@@ -67,7 +67,8 @@ def tearDown(self):
 class CreateUploadParserTest(unittest.TestCase):
 
     def test_parser(self):
-        self.assertTrue(create_upload_parser().parse_args(['--upload']).upload)
+        self.assertTrue(create_upload_parser().parse_args(
+            ['a', 'b', '--upload']).upload)
 
 
 class PerformRegisterTest(unittest.TestCase):
@@ -91,6 +92,8 @@ def test_command(self, call_mock):
 
 class MainTest(unittest.TestCase):
 
+    TEMPLATE_FILE_PATH = os.path.abspath(os.path.join(
+        os.path.dirname(__file__), '..', '.moban.dt', 'setup.py.in'))
     BEARS_PATH = os.path.abspath(os.path.join(
         os.path.dirname(__file__), '..', 'bears'))
     BEARS_UPLOAD_PATH = os.path.join(BEARS_PATH, 'upload')
@@ -102,7 +105,9 @@ class MainTest(unittest.TestCase):
     def setUp(self):
         self.orig_dir = os.getcwd()
 
-        self.argv = ['generate_package.py']
+        self.argv = ['generate_package.py',
+                     self.BEARS_PATH,
+                     self.TEMPLATE_FILE_PATH]
         argv_patcher = patch.object(sys, 'argv', self.argv)
         self.addCleanup(argv_patcher.stop)
         self.argv_mock = argv_patcher.start()
@@ -116,7 +121,7 @@ def test_main(self):
 
     def test_main_bear_version_prod(self):
         fake_prod_version = '99.99.99'
-        with patch('bears.generate_package.VERSION', fake_prod_version):
+        with patch('generate_package.VERSION', fake_prod_version):
             main()
         with open(self.CSS_BEAR_SETUP_PATH) as fl:
             setup_py = fl.read()
@@ -125,21 +130,21 @@ def test_main_bear_version_prod(self):
 
     def test_main_bear_version_dev(self):
         fake_dev_version = '13.37.0.dev133713371337'
-        with patch('bears.generate_package.VERSION', fake_dev_version):
+        with patch('generate_package.VERSION', fake_dev_version):
             main()
         with open(self.CSS_BEAR_SETUP_PATH) as fl:
             setup_py = fl.read()
         self.assertNotIn(fake_dev_version, setup_py)
         self.assertIn('13.37.0', setup_py)
 
-    @patch('bears.generate_package.perform_upload')
+    @patch('generate_package.perform_upload')
     def test_upload(self, call_mock):
         self.argv.append('--upload')
         main()
         for call_object in call_mock.call_args_list:
             self.assertRegex(call_object[0][0], r'.+Bear')
 
-    @patch('bears.generate_package.perform_register')
+    @patch('generate_package.perform_register')
     def test_register(self, call_mock):
         self.argv.append('--register')
         main()