def get_scheme( dist_name, # type: str user=False, # type: bool home=None, # type: Optional[str] root=None, # type: Optional[str] isolated=False, # type: bool prefix=None, # type: Optional[str] ): # type: (...) -> Scheme """ Get the "scheme" corresponding to the input parameters. The distutils documentation provides the context for the available schemes: https://docs.python.org/3/install/index.html#alternate-installation :param dist_name: the name of the package to retrieve the scheme for, used in the headers scheme path :param user: indicates to use the "user" scheme :param home: indicates to use the "home" scheme and provides the base directory for the same :param root: root under which other directories are re-based :param isolated: equivalent to --no-user-cfg, i.e. do not consider ~/.pydistutils.cfg (posix) or ~/pydistutils.cfg (non-posix) for scheme paths :param prefix: indicates to use the "prefix" scheme and provides the base directory for the same """ scheme = _distutils_scheme(dist_name, user, home, root, isolated, prefix) return Scheme( platlib=scheme["platlib"], purelib=scheme["purelib"], headers=scheme["headers"], scripts=scheme["scripts"], data=scheme["data"], )
def prep(self, data, tmpdir): self.name = 'sample' self.wheelpath = data.packages.joinpath( 'sample-1.2.0-py2.py3-none-any.whl') self.req = Requirement('sample') self.src = os.path.join(tmpdir, 'src') self.dest = os.path.join(tmpdir, 'dest') self.scheme = Scheme( purelib=os.path.join(self.dest, 'lib'), platlib=os.path.join(self.dest, 'lib'), headers=os.path.join(self.dest, 'headers'), scripts=os.path.join(self.dest, 'bin'), data=os.path.join(self.dest, 'data'), ) self.src_dist_info = os.path.join(self.src, 'sample-1.2.0.dist-info') self.dest_dist_info = os.path.join(self.scheme.purelib, 'sample-1.2.0.dist-info')
def get_scheme( dist_name: str, user: bool = False, home: typing.Optional[str] = None, root: typing.Optional[str] = None, isolated: bool = False, prefix: typing.Optional[str] = None, ) -> Scheme: """ Get the "scheme" corresponding to the input parameters. :param dist_name: the name of the package to retrieve the scheme for, used in the headers scheme path :param user: indicates to use the "user" scheme :param home: indicates to use the "home" scheme :param root: root under which other directories are re-based :param isolated: ignored, but kept for distutils compatibility (where this controls whether the user-site pydistutils.cfg is honored) :param prefix: indicates to use the "prefix" scheme and provides the base directory for the same """ if user and prefix: raise InvalidSchemeCombination("--user", "--prefix") if home and prefix: raise InvalidSchemeCombination("--home", "--prefix") if home is not None: scheme_name = _infer_home() elif user: scheme_name = _infer_user() else: scheme_name = _infer_prefix() if home is not None: variables = {k: home for k in _HOME_KEYS} elif prefix is not None: variables = {k: prefix for k in _HOME_KEYS} else: variables = {} paths = sysconfig.get_paths(scheme=scheme_name, vars=variables) # Logic here is very arbitrary, we're doing it for compatibility, don't ask. # 1. Pip historically uses a special header path in virtual environments. # 2. If the distribution name is not known, distutils uses 'UNKNOWN'. We # only do the same when not running in a virtual environment because # pip's historical header path logic (see point 1) did not do this. if running_under_virtualenv(): if user: base = variables.get("userbase", sys.prefix) else: base = variables.get("base", sys.prefix) python_xy = f"python{get_major_minor_version()}" paths["include"] = os.path.join(base, "include", "site", python_xy) elif not dist_name: dist_name = "UNKNOWN" scheme = Scheme( platlib=paths["platlib"], purelib=paths["purelib"], headers=os.path.join(paths["include"], dist_name), scripts=paths["scripts"], data=paths["data"], ) if root is not None: for key in SCHEME_KEYS: value = distutils.util.change_root(root, getattr(scheme, key)) setattr(scheme, key, value) return scheme
def prep(self, data: TestData, tmpdir: str) -> None: # Since Path implements __add__, os.path.join returns a Path object. # Passing Path objects to interfaces expecting str (like # `compileall.compile_file`) can cause failures, so we normalize it # to a string here. tmpdir = str(tmpdir) self.name = "sample" self.wheelpath = make_wheel( "sample", "1.2.0", metadata_body=textwrap.dedent(""" A sample Python project ======================= ... """), metadata_updates={ "Requires-Dist": ["peppercorn"], }, extra_files={ "sample/__init__.py": textwrap.dedent(''' __version__ = '1.2.0' def main(): """Entry point for the application script""" print("Call your main application code here") '''), "sample/package_data.dat": "some data", }, extra_metadata_files={ "DESCRIPTION.rst": textwrap.dedent(""" A sample Python project ======================= ... """), "top_level.txt": "sample\n", "empty_dir/empty_dir/": "", }, extra_data_files={ "data/my_data/data_file": "some data", }, entry_points={ "console_scripts": ["sample = sample:main"], "gui_scripts": ["sample2 = sample:main"], }, ).save_to_dir(tmpdir) self.req = Requirement("sample") self.src = os.path.join(tmpdir, "src") self.dest = os.path.join(tmpdir, "dest") self.scheme = Scheme( purelib=os.path.join(self.dest, "lib"), platlib=os.path.join(self.dest, "lib"), headers=os.path.join(self.dest, "headers"), scripts=os.path.join(self.dest, "bin"), data=os.path.join(self.dest, "data"), ) self.src_dist_info = os.path.join(self.src, "sample-1.2.0.dist-info") self.dest_dist_info = os.path.join(self.scheme.purelib, "sample-1.2.0.dist-info")
def get_scheme( dist_name, # type: str user=False, # type: bool home=None, # type: typing.Optional[str] root=None, # type: typing.Optional[str] isolated=False, # type: bool prefix=None, # type: typing.Optional[str] ): # type: (...) -> Scheme """ Get the "scheme" corresponding to the input parameters. :param dist_name: the name of the package to retrieve the scheme for, used in the headers scheme path :param user: indicates to use the "user" scheme :param home: indicates to use the "home" scheme :param root: root under which other directories are re-based :param isolated: ignored, but kept for distutils compatibility (where this controls whether the user-site pydistutils.cfg is honored) :param prefix: indicates to use the "prefix" scheme and provides the base directory for the same """ if user and prefix: raise InvalidSchemeCombination("--user", "--prefix") if home and prefix: raise InvalidSchemeCombination("--home", "--prefix") if home is not None: scheme_name = _infer_home() elif user: scheme_name = _infer_user() else: scheme_name = _infer_prefix() if home is not None: variables = {k: home for k in _HOME_KEYS} elif prefix is not None: variables = {k: prefix for k in _HOME_KEYS} else: variables = {} paths = sysconfig.get_paths(scheme=scheme_name, vars=variables) # Pip historically uses a special header path in virtual environments. if running_under_virtualenv(): if user: base = variables.get("userbase", sys.prefix) else: base = variables.get("base", sys.prefix) python_xy = f"python{get_major_minor_version()}" paths["include"] = os.path.join(base, "include", "site", python_xy) # Special user scripts path on Windows for compatibility to distutils. # See ``distutils.commands.install.INSTALL_SCHEMES["nt_user"]["scripts"]``. if scheme_name == "nt_user": base = variables.get("userbase", sys.prefix) python_xy = f"Python{sys.version_info.major}{sys.version_info.minor}" paths["scripts"] = os.path.join(base, python_xy, "Scripts") scheme = Scheme( platlib=paths["platlib"], purelib=paths["purelib"], headers=os.path.join(paths["include"], dist_name), scripts=paths["scripts"], data=paths["data"], ) if root is not None: for key in SCHEME_KEYS: value = distutils.util.change_root(root, getattr(scheme, key)) setattr(scheme, key, value) return scheme