%bcond_without bootstrap
%bcond_without python3

%global srcname setuptools
%define _unpackaged_files_terminate_build 1

%global python_wheelname %{srcname}-%{version}-py2.py3-none-any.whl
%if %{with python3}
%global python3_wheelname %python_wheelname
%global python3_record %{python3_sitelib}/%{srcname}-%{version}.dist-info/RECORD
%endif

Name:           python-setuptools
Version:        49.6.0
Release:        1%{?_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-rpm-macros
%if %{with python3}
BuildRequires:  python3
BuildRequires:  python3-devel
BuildRequires:  python3-rpm-macros
%if %{without bootstrap}
BuildRequires:  python3-pip
BuildRequires:  python3-wheel
%endif # without bootstrap
%endif # with python3

%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 パッケージの構築や配布が簡単に行えるように
なります。特に他のパッケージに依存しているパッケージを扱う際に便利
です。


%if %{with python3}
%package -n     python3-setuptools
Summary:        Download, build, install, upgrade, and uninstall Python3 packages
Summary(ja):    Python3 パッケージのダウンロード、ビルド、インストール、アップグレードおよびアンインストール用ツール
Group:          programming
Requires(post,postun): alternatives

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


%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 %{with python3}
%if %{without bootstrap}
%py3_build_wheel
%else
%py3_build
%endif
%endif # with python3

%install
rm -rf %{buildroot}

# Must do the python3 install first because the scripts in /usr/bin are
# overwritten with every setup.py install (and we want the python2 version to
# be the default for now).
%if %{with python3}
%if %{without bootstrap}
%py3_install_wheel %{python3_wheelname}

# Remove /usr/bin/easy_install from the record as later on we delete the file
sed -i '/\/usr\/bin\/easy_install,/d' %{buildroot}%{python3_record}
%else
%py3_install
%endif

# TODO: we have to remove this by hand now, but it'd be nice if we wouldn't have to
rm %{buildroot}%{_bindir}/easy_install

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

find %{buildroot}%{python3_sitelib} -name '*.exe' | xargs rm -f
%endif # with python3

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


%clean
rm -rf $RPM_BUILD_ROOT


%if %{with python3}
%pre -n python3-setuptools
if [ ! -L %{_bindir}/easy_install ]; then
  rm -f %{_bindir}/easy_install
fi

%post -n python3-setuptools
/sbin/update-alternatives \
  --install %{_bindir}/easy_install easy_install \
  %{_bindir}/easy_install-%{python3_version} %{python3_version_nodots}

%preun -n python3-setuptools
if [ "$1" = "0" ]; then
  /sbin/update-alternatives \
    --remove easy_install %{_bindir}/easy_install-%{python3_version}
fi
%endif

%if %{with python3}
%files -n python3-setuptools
%license LICENSE
%doc docs/* CHANGES.rst README.rst
%{python3_sitelib}/easy_install.py
%{python3_sitelib}/distutils-precedence.pth
%{python3_sitelib}/pkg_resources/
%{python3_sitelib}/setuptools*/
%{python3_sitelib}/__pycache__/*
%{python3_sitelib}/_distutils_hack
%{_bindir}/easy_install-3*
%endif


%changelog
* Sat Aug 15 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 49.6.0-1
- updated to 49.6.0.
- built with python3 only.

* Wed Apr 08 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 44.1.0-1
- updated to 44.1.0 (last release for Python2).

* 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