%bcond_with bootstrap

%global srcname setuptools
%define _unpackaged_files_terminate_build 1

%global python_wheelname %{srcname}-%{version}-py2.py3-none-any.whl
%global python2_wheelname %python_wheelname
%global python2_record %{python_sitelib}/%{srcname}-%{version}.dist-info/RECORD

Name:           python2-setuptools
Version:        44.1.1
Release:        2%{?_dist_release}
Summary:        Download, build, install, upgrade, and uninstall Python packages
Summary(ja):     Python パッケージのダウンロード、ビルド、インストール、アップグレードおよびアンインストール用ツール
Group:          programming
License:        PSFL/ZPL
URL:            https://pypi.python.org/pypi/setuptools
Source0:        https://files.pythonhosted.org/packages/source/s/%{srcname}/%{srcname}-%{version}.zip
Source1:        psfl.txt
Source2:        zpl.txt
BuildRoot:      %{_tmppath}/%{name}-%{version}-root

BuildArch:      noarch
BuildRequires:  python-devel
BuildRequires:  python-rpm-macros
%if %{without bootstrap}
BuildRequires:  python-pip
BuildRequires:  python-wheel
BuildConflicts: python-setuptools < %{version}
%endif # without bootstrap
Requires(post,postun): alternatives
Obsoletes: python-setuptools < %{version}
Provides: python-setuptools = %{version}-%{release}


%description
setuptools is a collection of enhancements to the Python distutils that allow
you to more easily build and distribute Python packages, especially ones that
have dependencies on other packages.

%description -l ja
setuptools は Python distutils の拡張機能を集めたツールです。
このツールにより Python パッケージの構築や配布が簡単に行えるように
なります。特に他のパッケージに依存しているパッケージを扱う際に便利
です。


%prep
%setup -q -n %{srcname}-%{version}

# We can't remove .egg-info (but it doesn't matter, since it'll be rebuilt):
#  The problem is that to properly execute setuptools' setup.py,
#   it is needed for setuptools to be loaded as a Distribution
#   (with egg-info or .dist-info dir), it's not sufficient
#   to just have them on PYTHONPATH
#  Running "setup.py install" without having setuptools installed
#   as a distribution gives warnings such as
#    ... distutils/dist.py:267: UserWarning: Unknown distribution option: 'entry_points'
#   and doesn't create "easy_install" and .egg-info directory
# Note: this is only a problem if bootstrapping wheel or building on RHEL,
#  otherwise setuptools are installed as dependency into buildroot

