Przeglądaj źródła

Provide dulwich binary script using console_scripts entrypoints when setuptools is available. Fixes #540

Jelmer Vernooij 4 lat temu
rodzic
commit
5a7a9ded6c
4 zmienionych plików z 41 dodań i 5 usunięć
  1. 5 2
      NEWS
  2. 25 0
      bin/dulwich
  3. 2 1
      dulwich/cli.py
  4. 9 2
      setup.py

+ 5 - 2
NEWS

@@ -14,8 +14,11 @@
    back a 401. The client can then retry with credentials.
    (Jelmer Vernooij, #691)
 
- * Install dulwich script from entry_points, making it slightly easier
-   to use on Windows. (Jelmer Vernooij, #540)
+ * Move the guts of bin/dulwich to dulwich.cli, so it is easier to
+   test or import. (Jelmer Vernooij)
+
+ * Install dulwich script from entry_points when setuptools is available,
+   making it slightly easier to use on Windows. (Jelmer Vernooij, #540)
 
 0.20.2	2020-06-01
 

+ 25 - 0
bin/dulwich

@@ -0,0 +1,25 @@
+#!/usr/bin/python3 -u
+# command-line interface for Dulwich
+# Copyright (C) 2020 Jelmer Vernooij <jelmer@jelmer.uk>
+#
+# Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
+# General Public License as public by the Free Software Foundation; version 2.0
+# or (at your option) any later version. You can redistribute it and/or
+# modify it under the terms of either of these two licenses.
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# You should have received a copy of the licenses; if not, see
+# <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
+# and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
+# License, Version 2.0.
+#
+
+import sys
+
+from dulwich.cli import main
+sys.exit(main(sys.argv[1:]))

+ 2 - 1
dulwich/cli.py

@@ -33,6 +33,7 @@ import sys
 from getopt import getopt
 import optparse
 import signal
+from typing import Dict
 
 def signal_int(signal, frame):
     sys.exit(1)
@@ -536,7 +537,7 @@ class cmd_remote_add(Command):
 
 class SuperCommand(Command):
 
-    subcommands = {}
+    subcommands: Dict[str, Command]  = {}
 
     def run(self, args):
         if not args:

+ 9 - 2
setup.py

@@ -64,7 +64,7 @@ ext_modules = [
 ]
 
 setup_kwargs = {}
-
+scripts = ['bin/dul-receive-pack', 'bin/dul-upload-pack']
 if has_setuptools:
     setup_kwargs['extras_require'] = {
         'fastimport': ['fastimport'],
@@ -75,6 +75,13 @@ if has_setuptools:
     setup_kwargs['include_package_data'] = True
     setup_kwargs['test_suite'] = 'dulwich.tests.test_suite'
     setup_kwargs['tests_require'] = tests_require
+    setup_kwargs['entry_points'] = {
+        "console_scripts": [
+            "dulwich=dulwich.cli:main",
+        ]}
+else:
+    scripts.append('bin/dulwich')
+
 
 with io.open(os.path.join(os.path.dirname(__file__), "README.rst"),
              encoding="utf-8") as f:
@@ -97,7 +104,7 @@ setup(name='dulwich',
       packages=['dulwich', 'dulwich.tests', 'dulwich.tests.compat',
                 'dulwich.contrib'],
       package_data={'': ['../docs/tutorial/*.txt']},
-      scripts=['bin/dulwich', 'bin/dul-receive-pack', 'bin/dul-upload-pack'],
+      scripts=scripts,
       ext_modules=ext_modules,
       distclass=DulwichDistribution,
       classifiers=[