1

リソースの異種セットにインストールされる Python モジュール用に distutils ベースの setup.py を構成しています。異種性のため、モジュールがインストールされる場所は各ホストで同じではありませんが、disutils はホスト固有の場所を選択します。

disutils を使用して o+rx パーミッションなしでモジュールがインストールされていることがわかりました (setup.py を実行する前に umask を設定しているにもかかわらず)。1 つの解決策は、この問題を手動で修正することですが、異種のインストール ターゲットで機能する自動化された手段が必要です。

たとえば、setup.py 内からインストールの終了場所を抽出する方法はありますか?

他の提案はありますか?

4

3 に答える 3

0

os.path.dirname(__file__) が探しているものかもしれません。モジュール内の __file__ は、モジュールがロードされたパスを返します。

yourmodule が、setup.py 内の Something.py を含むフォルダーであると仮定します。

import os
#setup(...) call here
from yourmodule import Something
print os.path.dirname(Something.__file__)

これに関する唯一の問題は、ファイル構造が setuputils と同じディレクトリに yourmodule を持っている場合です。その場合、python ローダーは優先的に現在のディレクトリから yourmodule.Something をロードします。

どちらかになる可能性があることを覆すための、ややハックだが効果的な2つのオプション

  1. Python パスから現在のディレクトリを削除し、サイト パッケージに現在存在するファイルから強制的にロードします。

    import sys sys.path = sys.path[1:]

  2. import ステートメントの直前で yourmodule フォルダーの名前を一時的に変更します。

オプション 1 の場合、全体は次のようになります。

import os
import sys

#setup(...) call here

#Remove first entry in sys.path which is current folder (probably impl dependent, but for practical purposes is consistent)
sys.path = sys.path[1:]
from yourmodule import Something
print os.path.dirname(Something.__file__)

setup.py の 1 つでこれをテストしたところ、うまく機能します。幸運を!

于 2010-05-03T07:33:19.153 に答える
0

私は disutils についてあまり詳しくありませんが、ファイルが書き込まれている場所が見つかるまで掘り下げると、その行にパス変数が表示されると思います。

このページはあなたを助けるかもしれません

于 2010-05-02T16:08:53.033 に答える
0

I find that the module is installed without o+rx permissions using disutils

I don’t remember right now if distutils copies the files with their rights as is or if it just copies the contents.

(in spite of setting umask ahead of running setup.py)

I’m not sure how umask and file copying from Python should interact; does umask apply to the system calls or does it need to be explicitly heeded by Python code?

For example, is there a way to extract the ending location of the installation from within setup.py?

There is one, a bit convoluted. What would you do with that information?

于 2011-10-28T15:00:56.563 に答える