ansible-test - Remove generation of egg-info (#83786)

Also remove egg-info generation from hacking/env-setup scripts.
pull/83796/head
Matt Clay 3 months ago committed by GitHub
parent 26375e7f12
commit ab624ad031
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
minor_changes:
- ansible-test - An ``ansible_core.egg-info`` directory is no longer generated when running tests.

@ -57,22 +57,6 @@ expr "$PYTHONPATH" : "${ANSIBLE_TEST_PREFIX_PYTHONPATH}.*" > /dev/null || prepen
expr "$PATH" : "${PREFIX_PATH}.*" > /dev/null || prepend_path PATH "$PREFIX_PATH" expr "$PATH" : "${PREFIX_PATH}.*" > /dev/null || prepend_path PATH "$PREFIX_PATH"
expr "$MANPATH" : "${PREFIX_MANPATH}.*" > /dev/null || prepend_path MANPATH "$PREFIX_MANPATH" expr "$MANPATH" : "${PREFIX_MANPATH}.*" > /dev/null || prepend_path MANPATH "$PREFIX_MANPATH"
#
# Generate egg_info so that pkg_resources works
#
# Do the work in a function so we don't repeat ourselves later
gen_egg_info()
{
# check for current and past egg-info directory names
if ls "$PREFIX_PYTHONPATH"/ansible*.egg-info >/dev/null 2>&1; then
# bypass shell aliases with leading backslash
# see https://github.com/ansible/ansible/pull/11967
\rm -rf "$PREFIX_PYTHONPATH"/ansible*.egg-info
fi
"$PYTHON_BIN" setup.py egg_info
}
if [ "$ANSIBLE_DEV_HOME" != "$PWD" ] ; then if [ "$ANSIBLE_DEV_HOME" != "$PWD" ] ; then
current_dir="$PWD" current_dir="$PWD"
else else
@ -81,10 +65,8 @@ fi
( (
cd "$ANSIBLE_DEV_HOME" cd "$ANSIBLE_DEV_HOME"
if [ "$verbosity" = silent ] ; then if [ "$verbosity" = silent ] ; then
gen_egg_info > /dev/null 2>&1 &
find . -type f -name "*.pyc" -exec rm -f {} \; > /dev/null 2>&1 find . -type f -name "*.pyc" -exec rm -f {} \; > /dev/null 2>&1
else else
gen_egg_info
find . -type f -name "*.pyc" -exec rm -f {} \; find . -type f -name "*.pyc" -exec rm -f {} \;
fi fi
cd "$current_dir" cd "$current_dir"

@ -64,25 +64,11 @@ if not set -q PYTHON_BIN
end end
end end
# Generate egg_info so that pkg_resources works
function gen_egg_info
# Check if ansible*.egg-info directory exists and remove if found
if test -d $PREFIX_PYTHONPATH/ansible*.egg-info
rm -rf $PREFIX_PYTHONPATH/ansible*.egg-info
end
# Execute setup.py egg_info using the chosen Python interpreter
eval $PYTHON_BIN setup.py egg_info
end
pushd $ANSIBLE_HOME pushd $ANSIBLE_HOME
if test -n "$QUIET" if test -n "$QUIET"
# Run gen_egg_info in the background and redirect output to /dev/null
gen_egg_info &> /dev/null
# Remove any .pyc files found # Remove any .pyc files found
find . -type f -name "*.pyc" -exec rm -f '{}' ';' &> /dev/null find . -type f -name "*.pyc" -exec rm -f '{}' ';' &> /dev/null
else else
# Run gen_egg_info
gen_egg_info
# Remove any .pyc files found # Remove any .pyc files found
find . -type f -name "*.pyc" -exec rm -f '{}' ';' find . -type f -name "*.pyc" -exec rm -f '{}' ';'
# Display setup details # Display setup details

@ -11,10 +11,6 @@ from .constants import (
SOFT_RLIMIT_NOFILE, SOFT_RLIMIT_NOFILE,
) )
from .io import (
write_text_file,
)
from .util import ( from .util import (
common_environment, common_environment,
ApplicationError, ApplicationError,
@ -25,7 +21,6 @@ from .util import (
ANSIBLE_SOURCE_ROOT, ANSIBLE_SOURCE_ROOT,
ANSIBLE_TEST_TOOLS_ROOT, ANSIBLE_TEST_TOOLS_ROOT,
MODE_FILE_EXECUTE, MODE_FILE_EXECUTE,
get_ansible_version,
raw_command, raw_command,
verified_chmod, verified_chmod,
) )
@ -251,12 +246,15 @@ def get_cli_path(path: str) -> str:
raise RuntimeError(path) raise RuntimeError(path)
# noinspection PyUnusedLocal
@mutex @mutex
def get_ansible_python_path(args: CommonConfig) -> str: def get_ansible_python_path(args: CommonConfig) -> str:
""" """
Return a directory usable for PYTHONPATH, containing only the ansible package. Return a directory usable for PYTHONPATH, containing only the ansible package.
If a temporary directory is required, it will be cached for the lifetime of the process and cleaned up at exit. If a temporary directory is required, it will be cached for the lifetime of the process and cleaned up at exit.
""" """
del args # not currently used
try: try:
return get_ansible_python_path.python_path # type: ignore[attr-defined] return get_ansible_python_path.python_path # type: ignore[attr-defined]
except AttributeError: except AttributeError:
@ -273,38 +271,11 @@ def get_ansible_python_path(args: CommonConfig) -> str:
os.symlink(ANSIBLE_LIB_ROOT, os.path.join(python_path, 'ansible')) os.symlink(ANSIBLE_LIB_ROOT, os.path.join(python_path, 'ansible'))
if not args.explain:
generate_egg_info(python_path)
get_ansible_python_path.python_path = python_path # type: ignore[attr-defined] get_ansible_python_path.python_path = python_path # type: ignore[attr-defined]
return python_path return python_path
def generate_egg_info(path: str) -> None:
"""Generate an egg-info in the specified base directory."""
# minimal PKG-INFO stub following the format defined in PEP 241
# required for older setuptools versions to avoid a traceback when importing pkg_resources from packages like cryptography
# newer setuptools versions are happy with an empty directory
# including a stub here means we don't need to locate the existing file or run any tools to generate it when running from source
pkg_info = '''
Metadata-Version: 1.0
Name: ansible
Version: %s
Platform: UNKNOWN
Summary: Radically simple IT automation
Author-email: info@ansible.com
License: GPLv3+
''' % get_ansible_version()
pkg_info_path = os.path.join(path, 'ansible_core.egg-info', 'PKG-INFO')
if os.path.exists(pkg_info_path):
return
write_text_file(pkg_info_path, pkg_info.lstrip(), create_directories=True)
class CollectionDetail: class CollectionDetail:
"""Collection detail.""" """Collection detail."""

Loading…
Cancel
Save