remove venv from files
This commit is contained in:
parent
3ae5f60f00
commit
e8044710a5
@ -1,247 +0,0 @@
|
|||||||
<#
|
|
||||||
.Synopsis
|
|
||||||
Activate a Python virtual environment for the current PowerShell session.
|
|
||||||
|
|
||||||
.Description
|
|
||||||
Pushes the python executable for a virtual environment to the front of the
|
|
||||||
$Env:PATH environment variable and sets the prompt to signify that you are
|
|
||||||
in a Python virtual environment. Makes use of the command line switches as
|
|
||||||
well as the `pyvenv.cfg` file values present in the virtual environment.
|
|
||||||
|
|
||||||
.Parameter VenvDir
|
|
||||||
Path to the directory that contains the virtual environment to activate. The
|
|
||||||
default value for this is the parent of the directory that the Activate.ps1
|
|
||||||
script is located within.
|
|
||||||
|
|
||||||
.Parameter Prompt
|
|
||||||
The prompt prefix to display when this virtual environment is activated. By
|
|
||||||
default, this prompt is the name of the virtual environment folder (VenvDir)
|
|
||||||
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1
|
|
||||||
Activates the Python virtual environment that contains the Activate.ps1 script.
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1 -Verbose
|
|
||||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
|
||||||
and shows extra information about the activation as it executes.
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
|
||||||
Activates the Python virtual environment located in the specified location.
|
|
||||||
|
|
||||||
.Example
|
|
||||||
Activate.ps1 -Prompt "MyPython"
|
|
||||||
Activates the Python virtual environment that contains the Activate.ps1 script,
|
|
||||||
and prefixes the current prompt with the specified string (surrounded in
|
|
||||||
parentheses) while the virtual environment is active.
|
|
||||||
|
|
||||||
.Notes
|
|
||||||
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
|
||||||
execution policy for the user. You can do this by issuing the following PowerShell
|
|
||||||
command:
|
|
||||||
|
|
||||||
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
|
||||||
|
|
||||||
For more information on Execution Policies:
|
|
||||||
https://go.microsoft.com/fwlink/?LinkID=135170
|
|
||||||
|
|
||||||
#>
|
|
||||||
Param(
|
|
||||||
[Parameter(Mandatory = $false)]
|
|
||||||
[String]
|
|
||||||
$VenvDir,
|
|
||||||
[Parameter(Mandatory = $false)]
|
|
||||||
[String]
|
|
||||||
$Prompt
|
|
||||||
)
|
|
||||||
|
|
||||||
<# Function declarations --------------------------------------------------- #>
|
|
||||||
|
|
||||||
<#
|
|
||||||
.Synopsis
|
|
||||||
Remove all shell session elements added by the Activate script, including the
|
|
||||||
addition of the virtual environment's Python executable from the beginning of
|
|
||||||
the PATH variable.
|
|
||||||
|
|
||||||
.Parameter NonDestructive
|
|
||||||
If present, do not remove this function from the global namespace for the
|
|
||||||
session.
|
|
||||||
|
|
||||||
#>
|
|
||||||
function global:deactivate ([switch]$NonDestructive) {
|
|
||||||
# Revert to original values
|
|
||||||
|
|
||||||
# The prior prompt:
|
|
||||||
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
|
||||||
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
|
||||||
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
|
||||||
}
|
|
||||||
|
|
||||||
# The prior PYTHONHOME:
|
|
||||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
|
||||||
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
|
||||||
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
|
||||||
}
|
|
||||||
|
|
||||||
# The prior PATH:
|
|
||||||
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
|
||||||
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
|
||||||
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
|
||||||
}
|
|
||||||
|
|
||||||
# Just remove the VIRTUAL_ENV altogether:
|
|
||||||
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
|
||||||
Remove-Item -Path env:VIRTUAL_ENV
|
|
||||||
}
|
|
||||||
|
|
||||||
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
|
||||||
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
|
||||||
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
|
||||||
}
|
|
||||||
|
|
||||||
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
|
||||||
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
|
||||||
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
|
||||||
}
|
|
||||||
|
|
||||||
# Leave deactivate function in the global namespace if requested:
|
|
||||||
if (-not $NonDestructive) {
|
|
||||||
Remove-Item -Path function:deactivate
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
<#
|
|
||||||
.Description
|
|
||||||
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
|
||||||
given folder, and returns them in a map.
|
|
||||||
|
|
||||||
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
|
||||||
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
|
||||||
then it is considered a `key = value` line. The left hand string is the key,
|
|
||||||
the right hand is the value.
|
|
||||||
|
|
||||||
If the value starts with a `'` or a `"` then the first and last character is
|
|
||||||
stripped from the value before being captured.
|
|
||||||
|
|
||||||
.Parameter ConfigDir
|
|
||||||
Path to the directory that contains the `pyvenv.cfg` file.
|
|
||||||
#>
|
|
||||||
function Get-PyVenvConfig(
|
|
||||||
[String]
|
|
||||||
$ConfigDir
|
|
||||||
) {
|
|
||||||
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
|
||||||
|
|
||||||
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
|
||||||
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
|
||||||
|
|
||||||
# An empty map will be returned if no config file is found.
|
|
||||||
$pyvenvConfig = @{ }
|
|
||||||
|
|
||||||
if ($pyvenvConfigPath) {
|
|
||||||
|
|
||||||
Write-Verbose "File exists, parse `key = value` lines"
|
|
||||||
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
|
||||||
|
|
||||||
$pyvenvConfigContent | ForEach-Object {
|
|
||||||
$keyval = $PSItem -split "\s*=\s*", 2
|
|
||||||
if ($keyval[0] -and $keyval[1]) {
|
|
||||||
$val = $keyval[1]
|
|
||||||
|
|
||||||
# Remove extraneous quotations around a string value.
|
|
||||||
if ("'""".Contains($val.Substring(0, 1))) {
|
|
||||||
$val = $val.Substring(1, $val.Length - 2)
|
|
||||||
}
|
|
||||||
|
|
||||||
$pyvenvConfig[$keyval[0]] = $val
|
|
||||||
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $pyvenvConfig
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
<# Begin Activate script --------------------------------------------------- #>
|
|
||||||
|
|
||||||
# Determine the containing directory of this script
|
|
||||||
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
||||||
$VenvExecDir = Get-Item -Path $VenvExecPath
|
|
||||||
|
|
||||||
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
|
||||||
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
|
||||||
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
|
||||||
|
|
||||||
# Set values required in priority: CmdLine, ConfigFile, Default
|
|
||||||
# First, get the location of the virtual environment, it might not be
|
|
||||||
# VenvExecDir if specified on the command line.
|
|
||||||
if ($VenvDir) {
|
|
||||||
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
|
||||||
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
|
||||||
Write-Verbose "VenvDir=$VenvDir"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Next, read the `pyvenv.cfg` file to determine any required value such
|
|
||||||
# as `prompt`.
|
|
||||||
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
|
||||||
|
|
||||||
# Next, set the prompt from the command line, or the config file, or
|
|
||||||
# just use the name of the virtual environment folder.
|
|
||||||
if ($Prompt) {
|
|
||||||
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
|
||||||
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
|
||||||
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
|
||||||
$Prompt = $pyvenvCfg['prompt'];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
|
||||||
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
|
||||||
$Prompt = Split-Path -Path $venvDir -Leaf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Verbose "Prompt = '$Prompt'"
|
|
||||||
Write-Verbose "VenvDir='$VenvDir'"
|
|
||||||
|
|
||||||
# Deactivate any currently active virtual environment, but leave the
|
|
||||||
# deactivate function in place.
|
|
||||||
deactivate -nondestructive
|
|
||||||
|
|
||||||
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
|
||||||
# that there is an activated venv.
|
|
||||||
$env:VIRTUAL_ENV = $VenvDir
|
|
||||||
|
|
||||||
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
|
||||||
|
|
||||||
Write-Verbose "Setting prompt to '$Prompt'"
|
|
||||||
|
|
||||||
# Set the prompt to include the env name
|
|
||||||
# Make sure _OLD_VIRTUAL_PROMPT is global
|
|
||||||
function global:_OLD_VIRTUAL_PROMPT { "" }
|
|
||||||
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
|
||||||
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
|
||||||
|
|
||||||
function global:prompt {
|
|
||||||
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
|
||||||
_OLD_VIRTUAL_PROMPT
|
|
||||||
}
|
|
||||||
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
|
||||||
}
|
|
||||||
|
|
||||||
# Clear PYTHONHOME
|
|
||||||
if (Test-Path -Path Env:PYTHONHOME) {
|
|
||||||
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
|
||||||
Remove-Item -Path Env:PYTHONHOME
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add the venv to the PATH
|
|
||||||
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
|
||||||
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
|
@ -1,70 +0,0 @@
|
|||||||
# This file must be used with "source bin/activate" *from bash*
|
|
||||||
# You cannot run it directly
|
|
||||||
|
|
||||||
deactivate () {
|
|
||||||
# reset old environment variables
|
|
||||||
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
|
||||||
PATH="${_OLD_VIRTUAL_PATH:-}"
|
|
||||||
export PATH
|
|
||||||
unset _OLD_VIRTUAL_PATH
|
|
||||||
fi
|
|
||||||
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
|
||||||
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
|
||||||
export PYTHONHOME
|
|
||||||
unset _OLD_VIRTUAL_PYTHONHOME
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Call hash to forget past commands. Without forgetting
|
|
||||||
# past commands the $PATH changes we made may not be respected
|
|
||||||
hash -r 2> /dev/null
|
|
||||||
|
|
||||||
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
|
||||||
PS1="${_OLD_VIRTUAL_PS1:-}"
|
|
||||||
export PS1
|
|
||||||
unset _OLD_VIRTUAL_PS1
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset VIRTUAL_ENV
|
|
||||||
unset VIRTUAL_ENV_PROMPT
|
|
||||||
if [ ! "${1:-}" = "nondestructive" ] ; then
|
|
||||||
# Self destruct!
|
|
||||||
unset -f deactivate
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# unset irrelevant variables
|
|
||||||
deactivate nondestructive
|
|
||||||
|
|
||||||
# on Windows, a path can contain colons and backslashes and has to be converted:
|
|
||||||
if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then
|
|
||||||
# transform D:\path\to\venv to /d/path/to/venv on MSYS
|
|
||||||
# and to /cygdrive/d/path/to/venv on Cygwin
|
|
||||||
export VIRTUAL_ENV=$(cygpath /opt/kugelstossmeeting-ticketing/venv)
|
|
||||||
else
|
|
||||||
# use the path as-is
|
|
||||||
export VIRTUAL_ENV=/opt/kugelstossmeeting-ticketing/venv
|
|
||||||
fi
|
|
||||||
|
|
||||||
_OLD_VIRTUAL_PATH="$PATH"
|
|
||||||
PATH="$VIRTUAL_ENV/"bin":$PATH"
|
|
||||||
export PATH
|
|
||||||
|
|
||||||
# unset PYTHONHOME if set
|
|
||||||
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
|
||||||
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
|
||||||
if [ -n "${PYTHONHOME:-}" ] ; then
|
|
||||||
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
|
||||||
unset PYTHONHOME
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
|
||||||
_OLD_VIRTUAL_PS1="${PS1:-}"
|
|
||||||
PS1='(venv) '"${PS1:-}"
|
|
||||||
export PS1
|
|
||||||
VIRTUAL_ENV_PROMPT='(venv) '
|
|
||||||
export VIRTUAL_ENV_PROMPT
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Call hash to forget past commands. Without forgetting
|
|
||||||
# past commands the $PATH changes we made may not be respected
|
|
||||||
hash -r 2> /dev/null
|
|
@ -1,27 +0,0 @@
|
|||||||
# This file must be used with "source bin/activate.csh" *from csh*.
|
|
||||||
# You cannot run it directly.
|
|
||||||
|
|
||||||
# Created by Davide Di Blasi <davidedb@gmail.com>.
|
|
||||||
# Ported to Python 3.3 venv by Andrew Svetlov <andrew.svetlov@gmail.com>
|
|
||||||
|
|
||||||
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
|
||||||
|
|
||||||
# Unset irrelevant variables.
|
|
||||||
deactivate nondestructive
|
|
||||||
|
|
||||||
setenv VIRTUAL_ENV /opt/kugelstossmeeting-ticketing/venv
|
|
||||||
|
|
||||||
set _OLD_VIRTUAL_PATH="$PATH"
|
|
||||||
setenv PATH "$VIRTUAL_ENV/"bin":$PATH"
|
|
||||||
|
|
||||||
|
|
||||||
set _OLD_VIRTUAL_PROMPT="$prompt"
|
|
||||||
|
|
||||||
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
|
||||||
set prompt = '(venv) '"$prompt"
|
|
||||||
setenv VIRTUAL_ENV_PROMPT '(venv) '
|
|
||||||
endif
|
|
||||||
|
|
||||||
alias pydoc python -m pydoc
|
|
||||||
|
|
||||||
rehash
|
|
@ -1,69 +0,0 @@
|
|||||||
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
|
||||||
# (https://fishshell.com/). You cannot run it directly.
|
|
||||||
|
|
||||||
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
|
||||||
# reset old environment variables
|
|
||||||
if test -n "$_OLD_VIRTUAL_PATH"
|
|
||||||
set -gx PATH $_OLD_VIRTUAL_PATH
|
|
||||||
set -e _OLD_VIRTUAL_PATH
|
|
||||||
end
|
|
||||||
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
|
||||||
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
|
||||||
set -e _OLD_VIRTUAL_PYTHONHOME
|
|
||||||
end
|
|
||||||
|
|
||||||
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
|
||||||
set -e _OLD_FISH_PROMPT_OVERRIDE
|
|
||||||
# prevents error when using nested fish instances (Issue #93858)
|
|
||||||
if functions -q _old_fish_prompt
|
|
||||||
functions -e fish_prompt
|
|
||||||
functions -c _old_fish_prompt fish_prompt
|
|
||||||
functions -e _old_fish_prompt
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
set -e VIRTUAL_ENV
|
|
||||||
set -e VIRTUAL_ENV_PROMPT
|
|
||||||
if test "$argv[1]" != "nondestructive"
|
|
||||||
# Self-destruct!
|
|
||||||
functions -e deactivate
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Unset irrelevant variables.
|
|
||||||
deactivate nondestructive
|
|
||||||
|
|
||||||
set -gx VIRTUAL_ENV /opt/kugelstossmeeting-ticketing/venv
|
|
||||||
|
|
||||||
set -gx _OLD_VIRTUAL_PATH $PATH
|
|
||||||
set -gx PATH "$VIRTUAL_ENV/"bin $PATH
|
|
||||||
|
|
||||||
# Unset PYTHONHOME if set.
|
|
||||||
if set -q PYTHONHOME
|
|
||||||
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
|
||||||
set -e PYTHONHOME
|
|
||||||
end
|
|
||||||
|
|
||||||
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
|
||||||
# fish uses a function instead of an env var to generate the prompt.
|
|
||||||
|
|
||||||
# Save the current fish_prompt function as the function _old_fish_prompt.
|
|
||||||
functions -c fish_prompt _old_fish_prompt
|
|
||||||
|
|
||||||
# With the original prompt function renamed, we can override with our own.
|
|
||||||
function fish_prompt
|
|
||||||
# Save the return status of the last command.
|
|
||||||
set -l old_status $status
|
|
||||||
|
|
||||||
# Output the venv prompt; color taken from the blue of the Python logo.
|
|
||||||
printf "%s%s%s" (set_color 4B8BBE) '(venv) ' (set_color normal)
|
|
||||||
|
|
||||||
# Restore the return status of the previous command.
|
|
||||||
echo "exit $old_status" | .
|
|
||||||
# Output the original/"old" prompt.
|
|
||||||
_old_fish_prompt
|
|
||||||
end
|
|
||||||
|
|
||||||
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
|
||||||
set -gx VIRTUAL_ENV_PROMPT '(venv) '
|
|
||||||
end
|
|
@ -1,8 +0,0 @@
|
|||||||
#!/opt/kugelstossmeeting-ticketing/venv/bin/python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pip._internal.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
@ -1,8 +0,0 @@
|
|||||||
#!/opt/kugelstossmeeting-ticketing/venv/bin/python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pip._internal.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
@ -1,8 +0,0 @@
|
|||||||
#!/opt/kugelstossmeeting-ticketing/venv/bin/python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from pip._internal.cli.main import main
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
|
||||||
sys.exit(main())
|
|
@ -1 +0,0 @@
|
|||||||
python3
|
|
@ -1 +0,0 @@
|
|||||||
/usr/bin/python3
|
|
@ -1 +0,0 @@
|
|||||||
python3
|
|
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
pip
|
|
@ -1,201 +0,0 @@
|
|||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright {yyyy} {name of copyright owner}
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
@ -1,320 +0,0 @@
|
|||||||
Metadata-Version: 2.1
|
|
||||||
Name: cysystemd
|
|
||||||
Version: 1.6.2
|
|
||||||
Summary: systemd wrapper in Cython
|
|
||||||
Home-page: http://github.com/mosquito/cysystemd
|
|
||||||
Author: Dmitry Orlov <me@mosquito.su>
|
|
||||||
Author-email: me@mosquito.su
|
|
||||||
License: Apache
|
|
||||||
Keywords: systemd,python,daemon,sd_notify,cython
|
|
||||||
Platform: POSIX
|
|
||||||
Classifier: Development Status :: 4 - Beta
|
|
||||||
Classifier: Environment :: Console
|
|
||||||
Classifier: Intended Audience :: Developers
|
|
||||||
Classifier: Intended Audience :: Education
|
|
||||||
Classifier: Intended Audience :: End Users/Desktop
|
|
||||||
Classifier: License :: OSI Approved :: Apache Software License
|
|
||||||
Classifier: Natural Language :: English
|
|
||||||
Classifier: Natural Language :: Russian
|
|
||||||
Classifier: Operating System :: POSIX :: Linux
|
|
||||||
Classifier: Programming Language :: Cython
|
|
||||||
Classifier: Programming Language :: Python
|
|
||||||
Classifier: Programming Language :: Python :: 3
|
|
||||||
Classifier: Programming Language :: Python :: 3.8
|
|
||||||
Classifier: Programming Language :: Python :: 3.9
|
|
||||||
Classifier: Programming Language :: Python :: 3.10
|
|
||||||
Classifier: Programming Language :: Python :: 3.11
|
|
||||||
Classifier: Programming Language :: Python :: 3.12
|
|
||||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
||||||
Classifier: Topic :: Software Development :: Libraries
|
|
||||||
Classifier: Topic :: System
|
|
||||||
Classifier: Topic :: System :: Operating System
|
|
||||||
Provides: systemd
|
|
||||||
Requires-Python: >3.6, <4
|
|
||||||
Description-Content-Type: text/markdown
|
|
||||||
License-File: LICENSE
|
|
||||||
|
|
||||||
![pypi version](https://img.shields.io/pypi/v/cysystemd.svg) ![](https://img.shields.io/pypi/pyversions/cysystemd.svg) ![License](https://img.shields.io/pypi/l/cysystemd.svg)
|
|
||||||
|
|
||||||
# systemd wrapper in Cython
|
|
||||||
|
|
||||||
Python systemd wrapper using Cython.
|
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
All packages available on `github releases <https://github.com/mosquito/cysystemd/releases>`_.
|
|
||||||
|
|
||||||
### Installation from binary wheels
|
|
||||||
|
|
||||||
* wheels is now available for Python 3.8, 3.9, 3.10, 3.11, 3.12
|
|
||||||
for `x86_64` and `arm64`
|
|
||||||
|
|
||||||
```shell
|
|
||||||
python3.10 -m pip install \
|
|
||||||
https://github.com/mosquito/cysystemd/releases/download/1.6.2/cysystemd-1.6.2-cp310-cp310-linux_x86_64.whl
|
|
||||||
```
|
|
||||||
|
|
||||||
### Installation from sources
|
|
||||||
|
|
||||||
You **must** install **systemd headers**
|
|
||||||
|
|
||||||
For Debian/Ubuntu users:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
apt install build-essential libsystemd-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
On older versions of Debian/Ubuntu, you might also need to install:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
apt install libsystemd-daemon-dev libsystemd-journal-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
For CentOS/RHEL
|
|
||||||
|
|
||||||
```shell
|
|
||||||
yum install gcc systemd-devel
|
|
||||||
```
|
|
||||||
|
|
||||||
And install it from pypi
|
|
||||||
|
|
||||||
```shell
|
|
||||||
pip install cysystemd
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage examples
|
|
||||||
|
|
||||||
### Writing to journald
|
|
||||||
|
|
||||||
#### Logging handler for python logger
|
|
||||||
|
|
||||||
```python
|
|
||||||
from cysystemd import journal
|
|
||||||
import logging
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
|
||||||
logger = logging.getLogger()
|
|
||||||
logger.addHandler(journal.JournaldLogHandler())
|
|
||||||
|
|
||||||
try:
|
|
||||||
logger.info("Trying to do something")
|
|
||||||
raise Exception('foo')
|
|
||||||
except:
|
|
||||||
logger.exception("Test Exception %s", 1)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### systemd daemon notification
|
|
||||||
|
|
||||||
|
|
||||||
```python
|
|
||||||
from cysystemd.daemon import notify, Notification
|
|
||||||
|
|
||||||
# Send READY=1
|
|
||||||
notify(Notification.READY)
|
|
||||||
|
|
||||||
# Send status
|
|
||||||
notify(Notification.STATUS, "I'm fine.")
|
|
||||||
|
|
||||||
# Send stopping
|
|
||||||
notify(Notification.STOPPING)
|
|
||||||
```
|
|
||||||
|
|
||||||
Write message into systemd journal:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from cysystemd import journal
|
|
||||||
|
|
||||||
|
|
||||||
journal.write("Hello Lennart")
|
|
||||||
|
|
||||||
# Or send structured data
|
|
||||||
journal.send(
|
|
||||||
message="Hello Lennart",
|
|
||||||
priority=journal.Priority.INFO,
|
|
||||||
some_field='some value',
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Reading journald
|
|
||||||
|
|
||||||
#### Reading all systemd records
|
|
||||||
|
|
||||||
```python
|
|
||||||
|
|
||||||
from cysystemd.reader import JournalReader, JournalOpenMode
|
|
||||||
|
|
||||||
journal_reader = JournalReader()
|
|
||||||
journal_reader.open(JournalOpenMode.SYSTEM)
|
|
||||||
journal_reader.seek_head()
|
|
||||||
|
|
||||||
for record in journal_reader:
|
|
||||||
print(record.data['MESSAGE'])
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Read only cron logs
|
|
||||||
|
|
||||||
```python
|
|
||||||
from cysystemd.reader import JournalReader, JournalOpenMode, Rule
|
|
||||||
|
|
||||||
|
|
||||||
rules = (
|
|
||||||
Rule("SYSLOG_IDENTIFIER", "CRON") &
|
|
||||||
Rule("_SYSTEMD_UNIT", "crond.service") |
|
|
||||||
Rule("_SYSTEMD_UNIT", "cron.service")
|
|
||||||
)
|
|
||||||
|
|
||||||
cron_reader = JournalReader()
|
|
||||||
cron_reader.open(JournalOpenMode.SYSTEM)
|
|
||||||
cron_reader.seek_head()
|
|
||||||
cron_reader.add_filter(rules)
|
|
||||||
|
|
||||||
for record in cron_reader:
|
|
||||||
print(record.data['MESSAGE'])
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Polling records
|
|
||||||
|
|
||||||
```python
|
|
||||||
from cysystemd.reader import JournalReader, JournalOpenMode
|
|
||||||
|
|
||||||
|
|
||||||
reader = JournalReader()
|
|
||||||
reader.open(JournalOpenMode.SYSTEM)
|
|
||||||
reader.seek_tail()
|
|
||||||
|
|
||||||
poll_timeout = 255
|
|
||||||
|
|
||||||
while True:
|
|
||||||
reader.wait(poll_timeout)
|
|
||||||
|
|
||||||
for record in reader:
|
|
||||||
print(record.data['MESSAGE'])
|
|
||||||
```
|
|
||||||
|
|
||||||
#### journald open modes
|
|
||||||
|
|
||||||
* `CURRENT_USER`
|
|
||||||
* `LOCAL_ONLY`
|
|
||||||
* `RUNTIME_ONLY`
|
|
||||||
* `SYSTEM`
|
|
||||||
* `SYSTEM_ONLY` - deprecated alias of `SYSTEM`
|
|
||||||
|
|
||||||
|
|
||||||
```python
|
|
||||||
from cysystemd.reader import JournalReader, JournalOpenMode
|
|
||||||
|
|
||||||
|
|
||||||
reader = JournalReader()
|
|
||||||
reader.open(JournalOpenMode.CURRENT_USER)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### journald entry
|
|
||||||
|
|
||||||
JournalEntry class has some special properties and methods:
|
|
||||||
|
|
||||||
* `data` - journal entry content (`dict`)
|
|
||||||
* `date` - entry timestamp (`datetime` instance)
|
|
||||||
* `cursor` - systemd identification bytes for this entry
|
|
||||||
* `boot_id()` - returns bootid
|
|
||||||
* `get_realtime_sec()` - entry epoch (`float`)
|
|
||||||
* `get_realtime_usec()` - entry epoch (`int` microseconds)
|
|
||||||
* `get_monotonic_sec()` - entry monotonic time (`float`)
|
|
||||||
* `get_monotonic_usec()` - entry monotonic time (`int` microseconds)
|
|
||||||
* `__getitem__(key)` - shoutcut for `entry.data[key]`
|
|
||||||
|
|
||||||
|
|
||||||
#### journald reader
|
|
||||||
|
|
||||||
JournalReader class has some special properties and methods:
|
|
||||||
|
|
||||||
* `open(flags=JournalOpenMode.CURRENT_USER)` - opening journald
|
|
||||||
with selected mode
|
|
||||||
* `open_directory(path)` - opening journald from path
|
|
||||||
* `open_files(*filename)` - opening journald from files
|
|
||||||
* `data_threshold` - may be used to get or set the data field size threshold
|
|
||||||
for data returned by fething entry data.
|
|
||||||
* `closed` - returns True when journal reader closed
|
|
||||||
* `locked` - returns True when journal reader locked
|
|
||||||
* `idle` - returns True when journal reader opened
|
|
||||||
* `seek_head` - move reader pointer to the first entry
|
|
||||||
* `seek_tail` - move reader pointer to the last entry
|
|
||||||
* `seek_monotonic_usec` - seeks to the entry with the specified monotonic
|
|
||||||
timestamp, i.e. CLOCK_MONOTONIC. Since monotonic time restarts on every
|
|
||||||
reboot a boot ID needs to be specified as well.
|
|
||||||
* `seek_realtime_usec` - seeks to the entry with the specified realtime
|
|
||||||
(wallclock) timestamp, i.e. CLOCK_REALTIME. Note that the realtime clock
|
|
||||||
is not necessarily monotonic. If a realtime timestamp is ambiguous, it is
|
|
||||||
not defined which position is sought to.
|
|
||||||
* `seek_cursor` - seeks to the entry located at the specified cursor
|
|
||||||
(see `JournalEntry.cursor`).
|
|
||||||
* `wait(timeout)` - It will synchronously wait until the journal gets
|
|
||||||
changed. The maximum time this call sleeps may be controlled with the
|
|
||||||
timeout_usec parameter.
|
|
||||||
* `__iter__` - returns JournalReader object
|
|
||||||
* `__next__` - calls `next()` or raise `StopIteration`
|
|
||||||
* `next(skip=0)` - returns the next `JournalEntry`. The `skip`
|
|
||||||
parameter skips some entries.
|
|
||||||
* `previous(skip=0)` - returns the previous `JournalEntry`.
|
|
||||||
The `skip` parameter skips some entries.
|
|
||||||
* `skip_next(skip)` - skips next entries.
|
|
||||||
* `skip_previous(skip)` - skips next entries.
|
|
||||||
* `add_filter(rule)` - adding filter rule.
|
|
||||||
See `read-only-cron-logs`_ as example.
|
|
||||||
* `clear_filter` - reset all filters
|
|
||||||
* `fd` - returns a special file descriptor
|
|
||||||
* `events` - returns `EPOLL` events
|
|
||||||
* `timeout` - returns internal timeout
|
|
||||||
* `process_events()` - After each poll() wake-up process_events() needs
|
|
||||||
to be called to process events. This call will also indicate what kind of
|
|
||||||
change has been detected.
|
|
||||||
* `get_catalog()` - retrieves a message catalog entry for the current
|
|
||||||
journal entry. This will look up an entry in the message catalog by using
|
|
||||||
the "MESSAGE_ID=" field of the current journal entry. Before returning
|
|
||||||
the entry all journal field names in the catalog entry text enclosed in
|
|
||||||
"@" will be replaced by the respective field values of the current entry.
|
|
||||||
If a field name referenced in the message catalog entry does not exist,
|
|
||||||
in the current journal entry, the "@" will be removed, but the field name
|
|
||||||
otherwise left untouched.
|
|
||||||
* `get_catalog_for_message_id(message_id: UUID)` - works similar to
|
|
||||||
`get_catalog()` but the entry is looked up by the specified
|
|
||||||
message ID (no open journal context is necessary for this),
|
|
||||||
and no field substitution is performed.
|
|
||||||
|
|
||||||
|
|
||||||
### Asyncio support
|
|
||||||
|
|
||||||
Initial `asyncio` support for reading journal asynchronously.
|
|
||||||
|
|
||||||
#### AsyncJournalReader
|
|
||||||
|
|
||||||
Blocking methods were wrapped by threads.
|
|
||||||
Method `wait()` use epoll on journald file descriptor.
|
|
||||||
|
|
||||||
```python
|
|
||||||
import asyncio
|
|
||||||
import json
|
|
||||||
|
|
||||||
from cysystemd.reader import JournalOpenMode
|
|
||||||
from cysystemd.async_reader import AsyncJournalReader
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
|
||||||
reader = AsyncJournalReader()
|
|
||||||
await reader.open(JournalOpenMode.SYSTEM)
|
|
||||||
await reader.seek_tail()
|
|
||||||
|
|
||||||
while await reader.wait():
|
|
||||||
async for record in reader:
|
|
||||||
print(
|
|
||||||
json.dumps(
|
|
||||||
record.data,
|
|
||||||
indent=1,
|
|
||||||
sort_keys=True
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
asyncio.run(main())
|
|
||||||
```
|
|
@ -1,18 +0,0 @@
|
|||||||
cysystemd-1.6.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
|
||||||
cysystemd-1.6.2.dist-info/LICENSE,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
||||||
cysystemd-1.6.2.dist-info/METADATA,sha256=4oFqUBKWQyG9qs9sjQHlKqDhPTRoGXF1_J4IndTmSzs,8965
|
|
||||||
cysystemd-1.6.2.dist-info/RECORD,,
|
|
||||||
cysystemd-1.6.2.dist-info/WHEEL,sha256=dmB08qEoX1BrR79mbewHdhOYI-eFe6IF8EPt_OSkMdg,104
|
|
||||||
cysystemd-1.6.2.dist-info/top_level.txt,sha256=sVxBjISgOxvUfs5fe5g_Zduu50pOo9MA2rofPIr4Plc,10
|
|
||||||
cysystemd/__init__.py,sha256=1Ani7bzbH7IJFTUfMHQP2zBpZNZYHc2LH32HByt8HcM,467
|
|
||||||
cysystemd/__pycache__/__init__.cpython-312.pyc,,
|
|
||||||
cysystemd/__pycache__/async_reader.cpython-312.pyc,,
|
|
||||||
cysystemd/__pycache__/daemon.cpython-312.pyc,,
|
|
||||||
cysystemd/__pycache__/journal.cpython-312.pyc,,
|
|
||||||
cysystemd/_daemon.cpython-312-x86_64-linux-gnu.so,sha256=BvgXZ_xeh26feevqpVEPz4j6dgrur8gnGjF7rqcHPWw,194200
|
|
||||||
cysystemd/_journal.cpython-312-x86_64-linux-gnu.so,sha256=kGELCGri36_oJUVmEnQ-EYm2oaIkb55OUJG0OZsOETU,331312
|
|
||||||
cysystemd/async_reader.py,sha256=eCrvagwU58JP1DmY-3pJNBp4uF1JQKp1oDjDJa1QZPs,6146
|
|
||||||
cysystemd/daemon.py,sha256=5xiasPBElGI1aa48yEDK10qYYP2RzCm8sQFO2s1Bxzs,2661
|
|
||||||
cysystemd/journal.py,sha256=f4dpqUHk3IQJSX0VKaPb-rKuRf26tFtjDcfHHGkw5fc,4880
|
|
||||||
cysystemd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
||||||
cysystemd/reader.cpython-312-x86_64-linux-gnu.so,sha256=oe3oPlGDjMm_YKjqoyiBP9RsgO188OauC2WPkiOXyPw,1685808
|
|
@ -1,5 +0,0 @@
|
|||||||
Wheel-Version: 1.0
|
|
||||||
Generator: setuptools (75.7.0)
|
|
||||||
Root-Is-Purelib: false
|
|
||||||
Tag: cp312-cp312-linux_x86_64
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
cysystemd
|
|
@ -1,22 +0,0 @@
|
|||||||
package_info = "systemd wrapper in Cython"
|
|
||||||
version_info = (1, 6, 2)
|
|
||||||
|
|
||||||
|
|
||||||
author_info = (("Dmitry Orlov", "me@mosquito.su"),)
|
|
||||||
|
|
||||||
author_email = ", ".join("{}".format(info[1]) for info in author_info)
|
|
||||||
|
|
||||||
license = "Apache"
|
|
||||||
|
|
||||||
__version__ = ".".join(str(x) for x in version_info)
|
|
||||||
__author__ = ", ".join("{} <{}>".format(*info) for info in author_info)
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
|
||||||
"__author__",
|
|
||||||
"__version__",
|
|
||||||
"author_info",
|
|
||||||
"license",
|
|
||||||
"package_info",
|
|
||||||
"version_info",
|
|
||||||
)
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,224 +0,0 @@
|
|||||||
import asyncio
|
|
||||||
import logging
|
|
||||||
import threading
|
|
||||||
from collections import deque
|
|
||||||
|
|
||||||
from collections.abc import AsyncIterator
|
|
||||||
from functools import partial
|
|
||||||
from typing import Callable, TypeVar
|
|
||||||
from uuid import UUID
|
|
||||||
from weakref import finalize
|
|
||||||
|
|
||||||
from .reader import JournalOpenMode, JournalReader, JournalEntry
|
|
||||||
|
|
||||||
A = TypeVar("A")
|
|
||||||
R = TypeVar("R")
|
|
||||||
log = logging.getLogger("cysystemd.async_reader")
|
|
||||||
|
|
||||||
|
|
||||||
class Base:
|
|
||||||
def __init__(self, loop=None, executor=None):
|
|
||||||
self._executor = executor
|
|
||||||
self._loop = loop or asyncio.get_event_loop()
|
|
||||||
|
|
||||||
async def _exec(self, func: Callable[[A], R], *args, **kwargs) -> R:
|
|
||||||
# noinspection PyTypeChecker
|
|
||||||
return await self._loop.run_in_executor(
|
|
||||||
self._executor, partial(func, *args, **kwargs)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncJournalReader(Base):
|
|
||||||
def __init__(self, executor=None, loop=None):
|
|
||||||
super().__init__(loop=loop, executor=executor)
|
|
||||||
self.__reader = JournalReader()
|
|
||||||
self.__flags = None
|
|
||||||
self.__wait_lock = asyncio.Lock()
|
|
||||||
self.__iterator = None
|
|
||||||
|
|
||||||
async def wait(self):
|
|
||||||
async with self.__wait_lock:
|
|
||||||
loop = self._loop
|
|
||||||
reader = self.__reader
|
|
||||||
event = asyncio.Event()
|
|
||||||
|
|
||||||
loop.add_reader(reader.fd, event.set)
|
|
||||||
|
|
||||||
try:
|
|
||||||
await event.wait()
|
|
||||||
finally:
|
|
||||||
loop.remove_reader(reader.fd)
|
|
||||||
|
|
||||||
reader.process_events()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def open(self, flags=JournalOpenMode.CURRENT_USER):
|
|
||||||
self.__flags = flags
|
|
||||||
return self._exec(self.__reader.open, flags=flags)
|
|
||||||
|
|
||||||
def open_directory(self, path):
|
|
||||||
return self._exec(self.__reader.open_directory, path)
|
|
||||||
|
|
||||||
def open_files(self, *file_names):
|
|
||||||
return self._exec(self.__reader.open_files, *file_names)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def data_threshold(self):
|
|
||||||
return self.__reader.data_threshold
|
|
||||||
|
|
||||||
@data_threshold.setter
|
|
||||||
def data_threshold(self, size):
|
|
||||||
self.__reader.data_threshold = size
|
|
||||||
|
|
||||||
@property
|
|
||||||
def closed(self):
|
|
||||||
return self.__reader.closed
|
|
||||||
|
|
||||||
@property
|
|
||||||
def locked(self):
|
|
||||||
return self.__reader.locked
|
|
||||||
|
|
||||||
@property
|
|
||||||
def idle(self):
|
|
||||||
return self.__reader.idle
|
|
||||||
|
|
||||||
def seek_head(self):
|
|
||||||
return self._exec(self.__reader.seek_head)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<%s[%s]: %s>" % (
|
|
||||||
self.__class__.__name__,
|
|
||||||
self.__flags,
|
|
||||||
"closed" if self.closed else "opened",
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def fd(self):
|
|
||||||
return self.__reader.fd
|
|
||||||
|
|
||||||
@property
|
|
||||||
def events(self):
|
|
||||||
return self.__reader.events
|
|
||||||
|
|
||||||
@property
|
|
||||||
def timeout(self):
|
|
||||||
return self.__reader.timeout
|
|
||||||
|
|
||||||
def get_catalog(self):
|
|
||||||
return self._exec(self.__reader.get_catalog)
|
|
||||||
|
|
||||||
def get_catalog_for_message_id(self, message_id):
|
|
||||||
return self._exec(
|
|
||||||
self.__reader.get_catalog_for_message_id, message_id
|
|
||||||
)
|
|
||||||
|
|
||||||
def seek_tail(self):
|
|
||||||
return self._exec(self.__reader.seek_tail)
|
|
||||||
|
|
||||||
def seek_monotonic_usec(self, boot_id: UUID, usec):
|
|
||||||
return self._exec(
|
|
||||||
self.__reader.seek_monotonic_usec, boot_id, usec
|
|
||||||
)
|
|
||||||
|
|
||||||
def seek_realtime_usec(self, usec):
|
|
||||||
return self._exec(self.__reader.seek_realtime_usec, usec)
|
|
||||||
|
|
||||||
def seek_cursor(self, cursor):
|
|
||||||
return self._exec(self.__reader.seek_cursor, cursor)
|
|
||||||
|
|
||||||
def skip_next(self, skip):
|
|
||||||
return self._exec(self.__reader.skip_next, skip)
|
|
||||||
|
|
||||||
def previous(self, skip=0):
|
|
||||||
return self._exec(self.__reader.previous, skip)
|
|
||||||
|
|
||||||
def skip_previous(self, skip):
|
|
||||||
return self._exec(self.__reader.skip_previous, skip)
|
|
||||||
|
|
||||||
def add_filter(self, rule):
|
|
||||||
return self._exec(self.__reader.add_filter, rule)
|
|
||||||
|
|
||||||
def clear_filter(self):
|
|
||||||
return self._exec(self.__reader.clear_filter)
|
|
||||||
|
|
||||||
def next(self, skip=0):
|
|
||||||
return self._exec(self.__reader.next, skip)
|
|
||||||
|
|
||||||
def __aiter__(self) -> "AsyncReaderIterator":
|
|
||||||
if self.__iterator is not None:
|
|
||||||
self.__iterator.close()
|
|
||||||
self.__iterator = None
|
|
||||||
|
|
||||||
iterator = AsyncReaderIterator(
|
|
||||||
loop=self._loop, executor=self._executor, reader=self.__reader
|
|
||||||
)
|
|
||||||
|
|
||||||
finalize(self, iterator.close)
|
|
||||||
|
|
||||||
self.__iterator = iterator
|
|
||||||
return iterator
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncReaderIterator(Base, AsyncIterator):
|
|
||||||
__slots__ = "reader", "queue", "queue_full", "event", "lock", "closed"
|
|
||||||
|
|
||||||
QUEUE_SIZE = 2
|
|
||||||
WRITE_EVENT_WAIT_TIME = 0.1
|
|
||||||
|
|
||||||
def __init__(self, *, reader, loop, executor):
|
|
||||||
super().__init__(loop=loop, executor=executor)
|
|
||||||
self.reader = reader
|
|
||||||
self.lock = asyncio.Lock()
|
|
||||||
self.queue = deque()
|
|
||||||
self.read_event = asyncio.Event()
|
|
||||||
self.write_event = threading.Semaphore(self.QUEUE_SIZE)
|
|
||||||
self.close_event = threading.Event()
|
|
||||||
|
|
||||||
self._loop.create_task(self._exec(self._journal_reader))
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
self.close_event.set()
|
|
||||||
self.__set_read_event()
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
def __set_read_event(self):
|
|
||||||
if self._loop.is_closed():
|
|
||||||
return
|
|
||||||
|
|
||||||
self._loop.call_soon_threadsafe(self.read_event.set)
|
|
||||||
|
|
||||||
def _journal_reader(self):
|
|
||||||
try:
|
|
||||||
for item in self.reader:
|
|
||||||
while not self.close_event.is_set():
|
|
||||||
if self.write_event.acquire(
|
|
||||||
timeout=self.WRITE_EVENT_WAIT_TIME
|
|
||||||
):
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
self.queue.append(item)
|
|
||||||
self.__set_read_event()
|
|
||||||
finally:
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
async def __anext__(self) -> JournalEntry:
|
|
||||||
async with self.lock:
|
|
||||||
if self.close_event.is_set() and len(self.queue) == 0:
|
|
||||||
raise StopAsyncIteration
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
item = self.queue.popleft()
|
|
||||||
except IndexError:
|
|
||||||
await self.read_event.wait()
|
|
||||||
self.read_event.clear()
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
self.write_event.release()
|
|
||||||
|
|
||||||
return item
|
|
@ -1,81 +0,0 @@
|
|||||||
import logging
|
|
||||||
from collections import namedtuple
|
|
||||||
from typing import Union
|
|
||||||
from enum import Enum, unique
|
|
||||||
|
|
||||||
from ._daemon import sd_notify
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger("cysystemd.daemon")
|
|
||||||
NotificationValue = namedtuple(
|
|
||||||
"NotificationValue", ("name", "constant", "type")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@unique
|
|
||||||
class Notification(Enum):
|
|
||||||
READY = NotificationValue(name="READY", constant=1, type=int)
|
|
||||||
RELOADING = NotificationValue(name="RELOADING", constant=1, type=int)
|
|
||||||
STOPPING = NotificationValue(name="STOPPING", constant=1, type=int)
|
|
||||||
STATUS = NotificationValue(name="STATUS", constant=None, type=str)
|
|
||||||
ERRNO = NotificationValue(name="ERRNO", constant=None, type=int)
|
|
||||||
BUSERROR = NotificationValue(name="BUSERROR", constant=None, type=str)
|
|
||||||
MAINPID = NotificationValue(name="MAINPID", constant=None, type=int)
|
|
||||||
WATCHDOG = NotificationValue(name="WATCHDOG", constant=1, type=int)
|
|
||||||
FDSTORE = NotificationValue(name="FDSTORE", constant=1, type=int)
|
|
||||||
FDNAME = NotificationValue(name="FDNAME", constant=None, type=int)
|
|
||||||
WATCHDOG_USEC = NotificationValue(
|
|
||||||
name="WATCHDOG_USEC", constant=None, type=int
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def notify(
|
|
||||||
notification: Notification,
|
|
||||||
value: Union[str, int] = None,
|
|
||||||
unset_environment: bool = False,
|
|
||||||
return_exceptions: bool = True,
|
|
||||||
):
|
|
||||||
|
|
||||||
""" Send notification to systemd daemon
|
|
||||||
|
|
||||||
:param return_exceptions: Return exception or raise it.
|
|
||||||
:param unset_environment: If the unset_environment parameter is non-zero,
|
|
||||||
notify() will unset the $NOTIFY_SOCKET environment variable
|
|
||||||
before returning (regardless of whether the function call itself
|
|
||||||
succeeded or not). Further calls to notify() will then fail,
|
|
||||||
but the variable is no longer inherited by child processes.
|
|
||||||
:param notification: Notification object
|
|
||||||
:param value: str or int value for non constant notifications
|
|
||||||
:returns None
|
|
||||||
"""
|
|
||||||
|
|
||||||
if not isinstance(notification, Notification):
|
|
||||||
raise TypeError("state must be an instance of Notification")
|
|
||||||
|
|
||||||
state = notification.value
|
|
||||||
|
|
||||||
if state.constant is not None and value:
|
|
||||||
raise ValueError(
|
|
||||||
"State %s should contain only constant value %r"
|
|
||||||
% (state.name, state.constant),
|
|
||||||
state.name,
|
|
||||||
state.constant,
|
|
||||||
)
|
|
||||||
|
|
||||||
line = "%s=%s" % (
|
|
||||||
state.name,
|
|
||||||
state.constant if state.constant is not None else state.type(value),
|
|
||||||
)
|
|
||||||
|
|
||||||
log.debug("Send %r into systemd", line)
|
|
||||||
|
|
||||||
try:
|
|
||||||
return sd_notify(line, unset_environment)
|
|
||||||
except Exception as e:
|
|
||||||
if return_exceptions:
|
|
||||||
log.error("%s", e)
|
|
||||||
return e
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ("notify", "Notification")
|
|
@ -1,193 +0,0 @@
|
|||||||
import logging
|
|
||||||
import re
|
|
||||||
import traceback
|
|
||||||
import uuid
|
|
||||||
from enum import IntEnum, unique
|
|
||||||
|
|
||||||
from ._journal import send, syslog_priorities
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from collections.abc import Mapping
|
|
||||||
except ImportError:
|
|
||||||
from collections import Mapping
|
|
||||||
|
|
||||||
|
|
||||||
_priorities = syslog_priorities()
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = "write", "send", "Priority", "JournaldLogHandler", "Facility"
|
|
||||||
|
|
||||||
|
|
||||||
@unique
|
|
||||||
class Priority(IntEnum):
|
|
||||||
PANIC = _priorities["panic"]
|
|
||||||
WARNING = _priorities["warn"]
|
|
||||||
ALERT = _priorities["alert"]
|
|
||||||
NONE = _priorities["none"]
|
|
||||||
CRITICAL = _priorities["crit"]
|
|
||||||
DEBUG = _priorities["debug"]
|
|
||||||
INFO = _priorities["info"]
|
|
||||||
ERROR = _priorities["error"]
|
|
||||||
NOTICE = _priorities["notice"]
|
|
||||||
|
|
||||||
|
|
||||||
@unique
|
|
||||||
class Facility(IntEnum):
|
|
||||||
KERN = 0
|
|
||||||
USER = 1
|
|
||||||
MAIL = 2
|
|
||||||
DAEMON = 3
|
|
||||||
AUTH = 4
|
|
||||||
SYSLOG = 5
|
|
||||||
LPR = 6
|
|
||||||
NEWS = 7
|
|
||||||
UUCP = 8
|
|
||||||
CLOCK_DAEMON = 9
|
|
||||||
AUTHPRIV = 10
|
|
||||||
FTP = 11
|
|
||||||
NTP = 12
|
|
||||||
AUDIT = 13
|
|
||||||
ALERT = 14
|
|
||||||
CRON = 15
|
|
||||||
LOCAL0 = 16
|
|
||||||
LOCAL1 = 17
|
|
||||||
LOCAL2 = 18
|
|
||||||
LOCAL3 = 19
|
|
||||||
LOCAL4 = 20
|
|
||||||
LOCAL5 = 21
|
|
||||||
LOCAL6 = 22
|
|
||||||
LOCAL7 = 23
|
|
||||||
|
|
||||||
|
|
||||||
def write(message, priority=Priority.INFO):
|
|
||||||
""" Write message into systemd journal
|
|
||||||
:type priority: Priority
|
|
||||||
:type message: str
|
|
||||||
"""
|
|
||||||
|
|
||||||
priority = int(Priority(int(priority)))
|
|
||||||
|
|
||||||
send(priority=priority, message=message)
|
|
||||||
|
|
||||||
|
|
||||||
class JournaldLogHandler(logging.Handler):
|
|
||||||
FIELD_BADCHAR_RE = re.compile(r'\W')
|
|
||||||
LEVELS = {
|
|
||||||
logging.CRITICAL: Priority.CRITICAL.value,
|
|
||||||
logging.FATAL: Priority.PANIC.value,
|
|
||||||
logging.ERROR: Priority.ERROR.value,
|
|
||||||
logging.WARNING: Priority.WARNING.value,
|
|
||||||
logging.WARN: Priority.WARNING.value,
|
|
||||||
logging.INFO: Priority.INFO.value,
|
|
||||||
logging.DEBUG: Priority.DEBUG.value,
|
|
||||||
logging.NOTSET: Priority.NONE.value,
|
|
||||||
}
|
|
||||||
|
|
||||||
__slots__ = ("__facility",)
|
|
||||||
|
|
||||||
def __init__(self, identifier=None, facility=Facility.DAEMON):
|
|
||||||
"""
|
|
||||||
|
|
||||||
:type identifier: Override default journald identifier
|
|
||||||
:type facility: Facility
|
|
||||||
"""
|
|
||||||
logging.Handler.__init__(self)
|
|
||||||
self.__identifier = identifier
|
|
||||||
self.__facility = int(facility)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _to_microsecond(ts):
|
|
||||||
"""
|
|
||||||
|
|
||||||
:type ts: float
|
|
||||||
"""
|
|
||||||
return int(ts * 1000 * 1000)
|
|
||||||
|
|
||||||
def emit(self, record):
|
|
||||||
message = str(record.getMessage())
|
|
||||||
|
|
||||||
tb_message = ""
|
|
||||||
if record.exc_info:
|
|
||||||
tb_message = "\n".join(
|
|
||||||
traceback.format_exception(*record.exc_info)
|
|
||||||
)
|
|
||||||
|
|
||||||
message += "\n"
|
|
||||||
message += tb_message
|
|
||||||
|
|
||||||
ts = self._to_microsecond(record.created)
|
|
||||||
|
|
||||||
hash_fields = (
|
|
||||||
message,
|
|
||||||
record.funcName,
|
|
||||||
record.levelno,
|
|
||||||
record.process,
|
|
||||||
record.processName,
|
|
||||||
record.levelname,
|
|
||||||
record.pathname,
|
|
||||||
record.name,
|
|
||||||
record.thread,
|
|
||||||
record.lineno,
|
|
||||||
ts,
|
|
||||||
tb_message,
|
|
||||||
)
|
|
||||||
|
|
||||||
message_id = uuid.uuid3(
|
|
||||||
uuid.NAMESPACE_OID, "$".join(str(x) for x in hash_fields)
|
|
||||||
).hex
|
|
||||||
|
|
||||||
data = {
|
|
||||||
key: value
|
|
||||||
for key, value in record.__dict__.items()
|
|
||||||
if not key.startswith("_") and value is not None
|
|
||||||
}
|
|
||||||
data["message"] = self.format(record)
|
|
||||||
data["priority"] = self.LEVELS[data.pop("levelno")]
|
|
||||||
data["syslog_facility"] = self.__facility
|
|
||||||
|
|
||||||
data["code_file"] = data.pop("filename")
|
|
||||||
data["code_line"] = data.pop("lineno")
|
|
||||||
data["code_func"] = data.pop("funcName")
|
|
||||||
if self.__identifier:
|
|
||||||
data["syslog_identifier"] = self.__identifier
|
|
||||||
else:
|
|
||||||
data["syslog_identifier"] = data["name"]
|
|
||||||
|
|
||||||
if "msg" in data:
|
|
||||||
data["message_raw"] = data.pop("msg")
|
|
||||||
|
|
||||||
data["message_id"] = message_id
|
|
||||||
data["code_module"] = data.pop("module")
|
|
||||||
data["logger_name"] = data.pop("name")
|
|
||||||
data["pid"] = data.pop("process")
|
|
||||||
data["proccess_name"] = data.pop("processName")
|
|
||||||
data["errno"] = 0 if not record.exc_info else 255
|
|
||||||
data["relative_ts"] = self._to_microsecond(data.pop("relativeCreated"))
|
|
||||||
data["thread_name"] = data.pop("threadName")
|
|
||||||
|
|
||||||
args = data.pop("args", [])
|
|
||||||
if isinstance(args, Mapping):
|
|
||||||
for key, value in args.items():
|
|
||||||
key = self.FIELD_BADCHAR_RE.sub('_', key)
|
|
||||||
data["argument_%s" % key] = value
|
|
||||||
else:
|
|
||||||
for idx, item in enumerate(args):
|
|
||||||
data["argument_%d" % idx] = str(item)
|
|
||||||
|
|
||||||
if tb_message:
|
|
||||||
data["traceback"] = tb_message
|
|
||||||
|
|
||||||
send(**data)
|
|
||||||
|
|
||||||
|
|
||||||
handler = JournaldLogHandler()
|
|
||||||
|
|
||||||
|
|
||||||
class JournaldLogger(logging.Logger):
|
|
||||||
def __init__(self, level, name="root"):
|
|
||||||
super(JournaldLogger, self).__init__(name, level)
|
|
||||||
self.addHandler(handler)
|
|
||||||
|
|
||||||
|
|
||||||
Logger = JournaldLogger(logging.WARNING)
|
|
Binary file not shown.
@ -1,760 +0,0 @@
|
|||||||
@Switch01
|
|
||||||
A_Rog
|
|
||||||
Aakanksha Agrawal
|
|
||||||
Abhinav Sagar
|
|
||||||
ABHYUDAY PRATAP SINGH
|
|
||||||
abs51295
|
|
||||||
AceGentile
|
|
||||||
Adam Chainz
|
|
||||||
Adam Tse
|
|
||||||
Adam Wentz
|
|
||||||
admin
|
|
||||||
Adrien Morison
|
|
||||||
ahayrapetyan
|
|
||||||
Ahilya
|
|
||||||
AinsworthK
|
|
||||||
Akash Srivastava
|
|
||||||
Alan Yee
|
|
||||||
Albert Tugushev
|
|
||||||
Albert-Guan
|
|
||||||
albertg
|
|
||||||
Alberto Sottile
|
|
||||||
Aleks Bunin
|
|
||||||
Ales Erjavec
|
|
||||||
Alethea Flowers
|
|
||||||
Alex Gaynor
|
|
||||||
Alex Grönholm
|
|
||||||
Alex Hedges
|
|
||||||
Alex Loosley
|
|
||||||
Alex Morega
|
|
||||||
Alex Stachowiak
|
|
||||||
Alexander Shtyrov
|
|
||||||
Alexandre Conrad
|
|
||||||
Alexey Popravka
|
|
||||||
Aleš Erjavec
|
|
||||||
Alli
|
|
||||||
Ami Fischman
|
|
||||||
Ananya Maiti
|
|
||||||
Anatoly Techtonik
|
|
||||||
Anders Kaseorg
|
|
||||||
Andre Aguiar
|
|
||||||
Andreas Lutro
|
|
||||||
Andrei Geacar
|
|
||||||
Andrew Gaul
|
|
||||||
Andrew Shymanel
|
|
||||||
Andrey Bienkowski
|
|
||||||
Andrey Bulgakov
|
|
||||||
Andrés Delfino
|
|
||||||
Andy Freeland
|
|
||||||
Andy Kluger
|
|
||||||
Ani Hayrapetyan
|
|
||||||
Aniruddha Basak
|
|
||||||
Anish Tambe
|
|
||||||
Anrs Hu
|
|
||||||
Anthony Sottile
|
|
||||||
Antoine Musso
|
|
||||||
Anton Ovchinnikov
|
|
||||||
Anton Patrushev
|
|
||||||
Antonio Alvarado Hernandez
|
|
||||||
Antony Lee
|
|
||||||
Antti Kaihola
|
|
||||||
Anubhav Patel
|
|
||||||
Anudit Nagar
|
|
||||||
Anuj Godase
|
|
||||||
AQNOUCH Mohammed
|
|
||||||
AraHaan
|
|
||||||
Arindam Choudhury
|
|
||||||
Armin Ronacher
|
|
||||||
Artem
|
|
||||||
Arun Babu Neelicattu
|
|
||||||
Ashley Manton
|
|
||||||
Ashwin Ramaswami
|
|
||||||
atse
|
|
||||||
Atsushi Odagiri
|
|
||||||
Avinash Karhana
|
|
||||||
Avner Cohen
|
|
||||||
Awit (Ah-Wit) Ghirmai
|
|
||||||
Baptiste Mispelon
|
|
||||||
Barney Gale
|
|
||||||
barneygale
|
|
||||||
Bartek Ogryczak
|
|
||||||
Bastian Venthur
|
|
||||||
Ben Bodenmiller
|
|
||||||
Ben Darnell
|
|
||||||
Ben Hoyt
|
|
||||||
Ben Mares
|
|
||||||
Ben Rosser
|
|
||||||
Bence Nagy
|
|
||||||
Benjamin Peterson
|
|
||||||
Benjamin VanEvery
|
|
||||||
Benoit Pierre
|
|
||||||
Berker Peksag
|
|
||||||
Bernard
|
|
||||||
Bernard Tyers
|
|
||||||
Bernardo B. Marques
|
|
||||||
Bernhard M. Wiedemann
|
|
||||||
Bertil Hatt
|
|
||||||
Bhavam Vidyarthi
|
|
||||||
Blazej Michalik
|
|
||||||
Bogdan Opanchuk
|
|
||||||
BorisZZZ
|
|
||||||
Brad Erickson
|
|
||||||
Bradley Ayers
|
|
||||||
Brandon L. Reiss
|
|
||||||
Brandt Bucher
|
|
||||||
Brett Randall
|
|
||||||
Brett Rosen
|
|
||||||
Brian Cristante
|
|
||||||
Brian Rosner
|
|
||||||
briantracy
|
|
||||||
BrownTruck
|
|
||||||
Bruno Oliveira
|
|
||||||
Bruno Renié
|
|
||||||
Bruno S
|
|
||||||
Bstrdsmkr
|
|
||||||
Buck Golemon
|
|
||||||
burrows
|
|
||||||
Bussonnier Matthias
|
|
||||||
bwoodsend
|
|
||||||
c22
|
|
||||||
Caleb Martinez
|
|
||||||
Calvin Smith
|
|
||||||
Carl Meyer
|
|
||||||
Carlos Liam
|
|
||||||
Carol Willing
|
|
||||||
Carter Thayer
|
|
||||||
Cass
|
|
||||||
Chandrasekhar Atina
|
|
||||||
Chih-Hsuan Yen
|
|
||||||
Chris Brinker
|
|
||||||
Chris Hunt
|
|
||||||
Chris Jerdonek
|
|
||||||
Chris Kuehl
|
|
||||||
Chris McDonough
|
|
||||||
Chris Pawley
|
|
||||||
Chris Pryer
|
|
||||||
Chris Wolfe
|
|
||||||
Christian Clauss
|
|
||||||
Christian Heimes
|
|
||||||
Christian Oudard
|
|
||||||
Christoph Reiter
|
|
||||||
Christopher Hunt
|
|
||||||
Christopher Snyder
|
|
||||||
cjc7373
|
|
||||||
Clark Boylan
|
|
||||||
Claudio Jolowicz
|
|
||||||
Clay McClure
|
|
||||||
Cody
|
|
||||||
Cody Soyland
|
|
||||||
Colin Watson
|
|
||||||
Collin Anderson
|
|
||||||
Connor Osborn
|
|
||||||
Cooper Lees
|
|
||||||
Cooper Ry Lees
|
|
||||||
Cory Benfield
|
|
||||||
Cory Wright
|
|
||||||
Craig Kerstiens
|
|
||||||
Cristian Sorinel
|
|
||||||
Cristina
|
|
||||||
Cristina Muñoz
|
|
||||||
Curtis Doty
|
|
||||||
cytolentino
|
|
||||||
Daan De Meyer
|
|
||||||
Dale
|
|
||||||
Damian
|
|
||||||
Damian Quiroga
|
|
||||||
Damian Shaw
|
|
||||||
Dan Black
|
|
||||||
Dan Savilonis
|
|
||||||
Dan Sully
|
|
||||||
Dane Hillard
|
|
||||||
daniel
|
|
||||||
Daniel Collins
|
|
||||||
Daniel Hahler
|
|
||||||
Daniel Holth
|
|
||||||
Daniel Jost
|
|
||||||
Daniel Katz
|
|
||||||
Daniel Shaulov
|
|
||||||
Daniele Esposti
|
|
||||||
Daniele Nicolodi
|
|
||||||
Daniele Procida
|
|
||||||
Daniil Konovalenko
|
|
||||||
Danny Hermes
|
|
||||||
Danny McClanahan
|
|
||||||
Darren Kavanagh
|
|
||||||
Dav Clark
|
|
||||||
Dave Abrahams
|
|
||||||
Dave Jones
|
|
||||||
David Aguilar
|
|
||||||
David Black
|
|
||||||
David Bordeynik
|
|
||||||
David Caro
|
|
||||||
David D Lowe
|
|
||||||
David Evans
|
|
||||||
David Hewitt
|
|
||||||
David Linke
|
|
||||||
David Poggi
|
|
||||||
David Pursehouse
|
|
||||||
David Runge
|
|
||||||
David Tucker
|
|
||||||
David Wales
|
|
||||||
Davidovich
|
|
||||||
ddelange
|
|
||||||
Deepak Sharma
|
|
||||||
Deepyaman Datta
|
|
||||||
Denise Yu
|
|
||||||
dependabot[bot]
|
|
||||||
derwolfe
|
|
||||||
Desetude
|
|
||||||
Devesh Kumar Singh
|
|
||||||
Diego Caraballo
|
|
||||||
Diego Ramirez
|
|
||||||
DiegoCaraballo
|
|
||||||
Dimitri Merejkowsky
|
|
||||||
Dimitri Papadopoulos
|
|
||||||
Dirk Stolle
|
|
||||||
Dmitry Gladkov
|
|
||||||
Dmitry Volodin
|
|
||||||
Domen Kožar
|
|
||||||
Dominic Davis-Foster
|
|
||||||
Donald Stufft
|
|
||||||
Dongweiming
|
|
||||||
doron zarhi
|
|
||||||
Dos Moonen
|
|
||||||
Douglas Thor
|
|
||||||
DrFeathers
|
|
||||||
Dustin Ingram
|
|
||||||
Dwayne Bailey
|
|
||||||
Ed Morley
|
|
||||||
Edgar Ramírez
|
|
||||||
Edgar Ramírez Mondragón
|
|
||||||
Ee Durbin
|
|
||||||
Efflam Lemaillet
|
|
||||||
efflamlemaillet
|
|
||||||
Eitan Adler
|
|
||||||
ekristina
|
|
||||||
elainechan
|
|
||||||
Eli Schwartz
|
|
||||||
Elisha Hollander
|
|
||||||
Ellen Marie Dash
|
|
||||||
Emil Burzo
|
|
||||||
Emil Styrke
|
|
||||||
Emmanuel Arias
|
|
||||||
Endoh Takanao
|
|
||||||
enoch
|
|
||||||
Erdinc Mutlu
|
|
||||||
Eric Cousineau
|
|
||||||
Eric Gillingham
|
|
||||||
Eric Hanchrow
|
|
||||||
Eric Hopper
|
|
||||||
Erik M. Bray
|
|
||||||
Erik Rose
|
|
||||||
Erwin Janssen
|
|
||||||
Eugene Vereshchagin
|
|
||||||
everdimension
|
|
||||||
Federico
|
|
||||||
Felipe Peter
|
|
||||||
Felix Yan
|
|
||||||
fiber-space
|
|
||||||
Filip Kokosiński
|
|
||||||
Filipe Laíns
|
|
||||||
Finn Womack
|
|
||||||
finnagin
|
|
||||||
Flavio Amurrio
|
|
||||||
Florian Briand
|
|
||||||
Florian Rathgeber
|
|
||||||
Francesco
|
|
||||||
Francesco Montesano
|
|
||||||
Frost Ming
|
|
||||||
Gabriel Curio
|
|
||||||
Gabriel de Perthuis
|
|
||||||
Garry Polley
|
|
||||||
gavin
|
|
||||||
gdanielson
|
|
||||||
Geoffrey Sneddon
|
|
||||||
George Song
|
|
||||||
Georgi Valkov
|
|
||||||
Georgy Pchelkin
|
|
||||||
ghost
|
|
||||||
Giftlin Rajaiah
|
|
||||||
gizmoguy1
|
|
||||||
gkdoc
|
|
||||||
Godefroid Chapelle
|
|
||||||
Gopinath M
|
|
||||||
GOTO Hayato
|
|
||||||
gousaiyang
|
|
||||||
gpiks
|
|
||||||
Greg Roodt
|
|
||||||
Greg Ward
|
|
||||||
Guilherme Espada
|
|
||||||
Guillaume Seguin
|
|
||||||
gutsytechster
|
|
||||||
Guy Rozendorn
|
|
||||||
Guy Tuval
|
|
||||||
gzpan123
|
|
||||||
Hanjun Kim
|
|
||||||
Hari Charan
|
|
||||||
Harsh Vardhan
|
|
||||||
harupy
|
|
||||||
Harutaka Kawamura
|
|
||||||
hauntsaninja
|
|
||||||
Henrich Hartzer
|
|
||||||
Henry Schreiner
|
|
||||||
Herbert Pfennig
|
|
||||||
Holly Stotelmyer
|
|
||||||
Honnix
|
|
||||||
Hsiaoming Yang
|
|
||||||
Hugo Lopes Tavares
|
|
||||||
Hugo van Kemenade
|
|
||||||
Hugues Bruant
|
|
||||||
Hynek Schlawack
|
|
||||||
Ian Bicking
|
|
||||||
Ian Cordasco
|
|
||||||
Ian Lee
|
|
||||||
Ian Stapleton Cordasco
|
|
||||||
Ian Wienand
|
|
||||||
Igor Kuzmitshov
|
|
||||||
Igor Sobreira
|
|
||||||
Ilan Schnell
|
|
||||||
Illia Volochii
|
|
||||||
Ilya Baryshev
|
|
||||||
Inada Naoki
|
|
||||||
Ionel Cristian Mărieș
|
|
||||||
Ionel Maries Cristian
|
|
||||||
Itamar Turner-Trauring
|
|
||||||
Ivan Pozdeev
|
|
||||||
J. Nick Koston
|
|
||||||
Jacob Kim
|
|
||||||
Jacob Walls
|
|
||||||
Jaime Sanz
|
|
||||||
jakirkham
|
|
||||||
Jakub Kuczys
|
|
||||||
Jakub Stasiak
|
|
||||||
Jakub Vysoky
|
|
||||||
Jakub Wilk
|
|
||||||
James Cleveland
|
|
||||||
James Curtin
|
|
||||||
James Firth
|
|
||||||
James Gerity
|
|
||||||
James Polley
|
|
||||||
Jan Pokorný
|
|
||||||
Jannis Leidel
|
|
||||||
Jarek Potiuk
|
|
||||||
jarondl
|
|
||||||
Jason Curtis
|
|
||||||
Jason R. Coombs
|
|
||||||
JasonMo
|
|
||||||
JasonMo1
|
|
||||||
Jay Graves
|
|
||||||
Jean Abou Samra
|
|
||||||
Jean-Christophe Fillion-Robin
|
|
||||||
Jeff Barber
|
|
||||||
Jeff Dairiki
|
|
||||||
Jeff Widman
|
|
||||||
Jelmer Vernooij
|
|
||||||
jenix21
|
|
||||||
Jeremy Stanley
|
|
||||||
Jeremy Zafran
|
|
||||||
Jesse Rittner
|
|
||||||
Jiashuo Li
|
|
||||||
Jim Fisher
|
|
||||||
Jim Garrison
|
|
||||||
Jiun Bae
|
|
||||||
Jivan Amara
|
|
||||||
Joe Bylund
|
|
||||||
Joe Michelini
|
|
||||||
John Paton
|
|
||||||
John T. Wodder II
|
|
||||||
John-Scott Atlakson
|
|
||||||
johnthagen
|
|
||||||
Jon Banafato
|
|
||||||
Jon Dufresne
|
|
||||||
Jon Parise
|
|
||||||
Jonas Nockert
|
|
||||||
Jonathan Herbert
|
|
||||||
Joonatan Partanen
|
|
||||||
Joost Molenaar
|
|
||||||
Jorge Niedbalski
|
|
||||||
Joseph Bylund
|
|
||||||
Joseph Long
|
|
||||||
Josh Bronson
|
|
||||||
Josh Hansen
|
|
||||||
Josh Schneier
|
|
||||||
Joshua
|
|
||||||
Juan Luis Cano Rodríguez
|
|
||||||
Juanjo Bazán
|
|
||||||
Judah Rand
|
|
||||||
Julian Berman
|
|
||||||
Julian Gethmann
|
|
||||||
Julien Demoor
|
|
||||||
Jussi Kukkonen
|
|
||||||
jwg4
|
|
||||||
Jyrki Pulliainen
|
|
||||||
Kai Chen
|
|
||||||
Kai Mueller
|
|
||||||
Kamal Bin Mustafa
|
|
||||||
kasium
|
|
||||||
kaustav haldar
|
|
||||||
keanemind
|
|
||||||
Keith Maxwell
|
|
||||||
Kelsey Hightower
|
|
||||||
Kenneth Belitzky
|
|
||||||
Kenneth Reitz
|
|
||||||
Kevin Burke
|
|
||||||
Kevin Carter
|
|
||||||
Kevin Frommelt
|
|
||||||
Kevin R Patterson
|
|
||||||
Kexuan Sun
|
|
||||||
Kit Randel
|
|
||||||
Klaas van Schelven
|
|
||||||
KOLANICH
|
|
||||||
kpinc
|
|
||||||
Krishna Oza
|
|
||||||
Kumar McMillan
|
|
||||||
Kurt McKee
|
|
||||||
Kyle Persohn
|
|
||||||
lakshmanaram
|
|
||||||
Laszlo Kiss-Kollar
|
|
||||||
Laurent Bristiel
|
|
||||||
Laurent LAPORTE
|
|
||||||
Laurie O
|
|
||||||
Laurie Opperman
|
|
||||||
layday
|
|
||||||
Leon Sasson
|
|
||||||
Lev Givon
|
|
||||||
Lincoln de Sousa
|
|
||||||
Lipis
|
|
||||||
lorddavidiii
|
|
||||||
Loren Carvalho
|
|
||||||
Lucas Cimon
|
|
||||||
Ludovic Gasc
|
|
||||||
Lukas Geiger
|
|
||||||
Lukas Juhrich
|
|
||||||
Luke Macken
|
|
||||||
Luo Jiebin
|
|
||||||
luojiebin
|
|
||||||
luz.paz
|
|
||||||
László Kiss Kollár
|
|
||||||
M00nL1ght
|
|
||||||
Marc Abramowitz
|
|
||||||
Marc Tamlyn
|
|
||||||
Marcus Smith
|
|
||||||
Mariatta
|
|
||||||
Mark Kohler
|
|
||||||
Mark Williams
|
|
||||||
Markus Hametner
|
|
||||||
Martey Dodoo
|
|
||||||
Martin Fischer
|
|
||||||
Martin Häcker
|
|
||||||
Martin Pavlasek
|
|
||||||
Masaki
|
|
||||||
Masklinn
|
|
||||||
Matej Stuchlik
|
|
||||||
Mathew Jennings
|
|
||||||
Mathieu Bridon
|
|
||||||
Mathieu Kniewallner
|
|
||||||
Matt Bacchi
|
|
||||||
Matt Good
|
|
||||||
Matt Maker
|
|
||||||
Matt Robenolt
|
|
||||||
matthew
|
|
||||||
Matthew Einhorn
|
|
||||||
Matthew Feickert
|
|
||||||
Matthew Gilliard
|
|
||||||
Matthew Iversen
|
|
||||||
Matthew Treinish
|
|
||||||
Matthew Trumbell
|
|
||||||
Matthew Willson
|
|
||||||
Matthias Bussonnier
|
|
||||||
mattip
|
|
||||||
Maurits van Rees
|
|
||||||
Max W Chase
|
|
||||||
Maxim Kurnikov
|
|
||||||
Maxime Rouyrre
|
|
||||||
mayeut
|
|
||||||
mbaluna
|
|
||||||
mdebi
|
|
||||||
memoselyk
|
|
||||||
meowmeowcat
|
|
||||||
Michael
|
|
||||||
Michael Aquilina
|
|
||||||
Michael E. Karpeles
|
|
||||||
Michael Klich
|
|
||||||
Michael Mintz
|
|
||||||
Michael Williamson
|
|
||||||
michaelpacer
|
|
||||||
Michał Górny
|
|
||||||
Mickaël Schoentgen
|
|
||||||
Miguel Araujo Perez
|
|
||||||
Mihir Singh
|
|
||||||
Mike
|
|
||||||
Mike Hendricks
|
|
||||||
Min RK
|
|
||||||
MinRK
|
|
||||||
Miro Hrončok
|
|
||||||
Monica Baluna
|
|
||||||
montefra
|
|
||||||
Monty Taylor
|
|
||||||
Muha Ajjan
|
|
||||||
Nadav Wexler
|
|
||||||
Nahuel Ambrosini
|
|
||||||
Nate Coraor
|
|
||||||
Nate Prewitt
|
|
||||||
Nathan Houghton
|
|
||||||
Nathaniel J. Smith
|
|
||||||
Nehal J Wani
|
|
||||||
Neil Botelho
|
|
||||||
Nguyễn Gia Phong
|
|
||||||
Nicholas Serra
|
|
||||||
Nick Coghlan
|
|
||||||
Nick Stenning
|
|
||||||
Nick Timkovich
|
|
||||||
Nicolas Bock
|
|
||||||
Nicole Harris
|
|
||||||
Nikhil Benesch
|
|
||||||
Nikhil Ladha
|
|
||||||
Nikita Chepanov
|
|
||||||
Nikolay Korolev
|
|
||||||
Nipunn Koorapati
|
|
||||||
Nitesh Sharma
|
|
||||||
Niyas Sait
|
|
||||||
Noah
|
|
||||||
Noah Gorny
|
|
||||||
Nowell Strite
|
|
||||||
NtaleGrey
|
|
||||||
nvdv
|
|
||||||
OBITORASU
|
|
||||||
Ofek Lev
|
|
||||||
ofrinevo
|
|
||||||
Oliver Freund
|
|
||||||
Oliver Jeeves
|
|
||||||
Oliver Mannion
|
|
||||||
Oliver Tonnhofer
|
|
||||||
Olivier Girardot
|
|
||||||
Olivier Grisel
|
|
||||||
Ollie Rutherfurd
|
|
||||||
OMOTO Kenji
|
|
||||||
Omry Yadan
|
|
||||||
onlinejudge95
|
|
||||||
Oren Held
|
|
||||||
Oscar Benjamin
|
|
||||||
Oz N Tiram
|
|
||||||
Pachwenko
|
|
||||||
Patrick Dubroy
|
|
||||||
Patrick Jenkins
|
|
||||||
Patrick Lawson
|
|
||||||
patricktokeeffe
|
|
||||||
Patrik Kopkan
|
|
||||||
Paul Ganssle
|
|
||||||
Paul Kehrer
|
|
||||||
Paul Moore
|
|
||||||
Paul Nasrat
|
|
||||||
Paul Oswald
|
|
||||||
Paul van der Linden
|
|
||||||
Paulus Schoutsen
|
|
||||||
Pavel Safronov
|
|
||||||
Pavithra Eswaramoorthy
|
|
||||||
Pawel Jasinski
|
|
||||||
Paweł Szramowski
|
|
||||||
Pekka Klärck
|
|
||||||
Peter Gessler
|
|
||||||
Peter Lisák
|
|
||||||
Peter Waller
|
|
||||||
petr-tik
|
|
||||||
Phaneendra Chiruvella
|
|
||||||
Phil Elson
|
|
||||||
Phil Freo
|
|
||||||
Phil Pennock
|
|
||||||
Phil Whelan
|
|
||||||
Philip Jägenstedt
|
|
||||||
Philip Molloy
|
|
||||||
Philippe Ombredanne
|
|
||||||
Pi Delport
|
|
||||||
Pierre-Yves Rofes
|
|
||||||
Pieter Degroote
|
|
||||||
pip
|
|
||||||
Prabakaran Kumaresshan
|
|
||||||
Prabhjyotsing Surjit Singh Sodhi
|
|
||||||
Prabhu Marappan
|
|
||||||
Pradyun Gedam
|
|
||||||
Prashant Sharma
|
|
||||||
Pratik Mallya
|
|
||||||
pre-commit-ci[bot]
|
|
||||||
Preet Thakkar
|
|
||||||
Preston Holmes
|
|
||||||
Przemek Wrzos
|
|
||||||
Pulkit Goyal
|
|
||||||
q0w
|
|
||||||
Qiangning Hong
|
|
||||||
Qiming Xu
|
|
||||||
Quentin Lee
|
|
||||||
Quentin Pradet
|
|
||||||
R. David Murray
|
|
||||||
Rafael Caricio
|
|
||||||
Ralf Schmitt
|
|
||||||
Razzi Abuissa
|
|
||||||
rdb
|
|
||||||
Reece Dunham
|
|
||||||
Remi Rampin
|
|
||||||
Rene Dudfield
|
|
||||||
Riccardo Magliocchetti
|
|
||||||
Riccardo Schirone
|
|
||||||
Richard Jones
|
|
||||||
Richard Si
|
|
||||||
Ricky Ng-Adam
|
|
||||||
Rishi
|
|
||||||
RobberPhex
|
|
||||||
Robert Collins
|
|
||||||
Robert McGibbon
|
|
||||||
Robert Pollak
|
|
||||||
Robert T. McGibbon
|
|
||||||
robin elisha robinson
|
|
||||||
Roey Berman
|
|
||||||
Rohan Jain
|
|
||||||
Roman Bogorodskiy
|
|
||||||
Roman Donchenko
|
|
||||||
Romuald Brunet
|
|
||||||
ronaudinho
|
|
||||||
Ronny Pfannschmidt
|
|
||||||
Rory McCann
|
|
||||||
Ross Brattain
|
|
||||||
Roy Wellington Ⅳ
|
|
||||||
Ruairidh MacLeod
|
|
||||||
Russell Keith-Magee
|
|
||||||
Ryan Shepherd
|
|
||||||
Ryan Wooden
|
|
||||||
ryneeverett
|
|
||||||
Sachi King
|
|
||||||
Salvatore Rinchiera
|
|
||||||
sandeepkiran-js
|
|
||||||
Sander Van Balen
|
|
||||||
Savio Jomton
|
|
||||||
schlamar
|
|
||||||
Scott Kitterman
|
|
||||||
Sean
|
|
||||||
seanj
|
|
||||||
Sebastian Jordan
|
|
||||||
Sebastian Schaetz
|
|
||||||
Segev Finer
|
|
||||||
SeongSoo Cho
|
|
||||||
Sergey Vasilyev
|
|
||||||
Seth Michael Larson
|
|
||||||
Seth Woodworth
|
|
||||||
Shahar Epstein
|
|
||||||
Shantanu
|
|
||||||
shireenrao
|
|
||||||
Shivansh-007
|
|
||||||
Shlomi Fish
|
|
||||||
Shovan Maity
|
|
||||||
Simeon Visser
|
|
||||||
Simon Cross
|
|
||||||
Simon Pichugin
|
|
||||||
sinoroc
|
|
||||||
sinscary
|
|
||||||
snook92
|
|
||||||
socketubs
|
|
||||||
Sorin Sbarnea
|
|
||||||
Srinivas Nyayapati
|
|
||||||
Stavros Korokithakis
|
|
||||||
Stefan Scherfke
|
|
||||||
Stefano Rivera
|
|
||||||
Stephan Erb
|
|
||||||
Stephen Rosen
|
|
||||||
stepshal
|
|
||||||
Steve (Gadget) Barnes
|
|
||||||
Steve Barnes
|
|
||||||
Steve Dower
|
|
||||||
Steve Kowalik
|
|
||||||
Steven Myint
|
|
||||||
Steven Silvester
|
|
||||||
stonebig
|
|
||||||
studioj
|
|
||||||
Stéphane Bidoul
|
|
||||||
Stéphane Bidoul (ACSONE)
|
|
||||||
Stéphane Klein
|
|
||||||
Sumana Harihareswara
|
|
||||||
Surbhi Sharma
|
|
||||||
Sviatoslav Sydorenko
|
|
||||||
Swat009
|
|
||||||
Sylvain
|
|
||||||
Takayuki SHIMIZUKAWA
|
|
||||||
Taneli Hukkinen
|
|
||||||
tbeswick
|
|
||||||
Thiago
|
|
||||||
Thijs Triemstra
|
|
||||||
Thomas Fenzl
|
|
||||||
Thomas Grainger
|
|
||||||
Thomas Guettler
|
|
||||||
Thomas Johansson
|
|
||||||
Thomas Kluyver
|
|
||||||
Thomas Smith
|
|
||||||
Thomas VINCENT
|
|
||||||
Tim D. Smith
|
|
||||||
Tim Gates
|
|
||||||
Tim Harder
|
|
||||||
Tim Heap
|
|
||||||
tim smith
|
|
||||||
tinruufu
|
|
||||||
Tobias Hermann
|
|
||||||
Tom Forbes
|
|
||||||
Tom Freudenheim
|
|
||||||
Tom V
|
|
||||||
Tomas Hrnciar
|
|
||||||
Tomas Orsava
|
|
||||||
Tomer Chachamu
|
|
||||||
Tommi Enenkel | AnB
|
|
||||||
Tomáš Hrnčiar
|
|
||||||
Tony Beswick
|
|
||||||
Tony Narlock
|
|
||||||
Tony Zhaocheng Tan
|
|
||||||
TonyBeswick
|
|
||||||
toonarmycaptain
|
|
||||||
Toshio Kuratomi
|
|
||||||
toxinu
|
|
||||||
Travis Swicegood
|
|
||||||
Tushar Sadhwani
|
|
||||||
Tzu-ping Chung
|
|
||||||
Valentin Haenel
|
|
||||||
Victor Stinner
|
|
||||||
victorvpaulo
|
|
||||||
Vikram - Google
|
|
||||||
Viktor Szépe
|
|
||||||
Ville Skyttä
|
|
||||||
Vinay Sajip
|
|
||||||
Vincent Philippon
|
|
||||||
Vinicyus Macedo
|
|
||||||
Vipul Kumar
|
|
||||||
Vitaly Babiy
|
|
||||||
Vladimir Fokow
|
|
||||||
Vladimir Rutsky
|
|
||||||
W. Trevor King
|
|
||||||
Wil Tan
|
|
||||||
Wilfred Hughes
|
|
||||||
William Edwards
|
|
||||||
William ML Leslie
|
|
||||||
William T Olson
|
|
||||||
William Woodruff
|
|
||||||
Wilson Mo
|
|
||||||
wim glenn
|
|
||||||
Winson Luk
|
|
||||||
Wolfgang Maier
|
|
||||||
Wu Zhenyu
|
|
||||||
XAMES3
|
|
||||||
Xavier Fernandez
|
|
||||||
xoviat
|
|
||||||
xtreak
|
|
||||||
YAMAMOTO Takashi
|
|
||||||
Yen Chi Hsuan
|
|
||||||
Yeray Diaz Diaz
|
|
||||||
Yoval P
|
|
||||||
Yu Jian
|
|
||||||
Yuan Jing Vincent Yan
|
|
||||||
Yusuke Hayashi
|
|
||||||
Zearin
|
|
||||||
Zhiping Deng
|
|
||||||
ziebam
|
|
||||||
Zvezdan Petkovic
|
|
||||||
Łukasz Langa
|
|
||||||
Роман Донченко
|
|
||||||
Семён Марьясин
|
|
||||||
rekcäH nitraM
|
|
@ -1 +0,0 @@
|
|||||||
pip
|
|
@ -1,20 +0,0 @@
|
|||||||
Copyright (c) 2008-present The pip developers (see AUTHORS.txt file)
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
a copy of this software and associated documentation files (the
|
|
||||||
"Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be
|
|
||||||
included in all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,88 +0,0 @@
|
|||||||
Metadata-Version: 2.1
|
|
||||||
Name: pip
|
|
||||||
Version: 24.0
|
|
||||||
Summary: The PyPA recommended tool for installing Python packages.
|
|
||||||
Author-email: The pip developers <distutils-sig@python.org>
|
|
||||||
License: MIT
|
|
||||||
Project-URL: Homepage, https://pip.pypa.io/
|
|
||||||
Project-URL: Documentation, https://pip.pypa.io
|
|
||||||
Project-URL: Source, https://github.com/pypa/pip
|
|
||||||
Project-URL: Changelog, https://pip.pypa.io/en/stable/news/
|
|
||||||
Classifier: Development Status :: 5 - Production/Stable
|
|
||||||
Classifier: Intended Audience :: Developers
|
|
||||||
Classifier: License :: OSI Approved :: MIT License
|
|
||||||
Classifier: Topic :: Software Development :: Build Tools
|
|
||||||
Classifier: Programming Language :: Python
|
|
||||||
Classifier: Programming Language :: Python :: 3
|
|
||||||
Classifier: Programming Language :: Python :: 3 :: Only
|
|
||||||
Classifier: Programming Language :: Python :: 3.7
|
|
||||||
Classifier: Programming Language :: Python :: 3.8
|
|
||||||
Classifier: Programming Language :: Python :: 3.9
|
|
||||||
Classifier: Programming Language :: Python :: 3.10
|
|
||||||
Classifier: Programming Language :: Python :: 3.11
|
|
||||||
Classifier: Programming Language :: Python :: 3.12
|
|
||||||
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
||||||
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
||||||
Requires-Python: >=3.7
|
|
||||||
Description-Content-Type: text/x-rst
|
|
||||||
License-File: LICENSE.txt
|
|
||||||
License-File: AUTHORS.txt
|
|
||||||
|
|
||||||
pip - The Python Package Installer
|
|
||||||
==================================
|
|
||||||
|
|
||||||
.. image:: https://img.shields.io/pypi/v/pip.svg
|
|
||||||
:target: https://pypi.org/project/pip/
|
|
||||||
:alt: PyPI
|
|
||||||
|
|
||||||
.. image:: https://img.shields.io/pypi/pyversions/pip
|
|
||||||
:target: https://pypi.org/project/pip
|
|
||||||
:alt: PyPI - Python Version
|
|
||||||
|
|
||||||
.. image:: https://readthedocs.org/projects/pip/badge/?version=latest
|
|
||||||
:target: https://pip.pypa.io/en/latest
|
|
||||||
:alt: Documentation
|
|
||||||
|
|
||||||
pip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.
|
|
||||||
|
|
||||||
Please take a look at our documentation for how to install and use pip:
|
|
||||||
|
|
||||||
* `Installation`_
|
|
||||||
* `Usage`_
|
|
||||||
|
|
||||||
We release updates regularly, with a new version every 3 months. Find more details in our documentation:
|
|
||||||
|
|
||||||
* `Release notes`_
|
|
||||||
* `Release process`_
|
|
||||||
|
|
||||||
If you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:
|
|
||||||
|
|
||||||
* `Issue tracking`_
|
|
||||||
* `Discourse channel`_
|
|
||||||
* `User IRC`_
|
|
||||||
|
|
||||||
If you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:
|
|
||||||
|
|
||||||
* `GitHub page`_
|
|
||||||
* `Development documentation`_
|
|
||||||
* `Development IRC`_
|
|
||||||
|
|
||||||
Code of Conduct
|
|
||||||
---------------
|
|
||||||
|
|
||||||
Everyone interacting in the pip project's codebases, issue trackers, chat
|
|
||||||
rooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.
|
|
||||||
|
|
||||||
.. _package installer: https://packaging.python.org/guides/tool-recommendations/
|
|
||||||
.. _Python Package Index: https://pypi.org
|
|
||||||
.. _Installation: https://pip.pypa.io/en/stable/installation/
|
|
||||||
.. _Usage: https://pip.pypa.io/en/stable/
|
|
||||||
.. _Release notes: https://pip.pypa.io/en/stable/news.html
|
|
||||||
.. _Release process: https://pip.pypa.io/en/latest/development/release-process/
|
|
||||||
.. _GitHub page: https://github.com/pypa/pip
|
|
||||||
.. _Development documentation: https://pip.pypa.io/en/latest/development
|
|
||||||
.. _Issue tracking: https://github.com/pypa/pip/issues
|
|
||||||
.. _Discourse channel: https://discuss.python.org/c/packaging
|
|
||||||
.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa
|
|
||||||
.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev
|
|
||||||
.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md
|
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +0,0 @@
|
|||||||
Wheel-Version: 1.0
|
|
||||||
Generator: bdist_wheel (0.42.0)
|
|
||||||
Root-Is-Purelib: true
|
|
||||||
Tag: py3-none-any
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
|||||||
[console_scripts]
|
|
||||||
pip = pip._internal.cli.main:main
|
|
||||||
pip3 = pip._internal.cli.main:main
|
|
||||||
pip3.12 = pip._internal.cli.main:main
|
|
@ -1 +0,0 @@
|
|||||||
pip
|
|
@ -1,13 +0,0 @@
|
|||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
__version__ = "24.0"
|
|
||||||
|
|
||||||
|
|
||||||
def main(args: Optional[List[str]] = None) -> int:
|
|
||||||
"""This is an internal API only meant for use by pip's own console scripts.
|
|
||||||
|
|
||||||
For additional details, see https://github.com/pypa/pip/issues/7498.
|
|
||||||
"""
|
|
||||||
from pip._internal.utils.entrypoints import _wrapper
|
|
||||||
|
|
||||||
return _wrapper(args)
|
|
@ -1,24 +0,0 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Remove '' and current working directory from the first entry
|
|
||||||
# of sys.path, if present to avoid using current directory
|
|
||||||
# in pip commands check, freeze, install, list and show,
|
|
||||||
# when invoked as python -m pip <command>
|
|
||||||
if sys.path[0] in ("", os.getcwd()):
|
|
||||||
sys.path.pop(0)
|
|
||||||
|
|
||||||
# If we are running from a wheel, add the wheel to sys.path
|
|
||||||
# This allows the usage python pip-*.whl/pip install pip-*.whl
|
|
||||||
if __package__ == "":
|
|
||||||
# __file__ is pip-*.whl/pip/__main__.py
|
|
||||||
# first dirname call strips of '/__main__.py', second strips off '/pip'
|
|
||||||
# Resulting path is the name of the wheel itself
|
|
||||||
# Add that to sys.path so we can import pip
|
|
||||||
path = os.path.dirname(os.path.dirname(__file__))
|
|
||||||
sys.path.insert(0, path)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
from pip._internal.cli.main import main as _main
|
|
||||||
|
|
||||||
sys.exit(_main())
|
|
@ -1,50 +0,0 @@
|
|||||||
"""Execute exactly this copy of pip, within a different environment.
|
|
||||||
|
|
||||||
This file is named as it is, to ensure that this module can't be imported via
|
|
||||||
an import statement.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# /!\ This version compatibility check section must be Python 2 compatible. /!\
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Copied from setup.py
|
|
||||||
PYTHON_REQUIRES = (3, 7)
|
|
||||||
|
|
||||||
|
|
||||||
def version_str(version): # type: ignore
|
|
||||||
return ".".join(str(v) for v in version)
|
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[:2] < PYTHON_REQUIRES:
|
|
||||||
raise SystemExit(
|
|
||||||
"This version of pip does not support python {} (requires >={}).".format(
|
|
||||||
version_str(sys.version_info[:2]), version_str(PYTHON_REQUIRES)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# From here on, we can use Python 3 features, but the syntax must remain
|
|
||||||
# Python 2 compatible.
|
|
||||||
|
|
||||||
import runpy # noqa: E402
|
|
||||||
from importlib.machinery import PathFinder # noqa: E402
|
|
||||||
from os.path import dirname # noqa: E402
|
|
||||||
|
|
||||||
PIP_SOURCES_ROOT = dirname(dirname(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
class PipImportRedirectingFinder:
|
|
||||||
@classmethod
|
|
||||||
def find_spec(self, fullname, path=None, target=None): # type: ignore
|
|
||||||
if fullname != "pip":
|
|
||||||
return None
|
|
||||||
|
|
||||||
spec = PathFinder.find_spec(fullname, [PIP_SOURCES_ROOT], target)
|
|
||||||
assert spec, (PIP_SOURCES_ROOT, fullname)
|
|
||||||
return spec
|
|
||||||
|
|
||||||
|
|
||||||
sys.meta_path.insert(0, PipImportRedirectingFinder())
|
|
||||||
|
|
||||||
assert __name__ == "__main__", "Cannot run __pip-runner__.py as a non-main module"
|
|
||||||
runpy.run_module("pip", run_name="__main__", alter_sys=True)
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,18 +0,0 @@
|
|||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
from pip._internal.utils import _log
|
|
||||||
|
|
||||||
# init_logging() must be called before any call to logging.getLogger()
|
|
||||||
# which happens at import of most modules.
|
|
||||||
_log.init_logging()
|
|
||||||
|
|
||||||
|
|
||||||
def main(args: (Optional[List[str]]) = None) -> int:
|
|
||||||
"""This is preserved for old console scripts that may still be referencing
|
|
||||||
it.
|
|
||||||
|
|
||||||
For additional details, see https://github.com/pypa/pip/issues/7498.
|
|
||||||
"""
|
|
||||||
from pip._internal.utils.entrypoints import _wrapper
|
|
||||||
|
|
||||||
return _wrapper(args)
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,311 +0,0 @@
|
|||||||
"""Build Environment used for isolation during sdist building
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import pathlib
|
|
||||||
import site
|
|
||||||
import sys
|
|
||||||
import textwrap
|
|
||||||
from collections import OrderedDict
|
|
||||||
from types import TracebackType
|
|
||||||
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type, Union
|
|
||||||
|
|
||||||
from pip._vendor.certifi import where
|
|
||||||
from pip._vendor.packaging.requirements import Requirement
|
|
||||||
from pip._vendor.packaging.version import Version
|
|
||||||
|
|
||||||
from pip import __file__ as pip_location
|
|
||||||
from pip._internal.cli.spinners import open_spinner
|
|
||||||
from pip._internal.locations import get_platlib, get_purelib, get_scheme
|
|
||||||
from pip._internal.metadata import get_default_environment, get_environment
|
|
||||||
from pip._internal.utils.subprocess import call_subprocess
|
|
||||||
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from pip._internal.index.package_finder import PackageFinder
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _dedup(a: str, b: str) -> Union[Tuple[str], Tuple[str, str]]:
|
|
||||||
return (a, b) if a != b else (a,)
|
|
||||||
|
|
||||||
|
|
||||||
class _Prefix:
|
|
||||||
def __init__(self, path: str) -> None:
|
|
||||||
self.path = path
|
|
||||||
self.setup = False
|
|
||||||
scheme = get_scheme("", prefix=path)
|
|
||||||
self.bin_dir = scheme.scripts
|
|
||||||
self.lib_dirs = _dedup(scheme.purelib, scheme.platlib)
|
|
||||||
|
|
||||||
|
|
||||||
def get_runnable_pip() -> str:
|
|
||||||
"""Get a file to pass to a Python executable, to run the currently-running pip.
|
|
||||||
|
|
||||||
This is used to run a pip subprocess, for installing requirements into the build
|
|
||||||
environment.
|
|
||||||
"""
|
|
||||||
source = pathlib.Path(pip_location).resolve().parent
|
|
||||||
|
|
||||||
if not source.is_dir():
|
|
||||||
# This would happen if someone is using pip from inside a zip file. In that
|
|
||||||
# case, we can use that directly.
|
|
||||||
return str(source)
|
|
||||||
|
|
||||||
return os.fsdecode(source / "__pip-runner__.py")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_system_sitepackages() -> Set[str]:
|
|
||||||
"""Get system site packages
|
|
||||||
|
|
||||||
Usually from site.getsitepackages,
|
|
||||||
but fallback on `get_purelib()/get_platlib()` if unavailable
|
|
||||||
(e.g. in a virtualenv created by virtualenv<20)
|
|
||||||
|
|
||||||
Returns normalized set of strings.
|
|
||||||
"""
|
|
||||||
if hasattr(site, "getsitepackages"):
|
|
||||||
system_sites = site.getsitepackages()
|
|
||||||
else:
|
|
||||||
# virtualenv < 20 overwrites site.py without getsitepackages
|
|
||||||
# fallback on get_purelib/get_platlib.
|
|
||||||
# this is known to miss things, but shouldn't in the cases
|
|
||||||
# where getsitepackages() has been removed (inside a virtualenv)
|
|
||||||
system_sites = [get_purelib(), get_platlib()]
|
|
||||||
return {os.path.normcase(path) for path in system_sites}
|
|
||||||
|
|
||||||
|
|
||||||
class BuildEnvironment:
|
|
||||||
"""Creates and manages an isolated environment to install build deps"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
temp_dir = TempDirectory(kind=tempdir_kinds.BUILD_ENV, globally_managed=True)
|
|
||||||
|
|
||||||
self._prefixes = OrderedDict(
|
|
||||||
(name, _Prefix(os.path.join(temp_dir.path, name)))
|
|
||||||
for name in ("normal", "overlay")
|
|
||||||
)
|
|
||||||
|
|
||||||
self._bin_dirs: List[str] = []
|
|
||||||
self._lib_dirs: List[str] = []
|
|
||||||
for prefix in reversed(list(self._prefixes.values())):
|
|
||||||
self._bin_dirs.append(prefix.bin_dir)
|
|
||||||
self._lib_dirs.extend(prefix.lib_dirs)
|
|
||||||
|
|
||||||
# Customize site to:
|
|
||||||
# - ensure .pth files are honored
|
|
||||||
# - prevent access to system site packages
|
|
||||||
system_sites = _get_system_sitepackages()
|
|
||||||
|
|
||||||
self._site_dir = os.path.join(temp_dir.path, "site")
|
|
||||||
if not os.path.exists(self._site_dir):
|
|
||||||
os.mkdir(self._site_dir)
|
|
||||||
with open(
|
|
||||||
os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
|
|
||||||
) as fp:
|
|
||||||
fp.write(
|
|
||||||
textwrap.dedent(
|
|
||||||
"""
|
|
||||||
import os, site, sys
|
|
||||||
|
|
||||||
# First, drop system-sites related paths.
|
|
||||||
original_sys_path = sys.path[:]
|
|
||||||
known_paths = set()
|
|
||||||
for path in {system_sites!r}:
|
|
||||||
site.addsitedir(path, known_paths=known_paths)
|
|
||||||
system_paths = set(
|
|
||||||
os.path.normcase(path)
|
|
||||||
for path in sys.path[len(original_sys_path):]
|
|
||||||
)
|
|
||||||
original_sys_path = [
|
|
||||||
path for path in original_sys_path
|
|
||||||
if os.path.normcase(path) not in system_paths
|
|
||||||
]
|
|
||||||
sys.path = original_sys_path
|
|
||||||
|
|
||||||
# Second, add lib directories.
|
|
||||||
# ensuring .pth file are processed.
|
|
||||||
for path in {lib_dirs!r}:
|
|
||||||
assert not path in sys.path
|
|
||||||
site.addsitedir(path)
|
|
||||||
"""
|
|
||||||
).format(system_sites=system_sites, lib_dirs=self._lib_dirs)
|
|
||||||
)
|
|
||||||
|
|
||||||
def __enter__(self) -> None:
|
|
||||||
self._save_env = {
|
|
||||||
name: os.environ.get(name, None)
|
|
||||||
for name in ("PATH", "PYTHONNOUSERSITE", "PYTHONPATH")
|
|
||||||
}
|
|
||||||
|
|
||||||
path = self._bin_dirs[:]
|
|
||||||
old_path = self._save_env["PATH"]
|
|
||||||
if old_path:
|
|
||||||
path.extend(old_path.split(os.pathsep))
|
|
||||||
|
|
||||||
pythonpath = [self._site_dir]
|
|
||||||
|
|
||||||
os.environ.update(
|
|
||||||
{
|
|
||||||
"PATH": os.pathsep.join(path),
|
|
||||||
"PYTHONNOUSERSITE": "1",
|
|
||||||
"PYTHONPATH": os.pathsep.join(pythonpath),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
def __exit__(
|
|
||||||
self,
|
|
||||||
exc_type: Optional[Type[BaseException]],
|
|
||||||
exc_val: Optional[BaseException],
|
|
||||||
exc_tb: Optional[TracebackType],
|
|
||||||
) -> None:
|
|
||||||
for varname, old_value in self._save_env.items():
|
|
||||||
if old_value is None:
|
|
||||||
os.environ.pop(varname, None)
|
|
||||||
else:
|
|
||||||
os.environ[varname] = old_value
|
|
||||||
|
|
||||||
def check_requirements(
|
|
||||||
self, reqs: Iterable[str]
|
|
||||||
) -> Tuple[Set[Tuple[str, str]], Set[str]]:
|
|
||||||
"""Return 2 sets:
|
|
||||||
- conflicting requirements: set of (installed, wanted) reqs tuples
|
|
||||||
- missing requirements: set of reqs
|
|
||||||
"""
|
|
||||||
missing = set()
|
|
||||||
conflicting = set()
|
|
||||||
if reqs:
|
|
||||||
env = (
|
|
||||||
get_environment(self._lib_dirs)
|
|
||||||
if hasattr(self, "_lib_dirs")
|
|
||||||
else get_default_environment()
|
|
||||||
)
|
|
||||||
for req_str in reqs:
|
|
||||||
req = Requirement(req_str)
|
|
||||||
# We're explicitly evaluating with an empty extra value, since build
|
|
||||||
# environments are not provided any mechanism to select specific extras.
|
|
||||||
if req.marker is not None and not req.marker.evaluate({"extra": ""}):
|
|
||||||
continue
|
|
||||||
dist = env.get_distribution(req.name)
|
|
||||||
if not dist:
|
|
||||||
missing.add(req_str)
|
|
||||||
continue
|
|
||||||
if isinstance(dist.version, Version):
|
|
||||||
installed_req_str = f"{req.name}=={dist.version}"
|
|
||||||
else:
|
|
||||||
installed_req_str = f"{req.name}==={dist.version}"
|
|
||||||
if not req.specifier.contains(dist.version, prereleases=True):
|
|
||||||
conflicting.add((installed_req_str, req_str))
|
|
||||||
# FIXME: Consider direct URL?
|
|
||||||
return conflicting, missing
|
|
||||||
|
|
||||||
def install_requirements(
|
|
||||||
self,
|
|
||||||
finder: "PackageFinder",
|
|
||||||
requirements: Iterable[str],
|
|
||||||
prefix_as_string: str,
|
|
||||||
*,
|
|
||||||
kind: str,
|
|
||||||
) -> None:
|
|
||||||
prefix = self._prefixes[prefix_as_string]
|
|
||||||
assert not prefix.setup
|
|
||||||
prefix.setup = True
|
|
||||||
if not requirements:
|
|
||||||
return
|
|
||||||
self._install_requirements(
|
|
||||||
get_runnable_pip(),
|
|
||||||
finder,
|
|
||||||
requirements,
|
|
||||||
prefix,
|
|
||||||
kind=kind,
|
|
||||||
)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _install_requirements(
|
|
||||||
pip_runnable: str,
|
|
||||||
finder: "PackageFinder",
|
|
||||||
requirements: Iterable[str],
|
|
||||||
prefix: _Prefix,
|
|
||||||
*,
|
|
||||||
kind: str,
|
|
||||||
) -> None:
|
|
||||||
args: List[str] = [
|
|
||||||
sys.executable,
|
|
||||||
pip_runnable,
|
|
||||||
"install",
|
|
||||||
"--ignore-installed",
|
|
||||||
"--no-user",
|
|
||||||
"--prefix",
|
|
||||||
prefix.path,
|
|
||||||
"--no-warn-script-location",
|
|
||||||
]
|
|
||||||
if logger.getEffectiveLevel() <= logging.DEBUG:
|
|
||||||
args.append("-v")
|
|
||||||
for format_control in ("no_binary", "only_binary"):
|
|
||||||
formats = getattr(finder.format_control, format_control)
|
|
||||||
args.extend(
|
|
||||||
(
|
|
||||||
"--" + format_control.replace("_", "-"),
|
|
||||||
",".join(sorted(formats or {":none:"})),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
index_urls = finder.index_urls
|
|
||||||
if index_urls:
|
|
||||||
args.extend(["-i", index_urls[0]])
|
|
||||||
for extra_index in index_urls[1:]:
|
|
||||||
args.extend(["--extra-index-url", extra_index])
|
|
||||||
else:
|
|
||||||
args.append("--no-index")
|
|
||||||
for link in finder.find_links:
|
|
||||||
args.extend(["--find-links", link])
|
|
||||||
|
|
||||||
for host in finder.trusted_hosts:
|
|
||||||
args.extend(["--trusted-host", host])
|
|
||||||
if finder.allow_all_prereleases:
|
|
||||||
args.append("--pre")
|
|
||||||
if finder.prefer_binary:
|
|
||||||
args.append("--prefer-binary")
|
|
||||||
args.append("--")
|
|
||||||
args.extend(requirements)
|
|
||||||
extra_environ = {"_PIP_STANDALONE_CERT": where()}
|
|
||||||
with open_spinner(f"Installing {kind}") as spinner:
|
|
||||||
call_subprocess(
|
|
||||||
args,
|
|
||||||
command_desc=f"pip subprocess to install {kind}",
|
|
||||||
spinner=spinner,
|
|
||||||
extra_environ=extra_environ,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class NoOpBuildEnvironment(BuildEnvironment):
|
|
||||||
"""A no-op drop-in replacement for BuildEnvironment"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __enter__(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __exit__(
|
|
||||||
self,
|
|
||||||
exc_type: Optional[Type[BaseException]],
|
|
||||||
exc_val: Optional[BaseException],
|
|
||||||
exc_tb: Optional[TracebackType],
|
|
||||||
) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def cleanup(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def install_requirements(
|
|
||||||
self,
|
|
||||||
finder: "PackageFinder",
|
|
||||||
requirements: Iterable[str],
|
|
||||||
prefix_as_string: str,
|
|
||||||
*,
|
|
||||||
kind: str,
|
|
||||||
) -> None:
|
|
||||||
raise NotImplementedError()
|
|
@ -1,290 +0,0 @@
|
|||||||
"""Cache Management
|
|
||||||
"""
|
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Any, Dict, List, Optional
|
|
||||||
|
|
||||||
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
|
||||||
from pip._vendor.packaging.utils import canonicalize_name
|
|
||||||
|
|
||||||
from pip._internal.exceptions import InvalidWheelFilename
|
|
||||||
from pip._internal.models.direct_url import DirectUrl
|
|
||||||
from pip._internal.models.link import Link
|
|
||||||
from pip._internal.models.wheel import Wheel
|
|
||||||
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
|
||||||
from pip._internal.utils.urls import path_to_url
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
ORIGIN_JSON_NAME = "origin.json"
|
|
||||||
|
|
||||||
|
|
||||||
def _hash_dict(d: Dict[str, str]) -> str:
|
|
||||||
"""Return a stable sha224 of a dictionary."""
|
|
||||||
s = json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
|
|
||||||
return hashlib.sha224(s.encode("ascii")).hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
class Cache:
|
|
||||||
"""An abstract class - provides cache directories for data from links
|
|
||||||
|
|
||||||
:param cache_dir: The root of the cache.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, cache_dir: str) -> None:
|
|
||||||
super().__init__()
|
|
||||||
assert not cache_dir or os.path.isabs(cache_dir)
|
|
||||||
self.cache_dir = cache_dir or None
|
|
||||||
|
|
||||||
def _get_cache_path_parts(self, link: Link) -> List[str]:
|
|
||||||
"""Get parts of part that must be os.path.joined with cache_dir"""
|
|
||||||
|
|
||||||
# We want to generate an url to use as our cache key, we don't want to
|
|
||||||
# just re-use the URL because it might have other items in the fragment
|
|
||||||
# and we don't care about those.
|
|
||||||
key_parts = {"url": link.url_without_fragment}
|
|
||||||
if link.hash_name is not None and link.hash is not None:
|
|
||||||
key_parts[link.hash_name] = link.hash
|
|
||||||
if link.subdirectory_fragment:
|
|
||||||
key_parts["subdirectory"] = link.subdirectory_fragment
|
|
||||||
|
|
||||||
# Include interpreter name, major and minor version in cache key
|
|
||||||
# to cope with ill-behaved sdists that build a different wheel
|
|
||||||
# depending on the python version their setup.py is being run on,
|
|
||||||
# and don't encode the difference in compatibility tags.
|
|
||||||
# https://github.com/pypa/pip/issues/7296
|
|
||||||
key_parts["interpreter_name"] = interpreter_name()
|
|
||||||
key_parts["interpreter_version"] = interpreter_version()
|
|
||||||
|
|
||||||
# Encode our key url with sha224, we'll use this because it has similar
|
|
||||||
# security properties to sha256, but with a shorter total output (and
|
|
||||||
# thus less secure). However the differences don't make a lot of
|
|
||||||
# difference for our use case here.
|
|
||||||
hashed = _hash_dict(key_parts)
|
|
||||||
|
|
||||||
# We want to nest the directories some to prevent having a ton of top
|
|
||||||
# level directories where we might run out of sub directories on some
|
|
||||||
# FS.
|
|
||||||
parts = [hashed[:2], hashed[2:4], hashed[4:6], hashed[6:]]
|
|
||||||
|
|
||||||
return parts
|
|
||||||
|
|
||||||
def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
|
|
||||||
can_not_cache = not self.cache_dir or not canonical_package_name or not link
|
|
||||||
if can_not_cache:
|
|
||||||
return []
|
|
||||||
|
|
||||||
path = self.get_path_for_link(link)
|
|
||||||
if os.path.isdir(path):
|
|
||||||
return [(candidate, path) for candidate in os.listdir(path)]
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_path_for_link(self, link: Link) -> str:
|
|
||||||
"""Return a directory to store cached items in for link."""
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def get(
|
|
||||||
self,
|
|
||||||
link: Link,
|
|
||||||
package_name: Optional[str],
|
|
||||||
supported_tags: List[Tag],
|
|
||||||
) -> Link:
|
|
||||||
"""Returns a link to a cached item if it exists, otherwise returns the
|
|
||||||
passed link.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleWheelCache(Cache):
|
|
||||||
"""A cache of wheels for future installs."""
|
|
||||||
|
|
||||||
def __init__(self, cache_dir: str) -> None:
|
|
||||||
super().__init__(cache_dir)
|
|
||||||
|
|
||||||
def get_path_for_link(self, link: Link) -> str:
|
|
||||||
"""Return a directory to store cached wheels for link
|
|
||||||
|
|
||||||
Because there are M wheels for any one sdist, we provide a directory
|
|
||||||
to cache them in, and then consult that directory when looking up
|
|
||||||
cache hits.
|
|
||||||
|
|
||||||
We only insert things into the cache if they have plausible version
|
|
||||||
numbers, so that we don't contaminate the cache with things that were
|
|
||||||
not unique. E.g. ./package might have dozens of installs done for it
|
|
||||||
and build a version of 0.0...and if we built and cached a wheel, we'd
|
|
||||||
end up using the same wheel even if the source has been edited.
|
|
||||||
|
|
||||||
:param link: The link of the sdist for which this will cache wheels.
|
|
||||||
"""
|
|
||||||
parts = self._get_cache_path_parts(link)
|
|
||||||
assert self.cache_dir
|
|
||||||
# Store wheels within the root cache_dir
|
|
||||||
return os.path.join(self.cache_dir, "wheels", *parts)
|
|
||||||
|
|
||||||
def get(
|
|
||||||
self,
|
|
||||||
link: Link,
|
|
||||||
package_name: Optional[str],
|
|
||||||
supported_tags: List[Tag],
|
|
||||||
) -> Link:
|
|
||||||
candidates = []
|
|
||||||
|
|
||||||
if not package_name:
|
|
||||||
return link
|
|
||||||
|
|
||||||
canonical_package_name = canonicalize_name(package_name)
|
|
||||||
for wheel_name, wheel_dir in self._get_candidates(link, canonical_package_name):
|
|
||||||
try:
|
|
||||||
wheel = Wheel(wheel_name)
|
|
||||||
except InvalidWheelFilename:
|
|
||||||
continue
|
|
||||||
if canonicalize_name(wheel.name) != canonical_package_name:
|
|
||||||
logger.debug(
|
|
||||||
"Ignoring cached wheel %s for %s as it "
|
|
||||||
"does not match the expected distribution name %s.",
|
|
||||||
wheel_name,
|
|
||||||
link,
|
|
||||||
package_name,
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
if not wheel.supported(supported_tags):
|
|
||||||
# Built for a different python/arch/etc
|
|
||||||
continue
|
|
||||||
candidates.append(
|
|
||||||
(
|
|
||||||
wheel.support_index_min(supported_tags),
|
|
||||||
wheel_name,
|
|
||||||
wheel_dir,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not candidates:
|
|
||||||
return link
|
|
||||||
|
|
||||||
_, wheel_name, wheel_dir = min(candidates)
|
|
||||||
return Link(path_to_url(os.path.join(wheel_dir, wheel_name)))
|
|
||||||
|
|
||||||
|
|
||||||
class EphemWheelCache(SimpleWheelCache):
|
|
||||||
"""A SimpleWheelCache that creates it's own temporary cache directory"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
self._temp_dir = TempDirectory(
|
|
||||||
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
|
|
||||||
globally_managed=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
super().__init__(self._temp_dir.path)
|
|
||||||
|
|
||||||
|
|
||||||
class CacheEntry:
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
link: Link,
|
|
||||||
persistent: bool,
|
|
||||||
):
|
|
||||||
self.link = link
|
|
||||||
self.persistent = persistent
|
|
||||||
self.origin: Optional[DirectUrl] = None
|
|
||||||
origin_direct_url_path = Path(self.link.file_path).parent / ORIGIN_JSON_NAME
|
|
||||||
if origin_direct_url_path.exists():
|
|
||||||
try:
|
|
||||||
self.origin = DirectUrl.from_json(
|
|
||||||
origin_direct_url_path.read_text(encoding="utf-8")
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(
|
|
||||||
"Ignoring invalid cache entry origin file %s for %s (%s)",
|
|
||||||
origin_direct_url_path,
|
|
||||||
link.filename,
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class WheelCache(Cache):
|
|
||||||
"""Wraps EphemWheelCache and SimpleWheelCache into a single Cache
|
|
||||||
|
|
||||||
This Cache allows for gracefully degradation, using the ephem wheel cache
|
|
||||||
when a certain link is not found in the simple wheel cache first.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, cache_dir: str) -> None:
|
|
||||||
super().__init__(cache_dir)
|
|
||||||
self._wheel_cache = SimpleWheelCache(cache_dir)
|
|
||||||
self._ephem_cache = EphemWheelCache()
|
|
||||||
|
|
||||||
def get_path_for_link(self, link: Link) -> str:
|
|
||||||
return self._wheel_cache.get_path_for_link(link)
|
|
||||||
|
|
||||||
def get_ephem_path_for_link(self, link: Link) -> str:
|
|
||||||
return self._ephem_cache.get_path_for_link(link)
|
|
||||||
|
|
||||||
def get(
|
|
||||||
self,
|
|
||||||
link: Link,
|
|
||||||
package_name: Optional[str],
|
|
||||||
supported_tags: List[Tag],
|
|
||||||
) -> Link:
|
|
||||||
cache_entry = self.get_cache_entry(link, package_name, supported_tags)
|
|
||||||
if cache_entry is None:
|
|
||||||
return link
|
|
||||||
return cache_entry.link
|
|
||||||
|
|
||||||
def get_cache_entry(
|
|
||||||
self,
|
|
||||||
link: Link,
|
|
||||||
package_name: Optional[str],
|
|
||||||
supported_tags: List[Tag],
|
|
||||||
) -> Optional[CacheEntry]:
|
|
||||||
"""Returns a CacheEntry with a link to a cached item if it exists or
|
|
||||||
None. The cache entry indicates if the item was found in the persistent
|
|
||||||
or ephemeral cache.
|
|
||||||
"""
|
|
||||||
retval = self._wheel_cache.get(
|
|
||||||
link=link,
|
|
||||||
package_name=package_name,
|
|
||||||
supported_tags=supported_tags,
|
|
||||||
)
|
|
||||||
if retval is not link:
|
|
||||||
return CacheEntry(retval, persistent=True)
|
|
||||||
|
|
||||||
retval = self._ephem_cache.get(
|
|
||||||
link=link,
|
|
||||||
package_name=package_name,
|
|
||||||
supported_tags=supported_tags,
|
|
||||||
)
|
|
||||||
if retval is not link:
|
|
||||||
return CacheEntry(retval, persistent=False)
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def record_download_origin(cache_dir: str, download_info: DirectUrl) -> None:
|
|
||||||
origin_path = Path(cache_dir) / ORIGIN_JSON_NAME
|
|
||||||
if origin_path.exists():
|
|
||||||
try:
|
|
||||||
origin = DirectUrl.from_json(origin_path.read_text(encoding="utf-8"))
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(
|
|
||||||
"Could not read origin file %s in cache entry (%s). "
|
|
||||||
"Will attempt to overwrite it.",
|
|
||||||
origin_path,
|
|
||||||
e,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
# TODO: use DirectUrl.equivalent when
|
|
||||||
# https://github.com/pypa/pip/pull/10564 is merged.
|
|
||||||
if origin.url != download_info.url:
|
|
||||||
logger.warning(
|
|
||||||
"Origin URL %s in cache entry %s does not match download URL "
|
|
||||||
"%s. This is likely a pip bug or a cache corruption issue. "
|
|
||||||
"Will overwrite it with the new value.",
|
|
||||||
origin.url,
|
|
||||||
cache_dir,
|
|
||||||
download_info.url,
|
|
||||||
)
|
|
||||||
origin_path.write_text(download_info.to_json(), encoding="utf-8")
|
|
@ -1,4 +0,0 @@
|
|||||||
"""Subpackage containing all of pip's command line interface related code
|
|
||||||
"""
|
|
||||||
|
|
||||||
# This file intentionally does not import submodules
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,172 +0,0 @@
|
|||||||
"""Logic that powers autocompletion installed by ``pip completion``.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import optparse
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from itertools import chain
|
|
||||||
from typing import Any, Iterable, List, Optional
|
|
||||||
|
|
||||||
from pip._internal.cli.main_parser import create_main_parser
|
|
||||||
from pip._internal.commands import commands_dict, create_command
|
|
||||||
from pip._internal.metadata import get_default_environment
|
|
||||||
|
|
||||||
|
|
||||||
def autocomplete() -> None:
|
|
||||||
"""Entry Point for completion of main and subcommand options."""
|
|
||||||
# Don't complete if user hasn't sourced bash_completion file.
|
|
||||||
if "PIP_AUTO_COMPLETE" not in os.environ:
|
|
||||||
return
|
|
||||||
cwords = os.environ["COMP_WORDS"].split()[1:]
|
|
||||||
cword = int(os.environ["COMP_CWORD"])
|
|
||||||
try:
|
|
||||||
current = cwords[cword - 1]
|
|
||||||
except IndexError:
|
|
||||||
current = ""
|
|
||||||
|
|
||||||
parser = create_main_parser()
|
|
||||||
subcommands = list(commands_dict)
|
|
||||||
options = []
|
|
||||||
|
|
||||||
# subcommand
|
|
||||||
subcommand_name: Optional[str] = None
|
|
||||||
for word in cwords:
|
|
||||||
if word in subcommands:
|
|
||||||
subcommand_name = word
|
|
||||||
break
|
|
||||||
# subcommand options
|
|
||||||
if subcommand_name is not None:
|
|
||||||
# special case: 'help' subcommand has no options
|
|
||||||
if subcommand_name == "help":
|
|
||||||
sys.exit(1)
|
|
||||||
# special case: list locally installed dists for show and uninstall
|
|
||||||
should_list_installed = not current.startswith("-") and subcommand_name in [
|
|
||||||
"show",
|
|
||||||
"uninstall",
|
|
||||||
]
|
|
||||||
if should_list_installed:
|
|
||||||
env = get_default_environment()
|
|
||||||
lc = current.lower()
|
|
||||||
installed = [
|
|
||||||
dist.canonical_name
|
|
||||||
for dist in env.iter_installed_distributions(local_only=True)
|
|
||||||
if dist.canonical_name.startswith(lc)
|
|
||||||
and dist.canonical_name not in cwords[1:]
|
|
||||||
]
|
|
||||||
# if there are no dists installed, fall back to option completion
|
|
||||||
if installed:
|
|
||||||
for dist in installed:
|
|
||||||
print(dist)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
should_list_installables = (
|
|
||||||
not current.startswith("-") and subcommand_name == "install"
|
|
||||||
)
|
|
||||||
if should_list_installables:
|
|
||||||
for path in auto_complete_paths(current, "path"):
|
|
||||||
print(path)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
subcommand = create_command(subcommand_name)
|
|
||||||
|
|
||||||
for opt in subcommand.parser.option_list_all:
|
|
||||||
if opt.help != optparse.SUPPRESS_HELP:
|
|
||||||
options += [
|
|
||||||
(opt_str, opt.nargs) for opt_str in opt._long_opts + opt._short_opts
|
|
||||||
]
|
|
||||||
|
|
||||||
# filter out previously specified options from available options
|
|
||||||
prev_opts = [x.split("=")[0] for x in cwords[1 : cword - 1]]
|
|
||||||
options = [(x, v) for (x, v) in options if x not in prev_opts]
|
|
||||||
# filter options by current input
|
|
||||||
options = [(k, v) for k, v in options if k.startswith(current)]
|
|
||||||
# get completion type given cwords and available subcommand options
|
|
||||||
completion_type = get_path_completion_type(
|
|
||||||
cwords,
|
|
||||||
cword,
|
|
||||||
subcommand.parser.option_list_all,
|
|
||||||
)
|
|
||||||
# get completion files and directories if ``completion_type`` is
|
|
||||||
# ``<file>``, ``<dir>`` or ``<path>``
|
|
||||||
if completion_type:
|
|
||||||
paths = auto_complete_paths(current, completion_type)
|
|
||||||
options = [(path, 0) for path in paths]
|
|
||||||
for option in options:
|
|
||||||
opt_label = option[0]
|
|
||||||
# append '=' to options which require args
|
|
||||||
if option[1] and option[0][:2] == "--":
|
|
||||||
opt_label += "="
|
|
||||||
print(opt_label)
|
|
||||||
else:
|
|
||||||
# show main parser options only when necessary
|
|
||||||
|
|
||||||
opts = [i.option_list for i in parser.option_groups]
|
|
||||||
opts.append(parser.option_list)
|
|
||||||
flattened_opts = chain.from_iterable(opts)
|
|
||||||
if current.startswith("-"):
|
|
||||||
for opt in flattened_opts:
|
|
||||||
if opt.help != optparse.SUPPRESS_HELP:
|
|
||||||
subcommands += opt._long_opts + opt._short_opts
|
|
||||||
else:
|
|
||||||
# get completion type given cwords and all available options
|
|
||||||
completion_type = get_path_completion_type(cwords, cword, flattened_opts)
|
|
||||||
if completion_type:
|
|
||||||
subcommands = list(auto_complete_paths(current, completion_type))
|
|
||||||
|
|
||||||
print(" ".join([x for x in subcommands if x.startswith(current)]))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def get_path_completion_type(
|
|
||||||
cwords: List[str], cword: int, opts: Iterable[Any]
|
|
||||||
) -> Optional[str]:
|
|
||||||
"""Get the type of path completion (``file``, ``dir``, ``path`` or None)
|
|
||||||
|
|
||||||
:param cwords: same as the environmental variable ``COMP_WORDS``
|
|
||||||
:param cword: same as the environmental variable ``COMP_CWORD``
|
|
||||||
:param opts: The available options to check
|
|
||||||
:return: path completion type (``file``, ``dir``, ``path`` or None)
|
|
||||||
"""
|
|
||||||
if cword < 2 or not cwords[cword - 2].startswith("-"):
|
|
||||||
return None
|
|
||||||
for opt in opts:
|
|
||||||
if opt.help == optparse.SUPPRESS_HELP:
|
|
||||||
continue
|
|
||||||
for o in str(opt).split("/"):
|
|
||||||
if cwords[cword - 2].split("=")[0] == o:
|
|
||||||
if not opt.metavar or any(
|
|
||||||
x in ("path", "file", "dir") for x in opt.metavar.split("/")
|
|
||||||
):
|
|
||||||
return opt.metavar
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def auto_complete_paths(current: str, completion_type: str) -> Iterable[str]:
|
|
||||||
"""If ``completion_type`` is ``file`` or ``path``, list all regular files
|
|
||||||
and directories starting with ``current``; otherwise only list directories
|
|
||||||
starting with ``current``.
|
|
||||||
|
|
||||||
:param current: The word to be completed
|
|
||||||
:param completion_type: path completion type(``file``, ``path`` or ``dir``)
|
|
||||||
:return: A generator of regular files and/or directories
|
|
||||||
"""
|
|
||||||
directory, filename = os.path.split(current)
|
|
||||||
current_path = os.path.abspath(directory)
|
|
||||||
# Don't complete paths if they can't be accessed
|
|
||||||
if not os.access(current_path, os.R_OK):
|
|
||||||
return
|
|
||||||
filename = os.path.normcase(filename)
|
|
||||||
# list all files that start with ``filename``
|
|
||||||
file_list = (
|
|
||||||
x for x in os.listdir(current_path) if os.path.normcase(x).startswith(filename)
|
|
||||||
)
|
|
||||||
for f in file_list:
|
|
||||||
opt = os.path.join(current_path, f)
|
|
||||||
comp_file = os.path.normcase(os.path.join(directory, f))
|
|
||||||
# complete regular files when there is not ``<dir>`` after option
|
|
||||||
# complete directories when there is ``<file>``, ``<path>`` or
|
|
||||||
# ``<dir>``after option
|
|
||||||
if completion_type != "dir" and os.path.isfile(opt):
|
|
||||||
yield comp_file
|
|
||||||
elif os.path.isdir(opt):
|
|
||||||
yield os.path.join(comp_file, "")
|
|
@ -1,236 +0,0 @@
|
|||||||
"""Base Command class, and related routines"""
|
|
||||||
|
|
||||||
import functools
|
|
||||||
import logging
|
|
||||||
import logging.config
|
|
||||||
import optparse
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import traceback
|
|
||||||
from optparse import Values
|
|
||||||
from typing import Any, Callable, List, Optional, Tuple
|
|
||||||
|
|
||||||
from pip._vendor.rich import traceback as rich_traceback
|
|
||||||
|
|
||||||
from pip._internal.cli import cmdoptions
|
|
||||||
from pip._internal.cli.command_context import CommandContextMixIn
|
|
||||||
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
|
||||||
from pip._internal.cli.status_codes import (
|
|
||||||
ERROR,
|
|
||||||
PREVIOUS_BUILD_DIR_ERROR,
|
|
||||||
UNKNOWN_ERROR,
|
|
||||||
VIRTUALENV_NOT_FOUND,
|
|
||||||
)
|
|
||||||
from pip._internal.exceptions import (
|
|
||||||
BadCommand,
|
|
||||||
CommandError,
|
|
||||||
DiagnosticPipError,
|
|
||||||
InstallationError,
|
|
||||||
NetworkConnectionError,
|
|
||||||
PreviousBuildDirError,
|
|
||||||
UninstallationError,
|
|
||||||
)
|
|
||||||
from pip._internal.utils.filesystem import check_path_owner
|
|
||||||
from pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
|
|
||||||
from pip._internal.utils.misc import get_prog, normalize_path
|
|
||||||
from pip._internal.utils.temp_dir import TempDirectoryTypeRegistry as TempDirRegistry
|
|
||||||
from pip._internal.utils.temp_dir import global_tempdir_manager, tempdir_registry
|
|
||||||
from pip._internal.utils.virtualenv import running_under_virtualenv
|
|
||||||
|
|
||||||
__all__ = ["Command"]
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class Command(CommandContextMixIn):
|
|
||||||
usage: str = ""
|
|
||||||
ignore_require_venv: bool = False
|
|
||||||
|
|
||||||
def __init__(self, name: str, summary: str, isolated: bool = False) -> None:
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
self.name = name
|
|
||||||
self.summary = summary
|
|
||||||
self.parser = ConfigOptionParser(
|
|
||||||
usage=self.usage,
|
|
||||||
prog=f"{get_prog()} {name}",
|
|
||||||
formatter=UpdatingDefaultsHelpFormatter(),
|
|
||||||
add_help_option=False,
|
|
||||||
name=name,
|
|
||||||
description=self.__doc__,
|
|
||||||
isolated=isolated,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.tempdir_registry: Optional[TempDirRegistry] = None
|
|
||||||
|
|
||||||
# Commands should add options to this option group
|
|
||||||
optgroup_name = f"{self.name.capitalize()} Options"
|
|
||||||
self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
|
|
||||||
|
|
||||||
# Add the general options
|
|
||||||
gen_opts = cmdoptions.make_option_group(
|
|
||||||
cmdoptions.general_group,
|
|
||||||
self.parser,
|
|
||||||
)
|
|
||||||
self.parser.add_option_group(gen_opts)
|
|
||||||
|
|
||||||
self.add_options()
|
|
||||||
|
|
||||||
def add_options(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def handle_pip_version_check(self, options: Values) -> None:
|
|
||||||
"""
|
|
||||||
This is a no-op so that commands by default do not do the pip version
|
|
||||||
check.
|
|
||||||
"""
|
|
||||||
# Make sure we do the pip version check if the index_group options
|
|
||||||
# are present.
|
|
||||||
assert not hasattr(options, "no_index")
|
|
||||||
|
|
||||||
def run(self, options: Values, args: List[str]) -> int:
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def parse_args(self, args: List[str]) -> Tuple[Values, List[str]]:
|
|
||||||
# factored out for testability
|
|
||||||
return self.parser.parse_args(args)
|
|
||||||
|
|
||||||
def main(self, args: List[str]) -> int:
|
|
||||||
try:
|
|
||||||
with self.main_context():
|
|
||||||
return self._main(args)
|
|
||||||
finally:
|
|
||||||
logging.shutdown()
|
|
||||||
|
|
||||||
def _main(self, args: List[str]) -> int:
|
|
||||||
# We must initialize this before the tempdir manager, otherwise the
|
|
||||||
# configuration would not be accessible by the time we clean up the
|
|
||||||
# tempdir manager.
|
|
||||||
self.tempdir_registry = self.enter_context(tempdir_registry())
|
|
||||||
# Intentionally set as early as possible so globally-managed temporary
|
|
||||||
# directories are available to the rest of the code.
|
|
||||||
self.enter_context(global_tempdir_manager())
|
|
||||||
|
|
||||||
options, args = self.parse_args(args)
|
|
||||||
|
|
||||||
# Set verbosity so that it can be used elsewhere.
|
|
||||||
self.verbosity = options.verbose - options.quiet
|
|
||||||
|
|
||||||
level_number = setup_logging(
|
|
||||||
verbosity=self.verbosity,
|
|
||||||
no_color=options.no_color,
|
|
||||||
user_log_file=options.log,
|
|
||||||
)
|
|
||||||
|
|
||||||
always_enabled_features = set(options.features_enabled) & set(
|
|
||||||
cmdoptions.ALWAYS_ENABLED_FEATURES
|
|
||||||
)
|
|
||||||
if always_enabled_features:
|
|
||||||
logger.warning(
|
|
||||||
"The following features are always enabled: %s. ",
|
|
||||||
", ".join(sorted(always_enabled_features)),
|
|
||||||
)
|
|
||||||
|
|
||||||
# Make sure that the --python argument isn't specified after the
|
|
||||||
# subcommand. We can tell, because if --python was specified,
|
|
||||||
# we should only reach this point if we're running in the created
|
|
||||||
# subprocess, which has the _PIP_RUNNING_IN_SUBPROCESS environment
|
|
||||||
# variable set.
|
|
||||||
if options.python and "_PIP_RUNNING_IN_SUBPROCESS" not in os.environ:
|
|
||||||
logger.critical(
|
|
||||||
"The --python option must be placed before the pip subcommand name"
|
|
||||||
)
|
|
||||||
sys.exit(ERROR)
|
|
||||||
|
|
||||||
# TODO: Try to get these passing down from the command?
|
|
||||||
# without resorting to os.environ to hold these.
|
|
||||||
# This also affects isolated builds and it should.
|
|
||||||
|
|
||||||
if options.no_input:
|
|
||||||
os.environ["PIP_NO_INPUT"] = "1"
|
|
||||||
|
|
||||||
if options.exists_action:
|
|
||||||
os.environ["PIP_EXISTS_ACTION"] = " ".join(options.exists_action)
|
|
||||||
|
|
||||||
if options.require_venv and not self.ignore_require_venv:
|
|
||||||
# If a venv is required check if it can really be found
|
|
||||||
if not running_under_virtualenv():
|
|
||||||
logger.critical("Could not find an activated virtualenv (required).")
|
|
||||||
sys.exit(VIRTUALENV_NOT_FOUND)
|
|
||||||
|
|
||||||
if options.cache_dir:
|
|
||||||
options.cache_dir = normalize_path(options.cache_dir)
|
|
||||||
if not check_path_owner(options.cache_dir):
|
|
||||||
logger.warning(
|
|
||||||
"The directory '%s' or its parent directory is not owned "
|
|
||||||
"or is not writable by the current user. The cache "
|
|
||||||
"has been disabled. Check the permissions and owner of "
|
|
||||||
"that directory. If executing pip with sudo, you should "
|
|
||||||
"use sudo's -H flag.",
|
|
||||||
options.cache_dir,
|
|
||||||
)
|
|
||||||
options.cache_dir = None
|
|
||||||
|
|
||||||
def intercepts_unhandled_exc(
|
|
||||||
run_func: Callable[..., int]
|
|
||||||
) -> Callable[..., int]:
|
|
||||||
@functools.wraps(run_func)
|
|
||||||
def exc_logging_wrapper(*args: Any) -> int:
|
|
||||||
try:
|
|
||||||
status = run_func(*args)
|
|
||||||
assert isinstance(status, int)
|
|
||||||
return status
|
|
||||||
except DiagnosticPipError as exc:
|
|
||||||
logger.error("%s", exc, extra={"rich": True})
|
|
||||||
logger.debug("Exception information:", exc_info=True)
|
|
||||||
|
|
||||||
return ERROR
|
|
||||||
except PreviousBuildDirError as exc:
|
|
||||||
logger.critical(str(exc))
|
|
||||||
logger.debug("Exception information:", exc_info=True)
|
|
||||||
|
|
||||||
return PREVIOUS_BUILD_DIR_ERROR
|
|
||||||
except (
|
|
||||||
InstallationError,
|
|
||||||
UninstallationError,
|
|
||||||
BadCommand,
|
|
||||||
NetworkConnectionError,
|
|
||||||
) as exc:
|
|
||||||
logger.critical(str(exc))
|
|
||||||
logger.debug("Exception information:", exc_info=True)
|
|
||||||
|
|
||||||
return ERROR
|
|
||||||
except CommandError as exc:
|
|
||||||
logger.critical("%s", exc)
|
|
||||||
logger.debug("Exception information:", exc_info=True)
|
|
||||||
|
|
||||||
return ERROR
|
|
||||||
except BrokenStdoutLoggingError:
|
|
||||||
# Bypass our logger and write any remaining messages to
|
|
||||||
# stderr because stdout no longer works.
|
|
||||||
print("ERROR: Pipe to stdout was broken", file=sys.stderr)
|
|
||||||
if level_number <= logging.DEBUG:
|
|
||||||
traceback.print_exc(file=sys.stderr)
|
|
||||||
|
|
||||||
return ERROR
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
logger.critical("Operation cancelled by user")
|
|
||||||
logger.debug("Exception information:", exc_info=True)
|
|
||||||
|
|
||||||
return ERROR
|
|
||||||
except BaseException:
|
|
||||||
logger.critical("Exception:", exc_info=True)
|
|
||||||
|
|
||||||
return UNKNOWN_ERROR
|
|
||||||
|
|
||||||
return exc_logging_wrapper
|
|
||||||
|
|
||||||
try:
|
|
||||||
if not options.debug_mode:
|
|
||||||
run = intercepts_unhandled_exc(self.run)
|
|
||||||
else:
|
|
||||||
run = self.run
|
|
||||||
rich_traceback.install(show_locals=True)
|
|
||||||
return run(options, args)
|
|
||||||
finally:
|
|
||||||
self.handle_pip_version_check(options)
|
|
File diff suppressed because it is too large
Load Diff
@ -1,27 +0,0 @@
|
|||||||
from contextlib import ExitStack, contextmanager
|
|
||||||
from typing import ContextManager, Generator, TypeVar
|
|
||||||
|
|
||||||
_T = TypeVar("_T", covariant=True)
|
|
||||||
|
|
||||||
|
|
||||||
class CommandContextMixIn:
|
|
||||||
def __init__(self) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self._in_main_context = False
|
|
||||||
self._main_context = ExitStack()
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def main_context(self) -> Generator[None, None, None]:
|
|
||||||
assert not self._in_main_context
|
|
||||||
|
|
||||||
self._in_main_context = True
|
|
||||||
try:
|
|
||||||
with self._main_context:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
self._in_main_context = False
|
|
||||||
|
|
||||||
def enter_context(self, context_provider: ContextManager[_T]) -> _T:
|
|
||||||
assert self._in_main_context
|
|
||||||
|
|
||||||
return self._main_context.enter_context(context_provider)
|
|
@ -1,79 +0,0 @@
|
|||||||
"""Primary application entrypoint.
|
|
||||||
"""
|
|
||||||
import locale
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import warnings
|
|
||||||
from typing import List, Optional
|
|
||||||
|
|
||||||
from pip._internal.cli.autocompletion import autocomplete
|
|
||||||
from pip._internal.cli.main_parser import parse_command
|
|
||||||
from pip._internal.commands import create_command
|
|
||||||
from pip._internal.exceptions import PipError
|
|
||||||
from pip._internal.utils import deprecation
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
# Do not import and use main() directly! Using it directly is actively
|
|
||||||
# discouraged by pip's maintainers. The name, location and behavior of
|
|
||||||
# this function is subject to change, so calling it directly is not
|
|
||||||
# portable across different pip versions.
|
|
||||||
|
|
||||||
# In addition, running pip in-process is unsupported and unsafe. This is
|
|
||||||
# elaborated in detail at
|
|
||||||
# https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program.
|
|
||||||
# That document also provides suggestions that should work for nearly
|
|
||||||
# all users that are considering importing and using main() directly.
|
|
||||||
|
|
||||||
# However, we know that certain users will still want to invoke pip
|
|
||||||
# in-process. If you understand and accept the implications of using pip
|
|
||||||
# in an unsupported manner, the best approach is to use runpy to avoid
|
|
||||||
# depending on the exact location of this entry point.
|
|
||||||
|
|
||||||
# The following example shows how to use runpy to invoke pip in that
|
|
||||||
# case:
|
|
||||||
#
|
|
||||||
# sys.argv = ["pip", your, args, here]
|
|
||||||
# runpy.run_module("pip", run_name="__main__")
|
|
||||||
#
|
|
||||||
# Note that this will exit the process after running, unlike a direct
|
|
||||||
# call to main. As it is not safe to do any processing after calling
|
|
||||||
# main, this should not be an issue in practice.
|
|
||||||
|
|
||||||
|
|
||||||
def main(args: Optional[List[str]] = None) -> int:
|
|
||||||
if args is None:
|
|
||||||
args = sys.argv[1:]
|
|
||||||
|
|
||||||
# Suppress the pkg_resources deprecation warning
|
|
||||||
# Note - we use a module of .*pkg_resources to cover
|
|
||||||
# the normal case (pip._vendor.pkg_resources) and the
|
|
||||||
# devendored case (a bare pkg_resources)
|
|
||||||
warnings.filterwarnings(
|
|
||||||
action="ignore", category=DeprecationWarning, module=".*pkg_resources"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Configure our deprecation warnings to be sent through loggers
|
|
||||||
deprecation.install_warning_logger()
|
|
||||||
|
|
||||||
autocomplete()
|
|
||||||
|
|
||||||
try:
|
|
||||||
cmd_name, cmd_args = parse_command(args)
|
|
||||||
except PipError as exc:
|
|
||||||
sys.stderr.write(f"ERROR: {exc}")
|
|
||||||
sys.stderr.write(os.linesep)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Needed for locale.getpreferredencoding(False) to work
|
|
||||||
# in pip._internal.utils.encoding.auto_decode
|
|
||||||
try:
|
|
||||||
locale.setlocale(locale.LC_ALL, "")
|
|
||||||
except locale.Error as e:
|
|
||||||
# setlocale can apparently crash if locale are uninitialized
|
|
||||||
logger.debug("Ignoring error %s when setting locale", e)
|
|
||||||
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
|
|
||||||
|
|
||||||
return command.main(cmd_args)
|
|
@ -1,134 +0,0 @@
|
|||||||
"""A single place for constructing and exposing the main parser
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
from typing import List, Optional, Tuple
|
|
||||||
|
|
||||||
from pip._internal.build_env import get_runnable_pip
|
|
||||||
from pip._internal.cli import cmdoptions
|
|
||||||
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
|
||||||
from pip._internal.commands import commands_dict, get_similar_commands
|
|
||||||
from pip._internal.exceptions import CommandError
|
|
||||||
from pip._internal.utils.misc import get_pip_version, get_prog
|
|
||||||
|
|
||||||
__all__ = ["create_main_parser", "parse_command"]
|
|
||||||
|
|
||||||
|
|
||||||
def create_main_parser() -> ConfigOptionParser:
|
|
||||||
"""Creates and returns the main parser for pip's CLI"""
|
|
||||||
|
|
||||||
parser = ConfigOptionParser(
|
|
||||||
usage="\n%prog <command> [options]",
|
|
||||||
add_help_option=False,
|
|
||||||
formatter=UpdatingDefaultsHelpFormatter(),
|
|
||||||
name="global",
|
|
||||||
prog=get_prog(),
|
|
||||||
)
|
|
||||||
parser.disable_interspersed_args()
|
|
||||||
|
|
||||||
parser.version = get_pip_version()
|
|
||||||
|
|
||||||
# add the general options
|
|
||||||
gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
|
|
||||||
parser.add_option_group(gen_opts)
|
|
||||||
|
|
||||||
# so the help formatter knows
|
|
||||||
parser.main = True # type: ignore
|
|
||||||
|
|
||||||
# create command listing for description
|
|
||||||
description = [""] + [
|
|
||||||
f"{name:27} {command_info.summary}"
|
|
||||||
for name, command_info in commands_dict.items()
|
|
||||||
]
|
|
||||||
parser.description = "\n".join(description)
|
|
||||||
|
|
||||||
return parser
|
|
||||||
|
|
||||||
|
|
||||||
def identify_python_interpreter(python: str) -> Optional[str]:
|
|
||||||
# If the named file exists, use it.
|
|
||||||
# If it's a directory, assume it's a virtual environment and
|
|
||||||
# look for the environment's Python executable.
|
|
||||||
if os.path.exists(python):
|
|
||||||
if os.path.isdir(python):
|
|
||||||
# bin/python for Unix, Scripts/python.exe for Windows
|
|
||||||
# Try both in case of odd cases like cygwin.
|
|
||||||
for exe in ("bin/python", "Scripts/python.exe"):
|
|
||||||
py = os.path.join(python, exe)
|
|
||||||
if os.path.exists(py):
|
|
||||||
return py
|
|
||||||
else:
|
|
||||||
return python
|
|
||||||
|
|
||||||
# Could not find the interpreter specified
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def parse_command(args: List[str]) -> Tuple[str, List[str]]:
|
|
||||||
parser = create_main_parser()
|
|
||||||
|
|
||||||
# Note: parser calls disable_interspersed_args(), so the result of this
|
|
||||||
# call is to split the initial args into the general options before the
|
|
||||||
# subcommand and everything else.
|
|
||||||
# For example:
|
|
||||||
# args: ['--timeout=5', 'install', '--user', 'INITools']
|
|
||||||
# general_options: ['--timeout==5']
|
|
||||||
# args_else: ['install', '--user', 'INITools']
|
|
||||||
general_options, args_else = parser.parse_args(args)
|
|
||||||
|
|
||||||
# --python
|
|
||||||
if general_options.python and "_PIP_RUNNING_IN_SUBPROCESS" not in os.environ:
|
|
||||||
# Re-invoke pip using the specified Python interpreter
|
|
||||||
interpreter = identify_python_interpreter(general_options.python)
|
|
||||||
if interpreter is None:
|
|
||||||
raise CommandError(
|
|
||||||
f"Could not locate Python interpreter {general_options.python}"
|
|
||||||
)
|
|
||||||
|
|
||||||
pip_cmd = [
|
|
||||||
interpreter,
|
|
||||||
get_runnable_pip(),
|
|
||||||
]
|
|
||||||
pip_cmd.extend(args)
|
|
||||||
|
|
||||||
# Set a flag so the child doesn't re-invoke itself, causing
|
|
||||||
# an infinite loop.
|
|
||||||
os.environ["_PIP_RUNNING_IN_SUBPROCESS"] = "1"
|
|
||||||
returncode = 0
|
|
||||||
try:
|
|
||||||
proc = subprocess.run(pip_cmd)
|
|
||||||
returncode = proc.returncode
|
|
||||||
except (subprocess.SubprocessError, OSError) as exc:
|
|
||||||
raise CommandError(f"Failed to run pip under {interpreter}: {exc}")
|
|
||||||
sys.exit(returncode)
|
|
||||||
|
|
||||||
# --version
|
|
||||||
if general_options.version:
|
|
||||||
sys.stdout.write(parser.version)
|
|
||||||
sys.stdout.write(os.linesep)
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# pip || pip help -> print_help()
|
|
||||||
if not args_else or (args_else[0] == "help" and len(args_else) == 1):
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
# the subcommand name
|
|
||||||
cmd_name = args_else[0]
|
|
||||||
|
|
||||||
if cmd_name not in commands_dict:
|
|
||||||
guess = get_similar_commands(cmd_name)
|
|
||||||
|
|
||||||
msg = [f'unknown command "{cmd_name}"']
|
|
||||||
if guess:
|
|
||||||
msg.append(f'maybe you meant "{guess}"')
|
|
||||||
|
|
||||||
raise CommandError(" - ".join(msg))
|
|
||||||
|
|
||||||
# all the args without the subcommand
|
|
||||||
cmd_args = args[:]
|
|
||||||
cmd_args.remove(cmd_name)
|
|
||||||
|
|
||||||
return cmd_name, cmd_args
|
|
@ -1,294 +0,0 @@
|
|||||||
"""Base option parser setup"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import optparse
|
|
||||||
import shutil
|
|
||||||
import sys
|
|
||||||
import textwrap
|
|
||||||
from contextlib import suppress
|
|
||||||
from typing import Any, Dict, Generator, List, Tuple
|
|
||||||
|
|
||||||
from pip._internal.cli.status_codes import UNKNOWN_ERROR
|
|
||||||
from pip._internal.configuration import Configuration, ConfigurationError
|
|
||||||
from pip._internal.utils.misc import redact_auth_from_url, strtobool
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class PrettyHelpFormatter(optparse.IndentedHelpFormatter):
|
|
||||||
"""A prettier/less verbose help formatter for optparse."""
|
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
|
||||||
# help position must be aligned with __init__.parseopts.description
|
|
||||||
kwargs["max_help_position"] = 30
|
|
||||||
kwargs["indent_increment"] = 1
|
|
||||||
kwargs["width"] = shutil.get_terminal_size()[0] - 2
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def format_option_strings(self, option: optparse.Option) -> str:
|
|
||||||
return self._format_option_strings(option)
|
|
||||||
|
|
||||||
def _format_option_strings(
|
|
||||||
self, option: optparse.Option, mvarfmt: str = " <{}>", optsep: str = ", "
|
|
||||||
) -> str:
|
|
||||||
"""
|
|
||||||
Return a comma-separated list of option strings and metavars.
|
|
||||||
|
|
||||||
:param option: tuple of (short opt, long opt), e.g: ('-f', '--format')
|
|
||||||
:param mvarfmt: metavar format string
|
|
||||||
:param optsep: separator
|
|
||||||
"""
|
|
||||||
opts = []
|
|
||||||
|
|
||||||
if option._short_opts:
|
|
||||||
opts.append(option._short_opts[0])
|
|
||||||
if option._long_opts:
|
|
||||||
opts.append(option._long_opts[0])
|
|
||||||
if len(opts) > 1:
|
|
||||||
opts.insert(1, optsep)
|
|
||||||
|
|
||||||
if option.takes_value():
|
|
||||||
assert option.dest is not None
|
|
||||||
metavar = option.metavar or option.dest.lower()
|
|
||||||
opts.append(mvarfmt.format(metavar.lower()))
|
|
||||||
|
|
||||||
return "".join(opts)
|
|
||||||
|
|
||||||
def format_heading(self, heading: str) -> str:
|
|
||||||
if heading == "Options":
|
|
||||||
return ""
|
|
||||||
return heading + ":\n"
|
|
||||||
|
|
||||||
def format_usage(self, usage: str) -> str:
|
|
||||||
"""
|
|
||||||
Ensure there is only one newline between usage and the first heading
|
|
||||||
if there is no description.
|
|
||||||
"""
|
|
||||||
msg = "\nUsage: {}\n".format(self.indent_lines(textwrap.dedent(usage), " "))
|
|
||||||
return msg
|
|
||||||
|
|
||||||
def format_description(self, description: str) -> str:
|
|
||||||
# leave full control over description to us
|
|
||||||
if description:
|
|
||||||
if hasattr(self.parser, "main"):
|
|
||||||
label = "Commands"
|
|
||||||
else:
|
|
||||||
label = "Description"
|
|
||||||
# some doc strings have initial newlines, some don't
|
|
||||||
description = description.lstrip("\n")
|
|
||||||
# some doc strings have final newlines and spaces, some don't
|
|
||||||
description = description.rstrip()
|
|
||||||
# dedent, then reindent
|
|
||||||
description = self.indent_lines(textwrap.dedent(description), " ")
|
|
||||||
description = f"{label}:\n{description}\n"
|
|
||||||
return description
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def format_epilog(self, epilog: str) -> str:
|
|
||||||
# leave full control over epilog to us
|
|
||||||
if epilog:
|
|
||||||
return epilog
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def indent_lines(self, text: str, indent: str) -> str:
|
|
||||||
new_lines = [indent + line for line in text.split("\n")]
|
|
||||||
return "\n".join(new_lines)
|
|
||||||
|
|
||||||
|
|
||||||
class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
|
|
||||||
"""Custom help formatter for use in ConfigOptionParser.
|
|
||||||
|
|
||||||
This is updates the defaults before expanding them, allowing
|
|
||||||
them to show up correctly in the help listing.
|
|
||||||
|
|
||||||
Also redact auth from url type options
|
|
||||||
"""
|
|
||||||
|
|
||||||
def expand_default(self, option: optparse.Option) -> str:
|
|
||||||
default_values = None
|
|
||||||
if self.parser is not None:
|
|
||||||
assert isinstance(self.parser, ConfigOptionParser)
|
|
||||||
self.parser._update_defaults(self.parser.defaults)
|
|
||||||
assert option.dest is not None
|
|
||||||
default_values = self.parser.defaults.get(option.dest)
|
|
||||||
help_text = super().expand_default(option)
|
|
||||||
|
|
||||||
if default_values and option.metavar == "URL":
|
|
||||||
if isinstance(default_values, str):
|
|
||||||
default_values = [default_values]
|
|
||||||
|
|
||||||
# If its not a list, we should abort and just return the help text
|
|
||||||
if not isinstance(default_values, list):
|
|
||||||
default_values = []
|
|
||||||
|
|
||||||
for val in default_values:
|
|
||||||
help_text = help_text.replace(val, redact_auth_from_url(val))
|
|
||||||
|
|
||||||
return help_text
|
|
||||||
|
|
||||||
|
|
||||||
class CustomOptionParser(optparse.OptionParser):
|
|
||||||
def insert_option_group(
|
|
||||||
self, idx: int, *args: Any, **kwargs: Any
|
|
||||||
) -> optparse.OptionGroup:
|
|
||||||
"""Insert an OptionGroup at a given position."""
|
|
||||||
group = self.add_option_group(*args, **kwargs)
|
|
||||||
|
|
||||||
self.option_groups.pop()
|
|
||||||
self.option_groups.insert(idx, group)
|
|
||||||
|
|
||||||
return group
|
|
||||||
|
|
||||||
@property
|
|
||||||
def option_list_all(self) -> List[optparse.Option]:
|
|
||||||
"""Get a list of all options, including those in option groups."""
|
|
||||||
res = self.option_list[:]
|
|
||||||
for i in self.option_groups:
|
|
||||||
res.extend(i.option_list)
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigOptionParser(CustomOptionParser):
|
|
||||||
"""Custom option parser which updates its defaults by checking the
|
|
||||||
configuration files and environmental variables"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
*args: Any,
|
|
||||||
name: str,
|
|
||||||
isolated: bool = False,
|
|
||||||
**kwargs: Any,
|
|
||||||
) -> None:
|
|
||||||
self.name = name
|
|
||||||
self.config = Configuration(isolated)
|
|
||||||
|
|
||||||
assert self.name
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def check_default(self, option: optparse.Option, key: str, val: Any) -> Any:
|
|
||||||
try:
|
|
||||||
return option.check_value(key, val)
|
|
||||||
except optparse.OptionValueError as exc:
|
|
||||||
print(f"An error occurred during configuration: {exc}")
|
|
||||||
sys.exit(3)
|
|
||||||
|
|
||||||
def _get_ordered_configuration_items(
|
|
||||||
self,
|
|
||||||
) -> Generator[Tuple[str, Any], None, None]:
|
|
||||||
# Configuration gives keys in an unordered manner. Order them.
|
|
||||||
override_order = ["global", self.name, ":env:"]
|
|
||||||
|
|
||||||
# Pool the options into different groups
|
|
||||||
section_items: Dict[str, List[Tuple[str, Any]]] = {
|
|
||||||
name: [] for name in override_order
|
|
||||||
}
|
|
||||||
for section_key, val in self.config.items():
|
|
||||||
# ignore empty values
|
|
||||||
if not val:
|
|
||||||
logger.debug(
|
|
||||||
"Ignoring configuration key '%s' as it's value is empty.",
|
|
||||||
section_key,
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
section, key = section_key.split(".", 1)
|
|
||||||
if section in override_order:
|
|
||||||
section_items[section].append((key, val))
|
|
||||||
|
|
||||||
# Yield each group in their override order
|
|
||||||
for section in override_order:
|
|
||||||
for key, val in section_items[section]:
|
|
||||||
yield key, val
|
|
||||||
|
|
||||||
def _update_defaults(self, defaults: Dict[str, Any]) -> Dict[str, Any]:
|
|
||||||
"""Updates the given defaults with values from the config files and
|
|
||||||
the environ. Does a little special handling for certain types of
|
|
||||||
options (lists)."""
|
|
||||||
|
|
||||||
# Accumulate complex default state.
|
|
||||||
self.values = optparse.Values(self.defaults)
|
|
||||||
late_eval = set()
|
|
||||||
# Then set the options with those values
|
|
||||||
for key, val in self._get_ordered_configuration_items():
|
|
||||||
# '--' because configuration supports only long names
|
|
||||||
option = self.get_option("--" + key)
|
|
||||||
|
|
||||||
# Ignore options not present in this parser. E.g. non-globals put
|
|
||||||
# in [global] by users that want them to apply to all applicable
|
|
||||||
# commands.
|
|
||||||
if option is None:
|
|
||||||
continue
|
|
||||||
|
|
||||||
assert option.dest is not None
|
|
||||||
|
|
||||||
if option.action in ("store_true", "store_false"):
|
|
||||||
try:
|
|
||||||
val = strtobool(val)
|
|
||||||
except ValueError:
|
|
||||||
self.error(
|
|
||||||
f"{val} is not a valid value for {key} option, "
|
|
||||||
"please specify a boolean value like yes/no, "
|
|
||||||
"true/false or 1/0 instead."
|
|
||||||
)
|
|
||||||
elif option.action == "count":
|
|
||||||
with suppress(ValueError):
|
|
||||||
val = strtobool(val)
|
|
||||||
with suppress(ValueError):
|
|
||||||
val = int(val)
|
|
||||||
if not isinstance(val, int) or val < 0:
|
|
||||||
self.error(
|
|
||||||
f"{val} is not a valid value for {key} option, "
|
|
||||||
"please instead specify either a non-negative integer "
|
|
||||||
"or a boolean value like yes/no or false/true "
|
|
||||||
"which is equivalent to 1/0."
|
|
||||||
)
|
|
||||||
elif option.action == "append":
|
|
||||||
val = val.split()
|
|
||||||
val = [self.check_default(option, key, v) for v in val]
|
|
||||||
elif option.action == "callback":
|
|
||||||
assert option.callback is not None
|
|
||||||
late_eval.add(option.dest)
|
|
||||||
opt_str = option.get_opt_string()
|
|
||||||
val = option.convert_value(opt_str, val)
|
|
||||||
# From take_action
|
|
||||||
args = option.callback_args or ()
|
|
||||||
kwargs = option.callback_kwargs or {}
|
|
||||||
option.callback(option, opt_str, val, self, *args, **kwargs)
|
|
||||||
else:
|
|
||||||
val = self.check_default(option, key, val)
|
|
||||||
|
|
||||||
defaults[option.dest] = val
|
|
||||||
|
|
||||||
for key in late_eval:
|
|
||||||
defaults[key] = getattr(self.values, key)
|
|
||||||
self.values = None
|
|
||||||
return defaults
|
|
||||||
|
|
||||||
def get_default_values(self) -> optparse.Values:
|
|
||||||
"""Overriding to make updating the defaults after instantiation of
|
|
||||||
the option parser possible, _update_defaults() does the dirty work."""
|
|
||||||
if not self.process_default_values:
|
|
||||||
# Old, pre-Optik 1.5 behaviour.
|
|
||||||
return optparse.Values(self.defaults)
|
|
||||||
|
|
||||||
# Load the configuration, or error out in case of an error
|
|
||||||
try:
|
|
||||||
self.config.load()
|
|
||||||
except ConfigurationError as err:
|
|
||||||
self.exit(UNKNOWN_ERROR, str(err))
|
|
||||||
|
|
||||||
defaults = self._update_defaults(self.defaults.copy()) # ours
|
|
||||||
for option in self._get_all_options():
|
|
||||||
assert option.dest is not None
|
|
||||||
default = defaults.get(option.dest)
|
|
||||||
if isinstance(default, str):
|
|
||||||
opt_str = option.get_opt_string()
|
|
||||||
defaults[option.dest] = option.check_value(opt_str, default)
|
|
||||||
return optparse.Values(defaults)
|
|
||||||
|
|
||||||
def error(self, msg: str) -> None:
|
|
||||||
self.print_usage(sys.stderr)
|
|
||||||
self.exit(UNKNOWN_ERROR, f"{msg}\n")
|
|
@ -1,68 +0,0 @@
|
|||||||
import functools
|
|
||||||
from typing import Callable, Generator, Iterable, Iterator, Optional, Tuple
|
|
||||||
|
|
||||||
from pip._vendor.rich.progress import (
|
|
||||||
BarColumn,
|
|
||||||
DownloadColumn,
|
|
||||||
FileSizeColumn,
|
|
||||||
Progress,
|
|
||||||
ProgressColumn,
|
|
||||||
SpinnerColumn,
|
|
||||||
TextColumn,
|
|
||||||
TimeElapsedColumn,
|
|
||||||
TimeRemainingColumn,
|
|
||||||
TransferSpeedColumn,
|
|
||||||
)
|
|
||||||
|
|
||||||
from pip._internal.utils.logging import get_indentation
|
|
||||||
|
|
||||||
DownloadProgressRenderer = Callable[[Iterable[bytes]], Iterator[bytes]]
|
|
||||||
|
|
||||||
|
|
||||||
def _rich_progress_bar(
|
|
||||||
iterable: Iterable[bytes],
|
|
||||||
*,
|
|
||||||
bar_type: str,
|
|
||||||
size: int,
|
|
||||||
) -> Generator[bytes, None, None]:
|
|
||||||
assert bar_type == "on", "This should only be used in the default mode."
|
|
||||||
|
|
||||||
if not size:
|
|
||||||
total = float("inf")
|
|
||||||
columns: Tuple[ProgressColumn, ...] = (
|
|
||||||
TextColumn("[progress.description]{task.description}"),
|
|
||||||
SpinnerColumn("line", speed=1.5),
|
|
||||||
FileSizeColumn(),
|
|
||||||
TransferSpeedColumn(),
|
|
||||||
TimeElapsedColumn(),
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
total = size
|
|
||||||
columns = (
|
|
||||||
TextColumn("[progress.description]{task.description}"),
|
|
||||||
BarColumn(),
|
|
||||||
DownloadColumn(),
|
|
||||||
TransferSpeedColumn(),
|
|
||||||
TextColumn("eta"),
|
|
||||||
TimeRemainingColumn(),
|
|
||||||
)
|
|
||||||
|
|
||||||
progress = Progress(*columns, refresh_per_second=30)
|
|
||||||
task_id = progress.add_task(" " * (get_indentation() + 2), total=total)
|
|
||||||
with progress:
|
|
||||||
for chunk in iterable:
|
|
||||||
yield chunk
|
|
||||||
progress.update(task_id, advance=len(chunk))
|
|
||||||
|
|
||||||
|
|
||||||
def get_download_progress_renderer(
|
|
||||||
*, bar_type: str, size: Optional[int] = None
|
|
||||||
) -> DownloadProgressRenderer:
|
|
||||||
"""Get an object that can be used to render the download progress.
|
|
||||||
|
|
||||||
Returns a callable, that takes an iterable to "wrap".
|
|
||||||
"""
|
|
||||||
if bar_type == "on":
|
|
||||||
return functools.partial(_rich_progress_bar, bar_type=bar_type, size=size)
|
|
||||||
else:
|
|
||||||
return iter # no-op, when passed an iterator
|
|
@ -1,505 +0,0 @@
|
|||||||
"""Contains the Command base classes that depend on PipSession.
|
|
||||||
|
|
||||||
The classes in this module are in a separate module so the commands not
|
|
||||||
needing download / PackageFinder capability don't unnecessarily import the
|
|
||||||
PackageFinder machinery and all its vendored dependencies, etc.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
from functools import partial
|
|
||||||
from optparse import Values
|
|
||||||
from typing import TYPE_CHECKING, Any, List, Optional, Tuple
|
|
||||||
|
|
||||||
from pip._internal.cache import WheelCache
|
|
||||||
from pip._internal.cli import cmdoptions
|
|
||||||
from pip._internal.cli.base_command import Command
|
|
||||||
from pip._internal.cli.command_context import CommandContextMixIn
|
|
||||||
from pip._internal.exceptions import CommandError, PreviousBuildDirError
|
|
||||||
from pip._internal.index.collector import LinkCollector
|
|
||||||
from pip._internal.index.package_finder import PackageFinder
|
|
||||||
from pip._internal.models.selection_prefs import SelectionPreferences
|
|
||||||
from pip._internal.models.target_python import TargetPython
|
|
||||||
from pip._internal.network.session import PipSession
|
|
||||||
from pip._internal.operations.build.build_tracker import BuildTracker
|
|
||||||
from pip._internal.operations.prepare import RequirementPreparer
|
|
||||||
from pip._internal.req.constructors import (
|
|
||||||
install_req_from_editable,
|
|
||||||
install_req_from_line,
|
|
||||||
install_req_from_parsed_requirement,
|
|
||||||
install_req_from_req_string,
|
|
||||||
)
|
|
||||||
from pip._internal.req.req_file import parse_requirements
|
|
||||||
from pip._internal.req.req_install import InstallRequirement
|
|
||||||
from pip._internal.resolution.base import BaseResolver
|
|
||||||
from pip._internal.self_outdated_check import pip_self_version_check
|
|
||||||
from pip._internal.utils.temp_dir import (
|
|
||||||
TempDirectory,
|
|
||||||
TempDirectoryTypeRegistry,
|
|
||||||
tempdir_kinds,
|
|
||||||
)
|
|
||||||
from pip._internal.utils.virtualenv import running_under_virtualenv
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from ssl import SSLContext
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _create_truststore_ssl_context() -> Optional["SSLContext"]:
|
|
||||||
if sys.version_info < (3, 10):
|
|
||||||
raise CommandError("The truststore feature is only available for Python 3.10+")
|
|
||||||
|
|
||||||
try:
|
|
||||||
import ssl
|
|
||||||
except ImportError:
|
|
||||||
logger.warning("Disabling truststore since ssl support is missing")
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
from pip._vendor import truststore
|
|
||||||
except ImportError as e:
|
|
||||||
raise CommandError(f"The truststore feature is unavailable: {e}")
|
|
||||||
|
|
||||||
return truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
||||||
|
|
||||||
|
|
||||||
class SessionCommandMixin(CommandContextMixIn):
|
|
||||||
|
|
||||||
"""
|
|
||||||
A class mixin for command classes needing _build_session().
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self) -> None:
|
|
||||||
super().__init__()
|
|
||||||
self._session: Optional[PipSession] = None
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _get_index_urls(cls, options: Values) -> Optional[List[str]]:
|
|
||||||
"""Return a list of index urls from user-provided options."""
|
|
||||||
index_urls = []
|
|
||||||
if not getattr(options, "no_index", False):
|
|
||||||
url = getattr(options, "index_url", None)
|
|
||||||
if url:
|
|
||||||
index_urls.append(url)
|
|
||||||
urls = getattr(options, "extra_index_urls", None)
|
|
||||||
if urls:
|
|
||||||
index_urls.extend(urls)
|
|
||||||
# Return None rather than an empty list
|
|
||||||
return index_urls or None
|
|
||||||
|
|
||||||
def get_default_session(self, options: Values) -> PipSession:
|
|
||||||
"""Get a default-managed session."""
|
|
||||||
if self._session is None:
|
|
||||||
self._session = self.enter_context(self._build_session(options))
|
|
||||||
# there's no type annotation on requests.Session, so it's
|
|
||||||
# automatically ContextManager[Any] and self._session becomes Any,
|
|
||||||
# then https://github.com/python/mypy/issues/7696 kicks in
|
|
||||||
assert self._session is not None
|
|
||||||
return self._session
|
|
||||||
|
|
||||||
def _build_session(
|
|
||||||
self,
|
|
||||||
options: Values,
|
|
||||||
retries: Optional[int] = None,
|
|
||||||
timeout: Optional[int] = None,
|
|
||||||
fallback_to_certifi: bool = False,
|
|
||||||
) -> PipSession:
|
|
||||||
cache_dir = options.cache_dir
|
|
||||||
assert not cache_dir or os.path.isabs(cache_dir)
|
|
||||||
|
|
||||||
if "truststore" in options.features_enabled:
|
|
||||||
try:
|
|
||||||
ssl_context = _create_truststore_ssl_context()
|
|
||||||
except Exception:
|
|
||||||
if not fallback_to_certifi:
|
|
||||||
raise
|
|
||||||
ssl_context = None
|
|
||||||
else:
|
|
||||||
ssl_context = None
|
|
||||||
|
|
||||||
session = PipSession(
|
|
||||||
cache=os.path.join(cache_dir, "http-v2") if cache_dir else None,
|
|
||||||
retries=retries if retries is not None else options.retries,
|
|
||||||
trusted_hosts=options.trusted_hosts,
|
|
||||||
index_urls=self._get_index_urls(options),
|
|
||||||
ssl_context=ssl_context,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Handle custom ca-bundles from the user
|
|
||||||
if options.cert:
|
|
||||||
session.verify = options.cert
|
|
||||||
|
|
||||||
# Handle SSL client certificate
|
|
||||||
if options.client_cert:
|
|
||||||
session.cert = options.client_cert
|
|
||||||
|
|
||||||
# Handle timeouts
|
|
||||||
if options.timeout or timeout:
|
|
||||||
session.timeout = timeout if timeout is not None else options.timeout
|
|
||||||
|
|
||||||
# Handle configured proxies
|
|
||||||
if options.proxy:
|
|
||||||
session.proxies = {
|
|
||||||
"http": options.proxy,
|
|
||||||
"https": options.proxy,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Determine if we can prompt the user for authentication or not
|
|
||||||
session.auth.prompting = not options.no_input
|
|
||||||
session.auth.keyring_provider = options.keyring_provider
|
|
||||||
|
|
||||||
return session
|
|
||||||
|
|
||||||
|
|
||||||
class IndexGroupCommand(Command, SessionCommandMixin):
|
|
||||||
|
|
||||||
"""
|
|
||||||
Abstract base class for commands with the index_group options.
|
|
||||||
|
|
||||||
This also corresponds to the commands that permit the pip version check.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def handle_pip_version_check(self, options: Values) -> None:
|
|
||||||
"""
|
|
||||||
Do the pip version check if not disabled.
|
|
||||||
|
|
||||||
This overrides the default behavior of not doing the check.
|
|
||||||
"""
|
|
||||||
# Make sure the index_group options are present.
|
|
||||||
assert hasattr(options, "no_index")
|
|
||||||
|
|
||||||
if options.disable_pip_version_check or options.no_index:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Otherwise, check if we're using the latest version of pip available.
|
|
||||||
session = self._build_session(
|
|
||||||
options,
|
|
||||||
retries=0,
|
|
||||||
timeout=min(5, options.timeout),
|
|
||||||
# This is set to ensure the function does not fail when truststore is
|
|
||||||
# specified in use-feature but cannot be loaded. This usually raises a
|
|
||||||
# CommandError and shows a nice user-facing error, but this function is not
|
|
||||||
# called in that try-except block.
|
|
||||||
fallback_to_certifi=True,
|
|
||||||
)
|
|
||||||
with session:
|
|
||||||
pip_self_version_check(session, options)
|
|
||||||
|
|
||||||
|
|
||||||
KEEPABLE_TEMPDIR_TYPES = [
|
|
||||||
tempdir_kinds.BUILD_ENV,
|
|
||||||
tempdir_kinds.EPHEM_WHEEL_CACHE,
|
|
||||||
tempdir_kinds.REQ_BUILD,
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def warn_if_run_as_root() -> None:
|
|
||||||
"""Output a warning for sudo users on Unix.
|
|
||||||
|
|
||||||
In a virtual environment, sudo pip still writes to virtualenv.
|
|
||||||
On Windows, users may run pip as Administrator without issues.
|
|
||||||
This warning only applies to Unix root users outside of virtualenv.
|
|
||||||
"""
|
|
||||||
if running_under_virtualenv():
|
|
||||||
return
|
|
||||||
if not hasattr(os, "getuid"):
|
|
||||||
return
|
|
||||||
# On Windows, there are no "system managed" Python packages. Installing as
|
|
||||||
# Administrator via pip is the correct way of updating system environments.
|
|
||||||
#
|
|
||||||
# We choose sys.platform over utils.compat.WINDOWS here to enable Mypy platform
|
|
||||||
# checks: https://mypy.readthedocs.io/en/stable/common_issues.html
|
|
||||||
if sys.platform == "win32" or sys.platform == "cygwin":
|
|
||||||
return
|
|
||||||
|
|
||||||
if os.getuid() != 0:
|
|
||||||
return
|
|
||||||
|
|
||||||
logger.warning(
|
|
||||||
"Running pip as the 'root' user can result in broken permissions and "
|
|
||||||
"conflicting behaviour with the system package manager. "
|
|
||||||
"It is recommended to use a virtual environment instead: "
|
|
||||||
"https://pip.pypa.io/warnings/venv"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def with_cleanup(func: Any) -> Any:
|
|
||||||
"""Decorator for common logic related to managing temporary
|
|
||||||
directories.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None:
|
|
||||||
for t in KEEPABLE_TEMPDIR_TYPES:
|
|
||||||
registry.set_delete(t, False)
|
|
||||||
|
|
||||||
def wrapper(
|
|
||||||
self: RequirementCommand, options: Values, args: List[Any]
|
|
||||||
) -> Optional[int]:
|
|
||||||
assert self.tempdir_registry is not None
|
|
||||||
if options.no_clean:
|
|
||||||
configure_tempdir_registry(self.tempdir_registry)
|
|
||||||
|
|
||||||
try:
|
|
||||||
return func(self, options, args)
|
|
||||||
except PreviousBuildDirError:
|
|
||||||
# This kind of conflict can occur when the user passes an explicit
|
|
||||||
# build directory with a pre-existing folder. In that case we do
|
|
||||||
# not want to accidentally remove it.
|
|
||||||
configure_tempdir_registry(self.tempdir_registry)
|
|
||||||
raise
|
|
||||||
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
class RequirementCommand(IndexGroupCommand):
|
|
||||||
def __init__(self, *args: Any, **kw: Any) -> None:
|
|
||||||
super().__init__(*args, **kw)
|
|
||||||
|
|
||||||
self.cmd_opts.add_option(cmdoptions.no_clean())
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def determine_resolver_variant(options: Values) -> str:
|
|
||||||
"""Determines which resolver should be used, based on the given options."""
|
|
||||||
if "legacy-resolver" in options.deprecated_features_enabled:
|
|
||||||
return "legacy"
|
|
||||||
|
|
||||||
return "resolvelib"
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def make_requirement_preparer(
|
|
||||||
cls,
|
|
||||||
temp_build_dir: TempDirectory,
|
|
||||||
options: Values,
|
|
||||||
build_tracker: BuildTracker,
|
|
||||||
session: PipSession,
|
|
||||||
finder: PackageFinder,
|
|
||||||
use_user_site: bool,
|
|
||||||
download_dir: Optional[str] = None,
|
|
||||||
verbosity: int = 0,
|
|
||||||
) -> RequirementPreparer:
|
|
||||||
"""
|
|
||||||
Create a RequirementPreparer instance for the given parameters.
|
|
||||||
"""
|
|
||||||
temp_build_dir_path = temp_build_dir.path
|
|
||||||
assert temp_build_dir_path is not None
|
|
||||||
legacy_resolver = False
|
|
||||||
|
|
||||||
resolver_variant = cls.determine_resolver_variant(options)
|
|
||||||
if resolver_variant == "resolvelib":
|
|
||||||
lazy_wheel = "fast-deps" in options.features_enabled
|
|
||||||
if lazy_wheel:
|
|
||||||
logger.warning(
|
|
||||||
"pip is using lazily downloaded wheels using HTTP "
|
|
||||||
"range requests to obtain dependency information. "
|
|
||||||
"This experimental feature is enabled through "
|
|
||||||
"--use-feature=fast-deps and it is not ready for "
|
|
||||||
"production."
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
legacy_resolver = True
|
|
||||||
lazy_wheel = False
|
|
||||||
if "fast-deps" in options.features_enabled:
|
|
||||||
logger.warning(
|
|
||||||
"fast-deps has no effect when used with the legacy resolver."
|
|
||||||
)
|
|
||||||
|
|
||||||
return RequirementPreparer(
|
|
||||||
build_dir=temp_build_dir_path,
|
|
||||||
src_dir=options.src_dir,
|
|
||||||
download_dir=download_dir,
|
|
||||||
build_isolation=options.build_isolation,
|
|
||||||
check_build_deps=options.check_build_deps,
|
|
||||||
build_tracker=build_tracker,
|
|
||||||
session=session,
|
|
||||||
progress_bar=options.progress_bar,
|
|
||||||
finder=finder,
|
|
||||||
require_hashes=options.require_hashes,
|
|
||||||
use_user_site=use_user_site,
|
|
||||||
lazy_wheel=lazy_wheel,
|
|
||||||
verbosity=verbosity,
|
|
||||||
legacy_resolver=legacy_resolver,
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def make_resolver(
|
|
||||||
cls,
|
|
||||||
preparer: RequirementPreparer,
|
|
||||||
finder: PackageFinder,
|
|
||||||
options: Values,
|
|
||||||
wheel_cache: Optional[WheelCache] = None,
|
|
||||||
use_user_site: bool = False,
|
|
||||||
ignore_installed: bool = True,
|
|
||||||
ignore_requires_python: bool = False,
|
|
||||||
force_reinstall: bool = False,
|
|
||||||
upgrade_strategy: str = "to-satisfy-only",
|
|
||||||
use_pep517: Optional[bool] = None,
|
|
||||||
py_version_info: Optional[Tuple[int, ...]] = None,
|
|
||||||
) -> BaseResolver:
|
|
||||||
"""
|
|
||||||
Create a Resolver instance for the given parameters.
|
|
||||||
"""
|
|
||||||
make_install_req = partial(
|
|
||||||
install_req_from_req_string,
|
|
||||||
isolated=options.isolated_mode,
|
|
||||||
use_pep517=use_pep517,
|
|
||||||
)
|
|
||||||
resolver_variant = cls.determine_resolver_variant(options)
|
|
||||||
# The long import name and duplicated invocation is needed to convince
|
|
||||||
# Mypy into correctly typechecking. Otherwise it would complain the
|
|
||||||
# "Resolver" class being redefined.
|
|
||||||
if resolver_variant == "resolvelib":
|
|
||||||
import pip._internal.resolution.resolvelib.resolver
|
|
||||||
|
|
||||||
return pip._internal.resolution.resolvelib.resolver.Resolver(
|
|
||||||
preparer=preparer,
|
|
||||||
finder=finder,
|
|
||||||
wheel_cache=wheel_cache,
|
|
||||||
make_install_req=make_install_req,
|
|
||||||
use_user_site=use_user_site,
|
|
||||||
ignore_dependencies=options.ignore_dependencies,
|
|
||||||
ignore_installed=ignore_installed,
|
|
||||||
ignore_requires_python=ignore_requires_python,
|
|
||||||
force_reinstall=force_reinstall,
|
|
||||||
upgrade_strategy=upgrade_strategy,
|
|
||||||
py_version_info=py_version_info,
|
|
||||||
)
|
|
||||||
import pip._internal.resolution.legacy.resolver
|
|
||||||
|
|
||||||
return pip._internal.resolution.legacy.resolver.Resolver(
|
|
||||||
preparer=preparer,
|
|
||||||
finder=finder,
|
|
||||||
wheel_cache=wheel_cache,
|
|
||||||
make_install_req=make_install_req,
|
|
||||||
use_user_site=use_user_site,
|
|
||||||
ignore_dependencies=options.ignore_dependencies,
|
|
||||||
ignore_installed=ignore_installed,
|
|
||||||
ignore_requires_python=ignore_requires_python,
|
|
||||||
force_reinstall=force_reinstall,
|
|
||||||
upgrade_strategy=upgrade_strategy,
|
|
||||||
py_version_info=py_version_info,
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_requirements(
|
|
||||||
self,
|
|
||||||
args: List[str],
|
|
||||||
options: Values,
|
|
||||||
finder: PackageFinder,
|
|
||||||
session: PipSession,
|
|
||||||
) -> List[InstallRequirement]:
|
|
||||||
"""
|
|
||||||
Parse command-line arguments into the corresponding requirements.
|
|
||||||
"""
|
|
||||||
requirements: List[InstallRequirement] = []
|
|
||||||
for filename in options.constraints:
|
|
||||||
for parsed_req in parse_requirements(
|
|
||||||
filename,
|
|
||||||
constraint=True,
|
|
||||||
finder=finder,
|
|
||||||
options=options,
|
|
||||||
session=session,
|
|
||||||
):
|
|
||||||
req_to_add = install_req_from_parsed_requirement(
|
|
||||||
parsed_req,
|
|
||||||
isolated=options.isolated_mode,
|
|
||||||
user_supplied=False,
|
|
||||||
)
|
|
||||||
requirements.append(req_to_add)
|
|
||||||
|
|
||||||
for req in args:
|
|
||||||
req_to_add = install_req_from_line(
|
|
||||||
req,
|
|
||||||
comes_from=None,
|
|
||||||
isolated=options.isolated_mode,
|
|
||||||
use_pep517=options.use_pep517,
|
|
||||||
user_supplied=True,
|
|
||||||
config_settings=getattr(options, "config_settings", None),
|
|
||||||
)
|
|
||||||
requirements.append(req_to_add)
|
|
||||||
|
|
||||||
for req in options.editables:
|
|
||||||
req_to_add = install_req_from_editable(
|
|
||||||
req,
|
|
||||||
user_supplied=True,
|
|
||||||
isolated=options.isolated_mode,
|
|
||||||
use_pep517=options.use_pep517,
|
|
||||||
config_settings=getattr(options, "config_settings", None),
|
|
||||||
)
|
|
||||||
requirements.append(req_to_add)
|
|
||||||
|
|
||||||
# NOTE: options.require_hashes may be set if --require-hashes is True
|
|
||||||
for filename in options.requirements:
|
|
||||||
for parsed_req in parse_requirements(
|
|
||||||
filename, finder=finder, options=options, session=session
|
|
||||||
):
|
|
||||||
req_to_add = install_req_from_parsed_requirement(
|
|
||||||
parsed_req,
|
|
||||||
isolated=options.isolated_mode,
|
|
||||||
use_pep517=options.use_pep517,
|
|
||||||
user_supplied=True,
|
|
||||||
config_settings=parsed_req.options.get("config_settings")
|
|
||||||
if parsed_req.options
|
|
||||||
else None,
|
|
||||||
)
|
|
||||||
requirements.append(req_to_add)
|
|
||||||
|
|
||||||
# If any requirement has hash options, enable hash checking.
|
|
||||||
if any(req.has_hash_options for req in requirements):
|
|
||||||
options.require_hashes = True
|
|
||||||
|
|
||||||
if not (args or options.editables or options.requirements):
|
|
||||||
opts = {"name": self.name}
|
|
||||||
if options.find_links:
|
|
||||||
raise CommandError(
|
|
||||||
"You must give at least one requirement to {name} "
|
|
||||||
'(maybe you meant "pip {name} {links}"?)'.format(
|
|
||||||
**dict(opts, links=" ".join(options.find_links))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
raise CommandError(
|
|
||||||
"You must give at least one requirement to {name} "
|
|
||||||
'(see "pip help {name}")'.format(**opts)
|
|
||||||
)
|
|
||||||
|
|
||||||
return requirements
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def trace_basic_info(finder: PackageFinder) -> None:
|
|
||||||
"""
|
|
||||||
Trace basic information about the provided objects.
|
|
||||||
"""
|
|
||||||
# Display where finder is looking for packages
|
|
||||||
search_scope = finder.search_scope
|
|
||||||
locations = search_scope.get_formatted_locations()
|
|
||||||
if locations:
|
|
||||||
logger.info(locations)
|
|
||||||
|
|
||||||
def _build_package_finder(
|
|
||||||
self,
|
|
||||||
options: Values,
|
|
||||||
session: PipSession,
|
|
||||||
target_python: Optional[TargetPython] = None,
|
|
||||||
ignore_requires_python: Optional[bool] = None,
|
|
||||||
) -> PackageFinder:
|
|
||||||
"""
|
|
||||||
Create a package finder appropriate to this requirement command.
|
|
||||||
|
|
||||||
:param ignore_requires_python: Whether to ignore incompatible
|
|
||||||
"Requires-Python" values in links. Defaults to False.
|
|
||||||
"""
|
|
||||||
link_collector = LinkCollector.create(session, options=options)
|
|
||||||
selection_prefs = SelectionPreferences(
|
|
||||||
allow_yanked=True,
|
|
||||||
format_control=options.format_control,
|
|
||||||
allow_all_prereleases=options.pre,
|
|
||||||
prefer_binary=options.prefer_binary,
|
|
||||||
ignore_requires_python=ignore_requires_python,
|
|
||||||
)
|
|
||||||
|
|
||||||
return PackageFinder.create(
|
|
||||||
link_collector=link_collector,
|
|
||||||
selection_prefs=selection_prefs,
|
|
||||||
target_python=target_python,
|
|
||||||
)
|
|
@ -1,159 +0,0 @@
|
|||||||
import contextlib
|
|
||||||
import itertools
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from typing import IO, Generator, Optional
|
|
||||||
|
|
||||||
from pip._internal.utils.compat import WINDOWS
|
|
||||||
from pip._internal.utils.logging import get_indentation
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class SpinnerInterface:
|
|
||||||
def spin(self) -> None:
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def finish(self, final_status: str) -> None:
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
|
||||||
class InteractiveSpinner(SpinnerInterface):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
message: str,
|
|
||||||
file: Optional[IO[str]] = None,
|
|
||||||
spin_chars: str = "-\\|/",
|
|
||||||
# Empirically, 8 updates/second looks nice
|
|
||||||
min_update_interval_seconds: float = 0.125,
|
|
||||||
):
|
|
||||||
self._message = message
|
|
||||||
if file is None:
|
|
||||||
file = sys.stdout
|
|
||||||
self._file = file
|
|
||||||
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
|
||||||
self._finished = False
|
|
||||||
|
|
||||||
self._spin_cycle = itertools.cycle(spin_chars)
|
|
||||||
|
|
||||||
self._file.write(" " * get_indentation() + self._message + " ... ")
|
|
||||||
self._width = 0
|
|
||||||
|
|
||||||
def _write(self, status: str) -> None:
|
|
||||||
assert not self._finished
|
|
||||||
# Erase what we wrote before by backspacing to the beginning, writing
|
|
||||||
# spaces to overwrite the old text, and then backspacing again
|
|
||||||
backup = "\b" * self._width
|
|
||||||
self._file.write(backup + " " * self._width + backup)
|
|
||||||
# Now we have a blank slate to add our status
|
|
||||||
self._file.write(status)
|
|
||||||
self._width = len(status)
|
|
||||||
self._file.flush()
|
|
||||||
self._rate_limiter.reset()
|
|
||||||
|
|
||||||
def spin(self) -> None:
|
|
||||||
if self._finished:
|
|
||||||
return
|
|
||||||
if not self._rate_limiter.ready():
|
|
||||||
return
|
|
||||||
self._write(next(self._spin_cycle))
|
|
||||||
|
|
||||||
def finish(self, final_status: str) -> None:
|
|
||||||
if self._finished:
|
|
||||||
return
|
|
||||||
self._write(final_status)
|
|
||||||
self._file.write("\n")
|
|
||||||
self._file.flush()
|
|
||||||
self._finished = True
|
|
||||||
|
|
||||||
|
|
||||||
# Used for dumb terminals, non-interactive installs (no tty), etc.
|
|
||||||
# We still print updates occasionally (once every 60 seconds by default) to
|
|
||||||
# act as a keep-alive for systems like Travis-CI that take lack-of-output as
|
|
||||||
# an indication that a task has frozen.
|
|
||||||
class NonInteractiveSpinner(SpinnerInterface):
|
|
||||||
def __init__(self, message: str, min_update_interval_seconds: float = 60.0) -> None:
|
|
||||||
self._message = message
|
|
||||||
self._finished = False
|
|
||||||
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
|
||||||
self._update("started")
|
|
||||||
|
|
||||||
def _update(self, status: str) -> None:
|
|
||||||
assert not self._finished
|
|
||||||
self._rate_limiter.reset()
|
|
||||||
logger.info("%s: %s", self._message, status)
|
|
||||||
|
|
||||||
def spin(self) -> None:
|
|
||||||
if self._finished:
|
|
||||||
return
|
|
||||||
if not self._rate_limiter.ready():
|
|
||||||
return
|
|
||||||
self._update("still running...")
|
|
||||||
|
|
||||||
def finish(self, final_status: str) -> None:
|
|
||||||
if self._finished:
|
|
||||||
return
|
|
||||||
self._update(f"finished with status '{final_status}'")
|
|
||||||
self._finished = True
|
|
||||||
|
|
||||||
|
|
||||||
class RateLimiter:
|
|
||||||
def __init__(self, min_update_interval_seconds: float) -> None:
|
|
||||||
self._min_update_interval_seconds = min_update_interval_seconds
|
|
||||||
self._last_update: float = 0
|
|
||||||
|
|
||||||
def ready(self) -> bool:
|
|
||||||
now = time.time()
|
|
||||||
delta = now - self._last_update
|
|
||||||
return delta >= self._min_update_interval_seconds
|
|
||||||
|
|
||||||
def reset(self) -> None:
|
|
||||||
self._last_update = time.time()
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def open_spinner(message: str) -> Generator[SpinnerInterface, None, None]:
|
|
||||||
# Interactive spinner goes directly to sys.stdout rather than being routed
|
|
||||||
# through the logging system, but it acts like it has level INFO,
|
|
||||||
# i.e. it's only displayed if we're at level INFO or better.
|
|
||||||
# Non-interactive spinner goes through the logging system, so it is always
|
|
||||||
# in sync with logging configuration.
|
|
||||||
if sys.stdout.isatty() and logger.getEffectiveLevel() <= logging.INFO:
|
|
||||||
spinner: SpinnerInterface = InteractiveSpinner(message)
|
|
||||||
else:
|
|
||||||
spinner = NonInteractiveSpinner(message)
|
|
||||||
try:
|
|
||||||
with hidden_cursor(sys.stdout):
|
|
||||||
yield spinner
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
spinner.finish("canceled")
|
|
||||||
raise
|
|
||||||
except Exception:
|
|
||||||
spinner.finish("error")
|
|
||||||
raise
|
|
||||||
else:
|
|
||||||
spinner.finish("done")
|
|
||||||
|
|
||||||
|
|
||||||
HIDE_CURSOR = "\x1b[?25l"
|
|
||||||
SHOW_CURSOR = "\x1b[?25h"
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def hidden_cursor(file: IO[str]) -> Generator[None, None, None]:
|
|
||||||
# The Windows terminal does not support the hide/show cursor ANSI codes,
|
|
||||||
# even via colorama. So don't even try.
|
|
||||||
if WINDOWS:
|
|
||||||
yield
|
|
||||||
# We don't want to clutter the output with control characters if we're
|
|
||||||
# writing to a file, or if the user is running with --quiet.
|
|
||||||
# See https://github.com/pypa/pip/issues/3418
|
|
||||||
elif not file.isatty() or logger.getEffectiveLevel() > logging.INFO:
|
|
||||||
yield
|
|
||||||
else:
|
|
||||||
file.write(HIDE_CURSOR)
|
|
||||||
try:
|
|
||||||
yield
|
|
||||||
finally:
|
|
||||||
file.write(SHOW_CURSOR)
|
|
@ -1,6 +0,0 @@
|
|||||||
SUCCESS = 0
|
|
||||||
ERROR = 1
|
|
||||||
UNKNOWN_ERROR = 2
|
|
||||||
VIRTUALENV_NOT_FOUND = 3
|
|
||||||
PREVIOUS_BUILD_DIR_ERROR = 4
|
|
||||||
NO_MATCHES_FOUND = 23
|
|
@ -1,132 +0,0 @@
|
|||||||
"""
|
|
||||||
Package containing all pip commands
|
|
||||||
"""
|
|
||||||
|
|
||||||
import importlib
|
|
||||||
from collections import namedtuple
|
|
||||||
from typing import Any, Dict, Optional
|
|
||||||
|
|
||||||
from pip._internal.cli.base_command import Command
|
|
||||||
|
|
||||||
CommandInfo = namedtuple("CommandInfo", "module_path, class_name, summary")
|
|
||||||
|
|
||||||
# This dictionary does a bunch of heavy lifting for help output:
|
|
||||||
# - Enables avoiding additional (costly) imports for presenting `--help`.
|
|
||||||
# - The ordering matters for help display.
|
|
||||||
#
|
|
||||||
# Even though the module path starts with the same "pip._internal.commands"
|
|
||||||
# prefix, the full path makes testing easier (specifically when modifying
|
|
||||||
# `commands_dict` in test setup / teardown).
|
|
||||||
commands_dict: Dict[str, CommandInfo] = {
|
|
||||||
"install": CommandInfo(
|
|
||||||
"pip._internal.commands.install",
|
|
||||||
"InstallCommand",
|
|
||||||
"Install packages.",
|
|
||||||
),
|
|
||||||
"download": CommandInfo(
|
|
||||||
"pip._internal.commands.download",
|
|
||||||
"DownloadCommand",
|
|
||||||
"Download packages.",
|
|
||||||
),
|
|
||||||
"uninstall": CommandInfo(
|
|
||||||
"pip._internal.commands.uninstall",
|
|
||||||
"UninstallCommand",
|
|
||||||
"Uninstall packages.",
|
|
||||||
),
|
|
||||||
"freeze": CommandInfo(
|
|
||||||
"pip._internal.commands.freeze",
|
|
||||||
"FreezeCommand",
|
|
||||||
"Output installed packages in requirements format.",
|
|
||||||
),
|
|
||||||
"inspect": CommandInfo(
|
|
||||||
"pip._internal.commands.inspect",
|
|
||||||
"InspectCommand",
|
|
||||||
"Inspect the python environment.",
|
|
||||||
),
|
|
||||||
"list": CommandInfo(
|
|
||||||
"pip._internal.commands.list",
|
|
||||||
"ListCommand",
|
|
||||||
"List installed packages.",
|
|
||||||
),
|
|
||||||
"show": CommandInfo(
|
|
||||||
"pip._internal.commands.show",
|
|
||||||
"ShowCommand",
|
|
||||||
"Show information about installed packages.",
|
|
||||||
),
|
|
||||||
"check": CommandInfo(
|
|
||||||
"pip._internal.commands.check",
|
|
||||||
"CheckCommand",
|
|
||||||
"Verify installed packages have compatible dependencies.",
|
|
||||||
),
|
|
||||||
"config": CommandInfo(
|
|
||||||
"pip._internal.commands.configuration",
|
|
||||||
"ConfigurationCommand",
|
|
||||||
"Manage local and global configuration.",
|
|
||||||
),
|
|
||||||
"search": CommandInfo(
|
|
||||||
"pip._internal.commands.search",
|
|
||||||
"SearchCommand",
|
|
||||||
"Search PyPI for packages.",
|
|
||||||
),
|
|
||||||
"cache": CommandInfo(
|
|
||||||
"pip._internal.commands.cache",
|
|
||||||
"CacheCommand",
|
|
||||||
"Inspect and manage pip's wheel cache.",
|
|
||||||
),
|
|
||||||
"index": CommandInfo(
|
|
||||||
"pip._internal.commands.index",
|
|
||||||
"IndexCommand",
|
|
||||||
"Inspect information available from package indexes.",
|
|
||||||
),
|
|
||||||
"wheel": CommandInfo(
|
|
||||||
"pip._internal.commands.wheel",
|
|
||||||
"WheelCommand",
|
|
||||||
"Build wheels from your requirements.",
|
|
||||||
),
|
|
||||||
"hash": CommandInfo(
|
|
||||||
"pip._internal.commands.hash",
|
|
||||||
"HashCommand",
|
|
||||||
"Compute hashes of package archives.",
|
|
||||||
),
|
|
||||||
"completion": CommandInfo(
|
|
||||||
"pip._internal.commands.completion",
|
|
||||||
"CompletionCommand",
|
|
||||||
"A helper command used for command completion.",
|
|
||||||
),
|
|
||||||
"debug": CommandInfo(
|
|
||||||
"pip._internal.commands.debug",
|
|
||||||
"DebugCommand",
|
|
||||||
"Show information useful for debugging.",
|
|
||||||
),
|
|
||||||
"help": CommandInfo(
|
|
||||||
"pip._internal.commands.help",
|
|
||||||
"HelpCommand",
|
|
||||||
"Show help for commands.",
|
|
||||||
),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def create_command(name: str, **kwargs: Any) -> Command:
|
|
||||||
"""
|
|
||||||
Create an instance of the Command class with the given name.
|
|
||||||
"""
|
|
||||||
module_path, class_name, summary = commands_dict[name]
|
|
||||||
module = importlib.import_module(module_path)
|
|
||||||
command_class = getattr(module, class_name)
|
|
||||||
command = command_class(name=name, summary=summary, **kwargs)
|
|
||||||
|
|
||||||
return command
|
|
||||||
|
|
||||||
|
|
||||||
def get_similar_commands(name: str) -> Optional[str]:
|
|
||||||
"""Command name auto-correct."""
|
|
||||||
from difflib import get_close_matches
|
|
||||||
|
|
||||||
name = name.lower()
|
|
||||||
|
|
||||||
close_commands = get_close_matches(name, commands_dict.keys())
|
|
||||||
|
|
||||||
if close_commands:
|
|
||||||
return close_commands[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,225 +0,0 @@
|
|||||||
import os
|
|
||||||
import textwrap
|
|
||||||
from optparse import Values
|
|
||||||
from typing import Any, List
|
|
||||||
|
|
||||||
from pip._internal.cli.base_command import Command
|
|
||||||
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
|
||||||
from pip._internal.exceptions import CommandError, PipError
|
|
||||||
from pip._internal.utils import filesystem
|
|
||||||
from pip._internal.utils.logging import getLogger
|
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class CacheCommand(Command):
|
|
||||||
"""
|
|
||||||
Inspect and manage pip's wheel cache.
|
|
||||||
|
|
||||||
Subcommands:
|
|
||||||
|
|
||||||
- dir: Show the cache directory.
|
|
||||||
- info: Show information about the cache.
|
|
||||||
- list: List filenames of packages stored in the cache.
|
|
||||||
- remove: Remove one or more package from the cache.
|
|
||||||
- purge: Remove all items from the cache.
|
|
||||||
|
|
||||||
``<pattern>`` can be a glob expression or a package name.
|
|
||||||
"""
|
|
||||||
|
|
||||||
ignore_require_venv = True
|
|
||||||
usage = """
|
|
||||||
%prog dir
|
|
||||||
%prog info
|
|
||||||
%prog list [<pattern>] [--format=[human, abspath]]
|
|
||||||
%prog remove <pattern>
|
|
||||||
%prog purge
|
|
||||||
"""
|
|
||||||
|
|
||||||
def add_options(self) -> None:
|
|
||||||
self.cmd_opts.add_option(
|
|
||||||
"--format",
|
|
||||||
action="store",
|
|
||||||
dest="list_format",
|
|
||||||
default="human",
|
|
||||||
choices=("human", "abspath"),
|
|
||||||
help="Select the output format among: human (default) or abspath",
|
|
||||||
)
|
|
||||||
|
|
||||||
self.parser.insert_option_group(0, self.cmd_opts)
|
|
||||||
|
|
||||||
def run(self, options: Values, args: List[str]) -> int:
|
|
||||||
handlers = {
|
|
||||||
"dir": self.get_cache_dir,
|
|
||||||
"info": self.get_cache_info,
|
|
||||||
"list": self.list_cache_items,
|
|
||||||
"remove": self.remove_cache_items,
|
|
||||||
"purge": self.purge_cache,
|
|
||||||
}
|
|
||||||
|
|
||||||
if not options.cache_dir:
|
|
||||||
logger.error("pip cache commands can not function since cache is disabled.")
|
|
||||||
return ERROR
|
|
||||||
|
|
||||||
# Determine action
|
|
||||||
if not args or args[0] not in handlers:
|
|
||||||
logger.error(
|
|
||||||
"Need an action (%s) to perform.",
|
|
||||||
", ".join(sorted(handlers)),
|
|
||||||
)
|
|
||||||
return ERROR
|
|
||||||
|
|
||||||
action = args[0]
|
|
||||||
|
|
||||||
# Error handling happens here, not in the action-handlers.
|
|
||||||
try:
|
|
||||||
handlers[action](options, args[1:])
|
|
||||||
except PipError as e:
|
|
||||||
logger.error(e.args[0])
|
|
||||||
return ERROR
|
|
||||||
|
|
||||||
return SUCCESS
|
|
||||||
|
|
||||||
def get_cache_dir(self, options: Values, args: List[Any]) -> None:
|
|
||||||
if args:
|
|
||||||
raise CommandError("Too many arguments")
|
|
||||||
|
|
||||||
logger.info(options.cache_dir)
|
|
||||||
|
|
||||||
def get_cache_info(self, options: Values, args: List[Any]) -> None:
|
|
||||||
if args:
|
|
||||||
raise CommandError("Too many arguments")
|
|
||||||
|
|
||||||
num_http_files = len(self._find_http_files(options))
|
|
||||||
num_packages = len(self._find_wheels(options, "*"))
|
|
||||||
|
|
||||||
http_cache_location = self._cache_dir(options, "http-v2")
|
|
||||||
old_http_cache_location = self._cache_dir(options, "http")
|
|
||||||
wheels_cache_location = self._cache_dir(options, "wheels")
|
|
||||||
http_cache_size = filesystem.format_size(
|
|
||||||
filesystem.directory_size(http_cache_location)
|
|
||||||
+ filesystem.directory_size(old_http_cache_location)
|
|
||||||
)
|
|
||||||
wheels_cache_size = filesystem.format_directory_size(wheels_cache_location)
|
|
||||||
|
|
||||||
message = (
|
|
||||||
textwrap.dedent(
|
|
||||||
"""
|
|
||||||
Package index page cache location (pip v23.3+): {http_cache_location}
|
|
||||||
Package index page cache location (older pips): {old_http_cache_location}
|
|
||||||
Package index page cache size: {http_cache_size}
|
|
||||||
Number of HTTP files: {num_http_files}
|
|
||||||
Locally built wheels location: {wheels_cache_location}
|
|
||||||
Locally built wheels size: {wheels_cache_size}
|
|
||||||
Number of locally built wheels: {package_count}
|
|
||||||
""" # noqa: E501
|
|
||||||
)
|
|
||||||
.format(
|
|
||||||
http_cache_location=http_cache_location,
|
|
||||||
old_http_cache_location=old_http_cache_location,
|
|
||||||
http_cache_size=http_cache_size,
|
|
||||||
num_http_files=num_http_files,
|
|
||||||
wheels_cache_location=wheels_cache_location,
|
|
||||||
package_count=num_packages,
|
|
||||||
wheels_cache_size=wheels_cache_size,
|
|
||||||
)
|
|
||||||
.strip()
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(message)
|
|
||||||
|
|
||||||
def list_cache_items(self, options: Values, args: List[Any]) -> None:
|
|
||||||
if len(args) > 1:
|
|
||||||
raise CommandError("Too many arguments")
|
|
||||||
|
|
||||||
if args:
|
|
||||||
pattern = args[0]
|
|
||||||
else:
|
|
||||||
pattern = "*"
|
|
||||||
|
|
||||||
files = self._find_wheels(options, pattern)
|
|
||||||
if options.list_format == "human":
|
|
||||||
self.format_for_human(files)
|
|
||||||
else:
|
|
||||||
self.format_for_abspath(files)
|
|
||||||
|
|
||||||
def format_for_human(self, files: List[str]) -> None:
|
|
||||||
if not files:
|
|
||||||
logger.info("No locally built wheels cached.")
|
|
||||||
return
|
|
||||||
|
|
||||||
results = []
|
|
||||||
for filename in files:
|
|
||||||
wheel = os.path.basename(filename)
|
|
||||||
size = filesystem.format_file_size(filename)
|
|
||||||
results.append(f" - {wheel} ({size})")
|
|
||||||
logger.info("Cache contents:\n")
|
|
||||||
logger.info("\n".join(sorted(results)))
|
|
||||||
|
|
||||||
def format_for_abspath(self, files: List[str]) -> None:
|
|
||||||
if files:
|
|
||||||
logger.info("\n".join(sorted(files)))
|
|
||||||
|
|
||||||
def remove_cache_items(self, options: Values, args: List[Any]) -> None:
|
|
||||||
if len(args) > 1:
|
|
||||||
raise CommandError("Too many arguments")
|
|
||||||
|
|
||||||
if not args:
|
|
||||||
raise CommandError("Please provide a pattern")
|
|
||||||
|
|
||||||
files = self._find_wheels(options, args[0])
|
|
||||||
|
|
||||||
no_matching_msg = "No matching packages"
|
|
||||||
if args[0] == "*":
|
|
||||||
# Only fetch http files if no specific pattern given
|
|
||||||
files += self._find_http_files(options)
|
|
||||||
else:
|
|
||||||
# Add the pattern to the log message
|
|
||||||
no_matching_msg += f' for pattern "{args[0]}"'
|
|
||||||
|
|
||||||
if not files:
|
|
||||||
logger.warning(no_matching_msg)
|
|
||||||
|
|
||||||
for filename in files:
|
|
||||||
os.unlink(filename)
|
|
||||||
logger.verbose("Removed %s", filename)
|
|
||||||
logger.info("Files removed: %s", len(files))
|
|
||||||
|
|
||||||
def purge_cache(self, options: Values, args: List[Any]) -> None:
|
|
||||||
if args:
|
|
||||||
raise CommandError("Too many arguments")
|
|
||||||
|
|
||||||
return self.remove_cache_items(options, ["*"])
|
|
||||||
|
|
||||||
def _cache_dir(self, options: Values, subdir: str) -> str:
|
|
||||||
return os.path.join(options.cache_dir, subdir)
|
|
||||||
|
|
||||||
def _find_http_files(self, options: Values) -> List[str]:
|
|
||||||
old_http_dir = self._cache_dir(options, "http")
|
|
||||||
new_http_dir = self._cache_dir(options, "http-v2")
|
|
||||||
return filesystem.find_files(old_http_dir, "*") + filesystem.find_files(
|
|
||||||
new_http_dir, "*"
|
|
||||||
)
|
|
||||||
|
|
||||||
def _find_wheels(self, options: Values, pattern: str) -> List[str]:
|
|
||||||
wheel_dir = self._cache_dir(options, "wheels")
|
|
||||||
|
|
||||||
# The wheel filename format, as specified in PEP 427, is:
|
|
||||||
# {distribution}-{version}(-{build})?-{python}-{abi}-{platform}.whl
|
|
||||||
#
|
|
||||||
# Additionally, non-alphanumeric values in the distribution are
|
|
||||||
# normalized to underscores (_), meaning hyphens can never occur
|
|
||||||
# before `-{version}`.
|
|
||||||
#
|
|
||||||
# Given that information:
|
|
||||||
# - If the pattern we're given contains a hyphen (-), the user is
|
|
||||||
# providing at least the version. Thus, we can just append `*.whl`
|
|
||||||
# to match the rest of it.
|
|
||||||
# - If the pattern we're given doesn't contain a hyphen (-), the
|
|
||||||
# user is only providing the name. Thus, we append `-*.whl` to
|
|
||||||
# match the hyphen before the version, followed by anything else.
|
|
||||||
#
|
|
||||||
# PEP 427: https://www.python.org/dev/peps/pep-0427/
|
|
||||||
pattern = pattern + ("*.whl" if "-" in pattern else "-*.whl")
|
|
||||||
|
|
||||||
return filesystem.find_files(wheel_dir, pattern)
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user