0

最近、奇妙な問題が発生しました。

私のOSはGentoo. と をインストールpiplaymanますが、/usr/bin: にあるバイナリ ファイルと/usr/bin/pip/usr/bin/laymanすべて.softlink/usr/bin/python-exec

% ll /usr/bin/{pip,layman}
lrwxrwxrwx 1 root root 11 Sep 18 23:51 /usr/bin/layman -> python-exec
lrwxrwxrwx 1 root root 11 Aug 16 08:14 /usr/bin/pip -> python-exec

の内容/usr/bin/python-exec:

#!/usr/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'Pygments==1.6','console_scripts','pygmentize'
__requires__ = 'Pygments==1.6'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('Pygments==1.6', 'console_scripts', 'pygmentize')()
) 

このファイルは次のものに属していることがわかりましたdev-python/python-exec-0.3.1:

% equery belongs python-exec
 * Searching for python-exec ... 
dev-python/python-exec-0.3.1 (/usr/bin/python-exec)

このパッケージは次のとおりです。

*  dev-python/python-exec
      Latest version available: 0.3.1
      Latest version installed: 0.3.1
      Size of files: 72 kB
      Homepage:      https://bitbucket.org/mgorny/python-exec/
      Description:   Python script wrapper
      License:       BSD

/usr/bin/python-execスクリプトの機能がわかりません。

/usr/bin/pip/usr/bin.laymanがこのスクリプトにソフトリンクするのはなぜですか?

pipパッケージのインストールやlaymanオーバーレイの管理に使用したい場合は/usr/bin/pip-python2.7、 and を使用する必要がありlayman-python2.7ます。

4

2 に答える 2

2

python-exec は、現在選択されている Python ランタイムに適した要求されたスクリプトの実装を呼び出す Gentoo 固有のラッパー スクリプトです。これにより、選択したランタイムに互換性のあるバージョンのスクリプトが存在する限り、Gentoo はスクリプトを壊すことなく Python ランタイム間の切り替えをサポートできます。

于 2014-08-02T02:04:55.030 に答える
0

python-exec ツールのヘルプ情報を読みました。

ピグメントワッパーだと思います。フォーマッター、フィルターなどがあります。

だから私が使用する場合:

$ python-exec -l python -f html -o /tmp/test.file
#this is the input#
print 'hello world'
....

入力を /tmp/test.file に書き込み、pygments を使用してコードをカラフルにします。

しかし、なぜピップと素人がそれにソフトリンクするのか、私にはまだわかりません。

追加:

私は理由を見つけました:

何らかの理由で、別のアプリケーションが/usr/bin/python-exec. (たぶんピグメントだと思います。)

正しい内容は次のとおりです。

#!/usr/bin/python-exec-c                                                                                                                             
# vim:fileencoding=utf-8:ft=python                                               
# (c) 2012 Michał Górny                                                          
# Released under the terms of the 2-clause BSD license.                          
#                                                                                
# This is not the script you are looking for. This is just a wrapper.            
# The actual scripts of this application were installed with -python*,           
# -pypy* or -jython* suffixes. You are most likely looking for one               
# of those.                                                                      

from __future__ import with_statement                                            
import os, os.path, sys                                                          

try:                                                                             
    from epython import EPYTHON                                                  
except ImportError:                                                              
    EPYTHON = os.path.basename(sys.executable)                                   
    if '' and EPYTHON.endswith(''):                                              
        EPYTHON = EPYTHON[:-len('')]                                             

# In the loop:                                                                   
# sys.argv[0] keeps the 'bare' name                                              
# __file__ keeps the 'full' name

while True:                                                                      
    __file__ = sys.argv[0] + '-' + EPYTHON                                       

    try:                                                                         
        kwargs = {}                                                              
        if sys.version_info[0] >= 3:                                             
            import tokenize                                                      

            # need to provide encoding                                           
            with open(__file__, 'rb') as f:                                      
                kwargs['encoding'] = tokenize.detect_encoding(f.readline)[0]     

        with open(__file__, 'r', **kwargs) as f:                                 
            data = f.read()                                                      
    except IOError:                                                              
        # follow symlinks (if supported)                                         
        try:                                                                     
            sys.argv[0] = os.path.join(os.path.dirname(sys.argv[0]),             
                    os.readlink(sys.argv[0]))                                    
        except (OSError, AttributeError):                                        
            # no more symlinks? then it's time to fail.                          
            sys.stderr.write('This Python implementation (%s) is not supported by the script.\n'
                    % EPYTHON)                                                   
            sys.exit(127)
    else:                                                                        
        break                                                                    

sys.argv[0] = __file__                                                           
exec(data)

また、pip、layman などの多くのバイナリ ファイルはすべてそれにソフトリンクします。これは単純なラッパーです。

于 2013-09-19T03:01:36.053 に答える