Author uranusjr
Recipients uranusjr
Date 2021-02-24.09:26:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1614158800.84.0.101101658017.issue43312@roundup.psfhosted.org>
In-reply-to
Content
While trying to migrate pip’s internal usages of distutils to sysconfig,[1] I noticed there isn’t a way for pip to select a scheme for sysconfig.get_paths() for `pip install --target` and `pip install --user`. I tried to implement some logic to "guess" a scheme ("posix_home" for `--home`, "nt_user" for `--user` when os.name is "nt", etc.), but eventually hit a wall trying to support alternative implementations.

PyPy, for example, adds additional schemes "pypy" and "pypy_nt", and it’s not clear whether pip should use then for `--home` or not. @mattip helped clear this up for PyPy (which also prompts bpo-43307), but we are worried that other implementations may introduce even more special rules that causes problems, and it’s also not a good idea for pip to implement special logic for every implementation.

I would propose two changes to sysconfig:

1. Make sysconfig._get_default_scheme() a public function. This function will be documented for implementations to return a default scheme to use when none is given to sysconfig.get_paths().
2. Add a new function sysconfig.get_preferred_schemes() for implementations to return preferred schemes for prefix, home, and user installations. This function should return a dict[str, str] with three keys "prefix", "home", and "user", and their values the scheme names to use.

I would be happy to work on a PR and iterate on the design if this sounds like a reasonable idea. For CPython, the implementation would be something like (to match distutils’s behaviour):

def get_preferred_schemes():
    if os.name == "nt":
        return {
            "prefix": "nt",
            "home": "posix_home",
            "user": "nt_user",
        }
    return {
        "prefix": "posix_prefix",
        "home": "posix_home",
        "user": "posix_user",
    }


[1]: https://github.com/pypa/pip/pull/9626
History
Date User Action Args
2021-02-24 09:26:40uranusjrsetrecipients: + uranusjr
2021-02-24 09:26:40uranusjrsetmessageid: <1614158800.84.0.101101658017.issue43312@roundup.psfhosted.org>
2021-02-24 09:26:40uranusjrlinkissue43312 messages
2021-02-24 09:26:39uranusjrcreate