# Strip shbang
find setuptools -name \*.py | xargs sed -i -e '1 {/^#!\//d}'
# Remove bundled exes
rm -f setuptools/*.exe
# These tests require internet connection
rm setuptools/tests/test_integration.py

%build
%if %{without bootstrap}
%py_build_wheel
%else
%py_build
%endif


%install
rm -rf %{buildroot}

%if %{without bootstrap}
%py_install_wheel %{python2_wheelname}
%else
%py_install
%endif

rm -rf %{buildroot}%{python_sitelib}/setuptools/tests
%if %{without bootstrap}
sed -i '/^setuptools\/tests\//d' %{buildroot}%{python2_record}
%endif

find %{buildroot}%{python_sitelib} -name '*.exe' | xargs rm -f

# Don't ship these
rm -r docs/{Makefile,conf.py,_*}
rm -f %{buildroot}%{_bindir}/easy_install


%clean
rm -rf $RPM_BUILD_ROOT


%pre
update-alternatives --remove easy_install %{_bindir}/easy_install-%{python_version} ||:
if [ ! -L %{_bindir}/easy_install ]; then
  rm -f %{_bindir}/easy_install
fi

%posttrans
if [ ! -L %{_bindir}/easy_install ]; then
  ln -sf easy_install-%{python_version} %{_bindir}/easy_install
fi

%preun
if [ "$1" = "0" ]
then
  update-alternatives --remove easy_install %{_bindir}/easy_install-%{python_version} ||:
  rm -f %{_bindir}/easy_install
fi


%files
%defattr(-,root,root,-)
%license LICENSE
%doc docs/* CHANGES.rst README.rst
%{python_sitelib}/*
%{_bindir}/easy_install*


%changelog
* Tue Feb 23 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 44.1.1-2
- rebuilt with rpm-4.16.

* Sat Aug 15 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 44.1.1-1
- updated to 44.1.1 (the last release for Python2).
- changed %%name.
- built with python2 only.

* Wed Apr 08 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 44.1.0-1
- updated to 44.1.0.

* Sun Dec 17 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 38.2.4-1
- new upstream release.
- dropped Patch0.
- made to use python{,3}-rpm-macros.

* Sat Jul 30 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 25.1.1-1
- new upstream release.
- enable to build on Vine6.

* Tue Jun 28 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> - 18.5-3
- rebuild with python3-3.5.2

* Thu Dec 24 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 18.5-2
- added a subpackage: python3-setuptools.

* Sun Nov 15 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 18.5-1
- new upstream release.
- imported patch0 from rawhide.

* Mon Mar  9 2015 IWAI, Masaharu <iwaim.sub@gmail.com> - 5.4.2-2
- alternatives for easy_install

* Fri Aug 08 2014 Toshiharu Kudoh <toshi.kd2@gmail.com> 5.4.2-1
- new upstream release

* Sat Jul 26 2014 Toshiharu Kudoh <toshi.kd2@gmail.com> 5.4.1-1
- new upstream release

* Sun Jul 06 2014 Toshiharu Kudoh <toshi.kd2@gmail.com> 5.4-1
- new upstream release

* Sat Apr 26 2014 Toshiharu Kudoh <toshi.kd2@gmail.com> 3.4.4-1
- new upstream release

* Sun Feb 19 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.6c11-2
- rebuild with python-2.7.2

* Tue Feb 02 2010 Shu KONNO <owa@bg.wakwak.com> 0.6c11-1
- new upstream release

* Tue Feb 02 2010 Shu KONNO <owa@bg.wakwak.com> 0.6c9-2
- rebuild with python-2.6

* Sun Dec 07 2008 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.6c9-1
- new upstream release
- add japanese summary and description

* Mon Jul 21 2008 Shu KONNO <owa@bg.wakwak.com> - 0.6c3-1vl5
- rebuilt with python-2.5.2
- applied new versioning policy

* Sat Nov 25 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> - 0.6c3-1vl2
- rebuilt for Vine Linux 4.0
- changed Group to Development/Tools

* Wed Nov 15 2006 Susumu Tanimura <stanimura-ngs@umin.ac.jp>
- Refurbished for VineLinux3.2

* Tue Sep 12 2006 Konstantin Ryabitsev <icon@fedoraproject.org> - 0.6c2-1
- Upstream 0.6c2
- Ghostbusting

* Mon Jul 31 2006 Konstantin Ryabitsev <icon@fedoraproject.org> - 0.6c1-2
- Set perms on license files (#200768)

* Sat Jul 22 2006 Konstantin Ryabitsev <icon@fedoraproject.org> - 0.6c1-1
- Version 0.6c1

* Wed Jun 28 2006 Konstantin Ryabitsev <icon@fedoraproject.org> - 0.6b3-1
- Taking over from Ignacio
- Version 0.6b3
- Ghost .pyo files in sitelib
- Add license files
- Remove manual python-abi, since we're building FC4 and up
- Kill .exe files

* Wed Feb 15 2006 Ignacio Vazquez-Abrams <ivazquez@ivazquez.net> 0.6a10-1
- Upstream update

* Mon Jan 16 2006 Ignacio Vazquez-Abrams <ivazquez@ivazquez.net> 0.6a9-1
- Upstream update

* Sat Dec 24 2005 Ignacio Vazquez-Abrams <ivazquez@ivazquez.net> 0.6a8-1
- Initial RPM release
