2017-12-03 3 views
0

Ich verwende eine benutzerdefinierte Installationsoption in setup.py, indem ich setuptools.Command unterklassifiziere, aber es löst eine Ausnahme aus, wenn die übergeordnete run-Funktion aufgerufen wird. Hier ist der setup.py CodeRuntimeError beim Ausführen eines Setuptools-Installationsbefehls mit benutzerdefinierten Optionen

from setuptools import setup 
from setuptools import Command 
import os, json, sys 

class vboxcustom(Command): 
    user_options = [ 
      ("disk-path=", "d", "Location where vbox disk files will be stored."), 
      ] 

    def initialize_options(self): 
     self.disk_path = None 

    def finalize_options(self): 
     if self.disk_path is None: 
      self.disk_path = os.path.expanduser("~/vbox") 

    def run(self): 
     settings_file = os.path.expanduser("~/.vbox") 

     settings = {"disk_path": self.disk_path} 

     f = open(settings_file, 'w') 
     f.write(json.dumps(settings)) 

     super(vboxcustom, self).run() 

setup(
     name="vbox", 
     version="1.0", 
     author="Ravi", 
     author_email="[email protected]", 
     python_requires=">=3", 
     install_requires=["dnspython"], 
     packages=["vboxhelper"], 
     scripts=["scripts/vbox"], 
     cmdclass={ 
      "install": vboxcustom, 
      } 
     ) 

Die Ausnahme wird ausgelöst, ist dies: RuntimeError: abstract method -- subclass <class '__main__.vboxcustom'> must override. Es scheint, ich habe eine Methode überschreiben, aber welche Methode (Im nur raten, der Fehler ist ziemlich unspezifisch)

Der Stack-Trace ist:

Traceback (most recent call last): 
    File "setup.py", line 37, in <module> 
    "install": vboxcustom, 
    File "/home/ravi/work/virenvs/testvbox/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup 
    return distutils.core.setup(**attrs) 
    File "/usr/lib/python3.6/distutils/core.py", line 148, in setup 
    dist.run_commands() 
    File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands 
    self.run_command(cmd) 
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command 
    cmd_obj.run() 
    File "setup.py", line 25, in run 
    super(vboxcustom, self).run() 
    File "/usr/lib/python3.6/distutils/cmd.py", line 176, in run 
    % self.__class__) 
RuntimeError: abstract method -- subclass <class '__main__.vboxcustom'> must override 

Ich glaube, ich nicht von Setuptools Unterklasse bin soll. Befehl, um den Installationsbefehl zu überschreiben, so dass ich von setuptools.command.install.install subclassiert habe und jetzt bekomme ich einen anderen Fehler. Die neue Ausnahme ausgelöst, ist dies:

distutils.errors.DistutilsGetoptError: invalid negative alias 'no-compile': option 'no-compile' not defined 

Antwort

1

Sie müssen user_options aus der Klasse erhalten install:

class vboxcustom(install): 
    user_options = install.user_options + [ 
     ("disk-path=", "d", "Location where vbox disk files will be stored."), 
    ] 
+0

@Ravi hilft es? – phd

+0

Ja, das war die Ursache des Fehlers. Ich stehe jetzt auf einem völlig anderen Fehler und schaue hinein. – Ravi

+1

Behoben! Auch Eltern müssen initialize_options und finalize_options aufgerufen werden – Ravi

Verwandte Themen