File aws-cli-2.spec of Package aws-cli-2

#
# spec file for package aws-cli-2
#
# Copyright (c) 2024 Dominik Wombacher <dominik@wombacher.cc>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%global pkgname aws-cli

%if 0%{?suse_version} >= 1600
%define pythons %{primary_python}
%else
%define pythons python311
%endif
%global _sitelibdir %{%{pythons}_sitelib}

Name:           aws-cli-2
Version:        2.31.13
Release:        0
Summary:        Universal Command Line Environment for AWS, version 2
# all files are licensed under Apache-2.0, except:
# - awscli/topictags.py is MIT
# - awscli/botocore/vendored/six.py is MIT
License:        Apache-2.0 AND MIT
Group:          System/Management
URL:            https://github.com/aws/aws-cli/tree/v2
Source:         https://github.com/aws/aws-cli/archive/%{version}/%{pkgname}-%{version}.tar.gz

# PATCH-FIX-OPENSUSE 0001-fix_TestEMRutils.test_which_with_existing_command.patch dominik@wombacher.cc -- Test fails if 'python' doesn't exist, patch adds 'python3' (openSUSE Tumbleweed) and 'python3.11' (openSUSE Leap / SLE) as valid option
Patch0001:      0001-fix_TestEMRutils.test_which_with_existing_command.patch
# PATCH-FIX-UPSTREAM 0002-support-ruamel-yaml-0.17.32-and-higher.patch gh#aws/aws-cli#8342 nforro@redhat.com -- Adapt to whitespace formatting changes and removal of OrderedDict in ruamel-yaml
#Patch0002:      0002-support-ruamel-yaml-0.17.32-and-higher.patch
# PATCH-FIX-UPSTREAM 0003-fix-python-312-incompatibilities.patch gh#aws/aws-cli#8342 nforro@redhat.com -- Make aws cli v2 Python 3.12 compatible
#Patch0003:      0003-fix-python-312-incompatibilities.patch
# PATCH-FIX-UPSTREAM 0004-fix-mystery-function-call-in-eks-tests.patch https://github.com/aws/aws-cli/pull/8106 nate.prewitt@gmail.com -- Fix mystery function call in EKS tests. Tagged for 2.15.47 but not part of the release.
#Patch0004:      0004-fix-mystery-function-call-in-eks-tests.patch
# PATCH-FIX-OPENSUSE 0005-skip-TestPromptToolkitPrompterBuffer.test_input_buffer_initialization.patch dominik@wombacher.cc -- Test randomly fails (trailing whitespace in output string expected) on aarch64
#Patch0005:      0005-skip-TestPromptToolkitPrompterBuffer.test_input_buffer_initialization.patch
# PATCH-FIX-OPENSUSE 0006-enforce-usage-of-cacert-discovered-by-python-certifi-by-default.patch dominik@wombacher.cc -- 'DEFAULT_CA_BUNDLE' is set to the bundled cacert from botocore, enforce usage of cacert discovered by python certifi by default. In openSUSE and SLES this is '/etc/ssl/ca-bundle.pem'.
Patch0006:      0006-enforce-usage-of-cacert-discovered-by-python-certifi-by-default.patch

BuildArch:      noarch

BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
BuildRequires:  %{pythons}
BuildRequires:  %{pythons}-devel
BuildRequires:  %{pythons}-pip
BuildRequires:  %{pythons}-flit-core
BuildRequires:  %{pythons}-colorama >= 0.2.5
BuildRequires:  %{pythons}-docutils >= 0.10
BuildRequires:  %{pythons}-ruamel.yaml >= 0.2.0
BuildRequires:  %{pythons}-ruamel.yaml.clib
BuildRequires:  %{pythons}-prompt_toolkit >= 3.0.24
BuildRequires:  %{pythons}-distro
BuildRequires:  %{pythons}-awscrt >= 0.27.6
BuildRequires:  %{pythons}-dateutil >= 2.1
BuildRequires:  %{pythons}-jmespath >= 0.7.1
BuildRequires:  %{pythons}-urllib3 < 1.27
BuildRequires:  %{pythons}-pytest
BuildRequires:  %{pythons}-pytest-xdist
BuildRequires:  %{pythons}-jsonschema
BuildRequires:  %{pythons}-certifi
BuildRequires:  procps

