【问题标题】:Global paster command not found in virtualenv在 virtualenv 中找不到全局粘贴命令
【发布时间】:2012-12-30 21:50:19
【问题描述】:

我创建了一个自定义粘贴命令,如http://pythonpaste.org/script/developer.html#what-do-commands-look-like 中所述。在我的 setup.py 中,我定义了这样的入口点:

entry_points={
  'paste.global_paster_command' : [
    'xxx_new = xxxconf.main:NewXxx'
  ]
}

我在一个激活的 virtualenv 中,并通过

安装了我的包
python setup.py develop

如果我在我的包文件夹中运行paster,我会看到我的自定义命令,我可以通过paster xxx ... 运行它。但是,如果我离开我的包文件夹 paster 将不再显示我的命令。我检查了which paster,它是我的 virtualenv 的版本。我还启动了一个 python 解释器并导入了xxxconf,它工作正常。

我不知道为什么当我在我的包文件夹之外时无法识别我的全局命令!?

【问题讨论】:

    标签: python setuptools paster


    【解决方案1】:

    你做错了什么,它应该有效。这是最小的工作示例,您可以使用 virtualenv 对其进行测试:

    blah/setup.py:

    from setuptools import setup, find_packages
    
    setup(name='blah',
          version='0.1',
          packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
          include_package_data=True,
          zip_safe=False,
          entry_points={'paste.global_paster_command': [ "xxx_new = blah.xxx:NewXxx", ] },
          )
    

    blah/blah/xxx.py:

    from paste.script import command
    
    class NewXxx(command.Command):
        usage = "PREFIX"
        summary = "some command"
        group_name = "my group"
    

    blah/blah/__init__.py:空。

    现在测试:

    $ pwd
    /tmp
    $ virtualenv paster
    New python executable in paster/bin/python
    Installing setuptools............done.
    Installing pip...............done.
    $ . paster/bin/activate
    (paster)$ pip install PasteScript
    Downloading/unpacking PasteScript
    [... skipping long pip output here ...]
    (paster)$ paster
    [...]
    Commands:
      create       Create the file layout for a Python distribution
      help         Display help
      make-config  Install a package and create a fresh config file/directory
      points       Show information about entry points
      post         Run a request for the described application
      request      Run a request for the described application
      serve        Serve the described application
      setup-app    Setup an application, given a config file
    
    (paster)$ cd blah/
    (paster)$ python setup.py develop
    running develop
    [... skipping setup.py output...]
    (paster)$ paster
    [...]
    Commands:
      create       Create the file layout for a Python distribution
      help         Display help
      make-config  Install a package and create a fresh config file/directory
      points       Show information about entry points
      post         Run a request for the described application
      request      Run a request for the described application
      serve        Serve the described application
      setup-app    Setup an application, given a config file
    
    my group:
      xxx_new      some command
    (paster)$ cd ~
    (paster)$ paster
    [...]
    Commands:
    [...]
      setup-app    Setup an application, given a config file
    
    my group:
      xxx_new      some command
    

    【讨论】:

      【解决方案2】:

      您应该在活动的 virtualenv 中安装您的 paste_script。然后你可以在任何地方使用它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-08-29
        • 2017-05-03
        • 1970-01-01
        • 2020-08-13
        • 2016-04-09
        • 2015-09-16
        相关资源
        最近更新 更多