Common Code#
Common classes and values used around relenv.
- exception relenv.common.RelenvException#
Base class for exeptions generated from relenv.
- class relenv.common.WorkDirs(root)#
Simple class used to hold references to working directories relenv uses relative to a given root.
- Parameters:
root (str) – The root of the working directories tree
- relenv.common.archived_build(triplet=None)#
Finds a the location of an archived build.
- Parameters:
triplet (str) – The build triplet to find
- Returns:
The location of the archived build
- Return type:
pathlib.Path
- relenv.common.build_arch()#
Return the current machine.
- relenv.common.check_url(url, timeout=30)#
Check that the url returns a 200.
- relenv.common.download_url(url, dest, verbose=True, backoff=3, timeout=60)#
Download the url to the provided destination.
This method assumes the last part of the url is a filename. (https://foo.com/bar/myfile.tar.xz)
- Parameters:
url (str) – The url to download
dest (str) – Where to download the url to
verbose (bool) – Print download url and destination to stdout
- Raises:
urllib.error.HTTPError – If the url was unable to be downloaded
- Returns:
The path to the downloaded content
- Return type:
str
- relenv.common.extract_archive(to_dir, archive)#
Extract an archive to a specific location.
- Parameters:
to_dir (str) – The directory to extract to
archive (str) – The archive to extract
- relenv.common.fetch_url(url, fp, backoff=3, timeout=30)#
Fetch the contents of a url.
This method will store the contents in the given file like object.
- relenv.common.format_shebang(python, tpl='#!/bin/sh\n"true" \'\'\'\'\n"exec" "$(dirname "$(readlink -f "$0")"){}" "$0" "$@"\n\'\'\'\n')#
Return a formatted shebang.
- relenv.common.get_download_location(url, dest)#
Get the full path to where the url will be downloaded to.
- Parameters:
url (str) – The url to donwload
dest (str) – Where to download the url to
- Returns:
The path to where the url will be downloaded to
- Return type:
str
- relenv.common.get_toolchain(arch=None, root=None)#
Get a the toolchain directory, specific to the arch if supplied.
- Parameters:
arch (str) – The architecture to get the toolchain for
root (str) – The root of the relenv working directories to search in
- Returns:
The directory holding the toolchain
- Return type:
pathlib.Path
- relenv.common.get_triplet(machine=None, plat=None)#
Get the target triplet for the specified machine and platform.
If any of the args are None, it will try to deduce what they should be.
- Parameters:
machine (str) – The machine for the triplet
plat (str) – The platform for the triplet
- Raises:
RelenvException – If the platform is unknown
- Returns:
The target triplet
- Return type:
str
- relenv.common.list_archived_builds()#
Return a list of version, architecture and platforms for builds.
- relenv.common.plat_from_triplet(plat)#
Convert platform from build to the value of sys.platform.
- relenv.common.relative_interpreter(root_dir, scripts_dir, interpreter)#
Return a relativized path to the given scripts_dir and interpreter.
- relenv.common.runcmd(*args, **kwargs)#
Run a command.
Run the provided command, raising an Exception when the command finishes with a non zero exit code. Arguments are passed through to
subprocess.run
- Returns:
The process result
- Return type:
subprocess.CompletedProcess
- Raises:
RelenvException – If the command finishes with a non zero exit code
- relenv.common.sanitize_sys_path(sys_path_entries)#
Sanitize sys.path to only include paths relative to the onedir environment.
- relenv.common.work_dir(name, root=None)#
Get the absolute path to the relenv working directory of the given name.
- Parameters:
name (str) – The name of the directory
root (str) – The root directory that this working directory will be relative to
- Returns:
An absolute path to the requested relenv working directory
- Return type:
pathlib.Path
- relenv.common.work_dirs(root=None)#
Returns a WorkDirs instance based on the given root.
- Parameters:
root (str) – The desired root of relenv’s working directories
- Returns:
A WorkDirs instance based on the given root
- Return type:
relenv.common.WorkDirs
- relenv.common.work_root(root=None)#
Get the root directory that all other relenv working directories should be based on.
- Parameters:
root (str) – An explicitly requested root directory
- Returns:
An absolute path to the relenv root working directory
- Return type:
pathlib.Path