Allow setting updated/new env var *values* on Runner.

オープン
#100 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

まず、_utils.py の create_environ()、_master.py の Master.spawn_worker() での使用箇所、そして _runner.py の Runner.init() を読んでください。Runner が明示的な環境値を受け取れるようにする方法を決め、そのうえで、ベンチマークコードが os.environ を変更しなくてもワーカーがそれらの値を受け取れるようにしてください。既存の inherit-environ の動作についても引き続き考慮する必要があります。

索引モデルが issue の本文から書いたものです。

説明

In _utils.py the create_environ() helper produces a dict that can be passed as the "env" arg to subprocess.run(), etc. It is used in Master.spawn_worker() (in _master.py). Currently it takes an "inherit_environ" arg (Bool) that corresponds to the "--inherit-environ" flag in the Runner CLI (see Runner.init() in _runner.py). This results in a potentially problematic situation.

The Problem

Let's say you have a benchmark script that internally relies on some environment variable that is defined relative to the commandline args given to the script. This environment variable may be set already or it might not. Regardless, you will be setting it to some new value. To make this work you need to do something like the following:

    # This is a concrete example.
    os.environ["MY_VAR"] = "spam" if runner.args.my_flag else "eggs"
    if runner.args.inherit_environ is None:
        runner.args.inherit_environ = ["MY_VAR"]
    else:
        runner.args.inherit_environ.append("MY_VAR")

However, in some cases you can't leave the env var set (or maybe the env var could cause pyperf to break). Plus things are more complicated if you have more than one such env var.

The Solution

Consequently, in a benchmark script it would be nice to be able to give the actual env var pairs to Runner rather than doing the dance above. Here are some possible approaches to solve the problem:

  • allow Runner.args.inherit_environ to be a dict
    • create_environ() would be updated to do the right thing
    • this is probably too messy to be part of pyperf's public API
  • add something like Runner.env_vars to allow benchmarks to explicitly set env var values to be used in workers
    • create_environ() would grow a new "env" arg or "inherit_environ" would updated as above
  • add Runner.add_env_var(name, value=INHERIT)
    • this is like either of the two above, but probably a better public API for the functionality
主要言語
Python
スター
967
フォーク
112
平均マージ
5日 8時間
マージ済み PR(30日)
9

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

psf/pyperf のほかの issue

psf/pyperf の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。