Requires:       groff
Requires:       %{pythons}-certifi
%{?python_enable_dependency_generator}

Provides:       awscli = %{version}-%{release}
# Either v1 (Cloud:Tools/aws-cli) or v2 can be installed at the same time
Conflicts:      awscli < 2
# Upstream bundles two Python modules
Provides:       bundled(python3dist(botocore)) = 2.0.0dev155
Provides:       bundled(python3dist(s3transfer)) = 0.5.1

%debug_package

%description
This package provides version 2 of the unified command line
interface to Amazon Web Services.


%package -n %{name}-doc
Summary:        Documentation files for %name
Group:          Documentation/Other
# Fix 'no-dependency-on python-base 3.xx' build error when using '{pythons}'
Requires:       python(abi) = %{python_version}

%description -n %{name}-doc
Documentation and examples for %name.


%prep
%autosetup -p1 -n %{pkgname}-%{version}

# Remove cacert.pem from bundled botocore to align with standalone python-botocore package behavior.
# Patch0006 enforce usage of '/etc/ssl/ca-bundle.pem' when package 'python-certifi' is installed.
rm awscli/botocore/cacert.pem

# Fix permissions
find awscli/examples/ -type f -name '*.rst' -executable -exec chmod -x '{}' +
chmod -x awscli/customizations/emr/helptext.py

# Use unittest.mock
find -type f -name '*.py' -exec sed \
    -e 's/^\( *\)import mock$/\1from unittest import mock/' \
    -e 's/^\( *\)from mock import mock/\1from unittest import mock/' \
    -e 's/^\( *\)from mock import/\1from unittest.mock import/' \
    -i '{}' +


%build
%pyproject_wheel


%install
%pyproject_install

%python_expand %fdupes %{buildroot}%{_sitelibdir}

# Shell completion
install -DTm644 %{buildroot}%{_bindir}/aws_bash_completer \
    %{buildroot}%{_datadir}/bash-completion/completions/aws
install -DTm644 %{buildroot}%{_bindir}/aws_zsh_completer.sh \
    %{buildroot}%{_sysconfdir}/zsh_completion.d/_aws

# remove unnecessary scripts
rm -vf %{buildroot}%{_bindir}/{aws_bash_completer,aws_zsh_completer.sh,aws.cmd}


%check
# It appears that some tests modify the environment and remove PYTHONPATH
# so it's not passed to botocore cmd-runner, inject it here
sed -i '/self.driver.start(env=env)/i \ \ \ \ \ \ \ \ env["PYTHONPATH"] = "%{buildroot}%{_sitelibdir}"' \
    tests/utils/botocore/__init__.py

# Set env vars used by pytest
export TESTS_REMOVE_REPO_ROOT_FROM_PATH=1
export TZ=UTC

# Upstream declares DeprecationWarning as Errors, '-Wd' handles them as Warning instead
# Test that randomly fails (trailing whitespace in output string expected) on aarch64:
#   tests/functional/autoprompt/test_prompttoolkit.py::TestPromptToolkitPrompterBuffer::test_input_buffer_initialization
%pytest -Wd --verbose tests/unit tests/functional


%files
%license LICENSE.txt
%doc README.rst CHANGELOG.rst
%dir %{_sitelibdir}/awscli
%dir %{_sitelibdir}/awscli-%{version}*-info
%{_sitelibdir}/awscli/*
%{_sitelibdir}/awscli-%{version}*-info/*
%{_bindir}/aws
%{_bindir}/aws_completer
%{_datadir}/bash-completion/completions/aws
%dir %{_sysconfdir}/zsh_completion.d
%config %attr(644,root,root) %{_sysconfdir}/zsh_completion.d/_aws
# doc sub-package
%exclude %{_sitelibdir}/awscli/examples
# debuginfo
%exclude %{_sitelibdir}/awscli/__pycache__
%pycache_only %{_sitelibdir}/awscli/__pycache__


%files -n %{name}-doc
%doc %{_sitelibdir}/awscli/examples/


%changelog

openSUSE Build Service is sponsored by