Blob Blame History Raw
# Not building on EPEL 6 because python-flask on EPEL 6 is flat broken;
# it depends on python-jinja2-26 but does not load it properly, so
# httpbin's test suite fails as soon as it tries to import flask.

# Not building on EPEL 7 as test_delete_endpoint_returns_body fails
# there, for some reason, and I do not have the round tuits to figure
# it out.

%global github_owner    Runscope
%global github_name     httpbin
%global github_commit   3f417eb81885f9e5fd99282121e3df9d619583c1

%global desc Testing an HTTP Library can become difficult sometimes. RequestBin is \
fantastic for testing POST requests, but doesn't let you control the response. \
This exists to cover all kinds of HTTP scenarios. Additional endpoints are \
being considered. All endpoint responses are JSON-encoded.

%global sum HTTP Request & Response Service, written in Python + Flask

# Enable Python 3 builds for Fedora + EPEL >7
# EPEL 7 is missing Python 3 builds of flask and itsdangerous
%if 0%{?fedora} || 0%{?rhel} > 7
# If the definition isn't available for python3_pkgversion, define it
%{?!python3_pkgversion:%global python3_pkgversion 3}
%bcond_without  python3
%else
%bcond_with     python3
%endif

# Requirements for tests (BuildRequires) and run (Requires)
# EPEL builds do not provide python2-*
%global t_requires python-flask python-markupsafe python-decorator python-itsdangerous python-six python-argparse
%global t3_requires python%{python3_pkgversion}-flask python%{python3_pkgversion}-markupsafe python%{python3_pkgversion}-decorator python%{python3_pkgversion}-itsdangerous python%{python3_pkgversion}-six

Name:           python-%{github_name}
Version:        0.5.0
Release:        3%{?dist}
Summary:        %{sum}

License:        MIT
URL:            https://github.com/%{github_owner}/%{github_name}
Source0:        https://github.com/%{github_owner}/%{github_name}/archive/%{github_commit}/%{github_name}-%{version}.tar.gz
BuildArch:      noarch

BuildRequires:  python2-devel
# no python2-setuptools on EL6
BuildRequires:  python-setuptools
BuildRequires:  %{t_requires}

%if %{with python3}
# Required for Python 3 pkgversion macros to work
BuildRequires:  python3-pkgversion-macros

BuildRequires:  python%{python3_pkgversion}-setuptools
BuildRequires:  python%{python3_pkgversion}-devel
BuildRequires:  %{t3_requires}

%if 0%{?with_python3_other}
BuildRequires:  python%{python3_other_pkgversion}-setuptools
BuildRequires:  python%{python3_other_pkgversion}-devel
%endif
%endif

%description
%{desc}


%package -n python2-%{github_name}
Summary:    %{sum}
Requires:   %{t_requires}
%{?python_provide:%python_provide python2-%{github_name}}

%description -n python2-%{github_name}
%{desc}

This package provides the Python 2 implementation.

%if %{with python3}
%package -n python%{python3_pkgversion}-%{github_name}
Summary:    %{sum}
Requires:   %{t3_requires}
%{?python_provide:%python_provide python%{python3_pkgversion}-%{github_name}}

%description -n python%{python3_pkgversion}-%{github_name}
%{desc}

This package provides the Python 3 implementation.

%if 0%{?with_python3_other}
%package -n python%{python3_other_pkgversion}-%{github_name}
Summary:        %{sum}
%{?python_provide:%python_provide python%{python3_other_pkgversion}-%{github_name}}

%description -n python%{python3_other_pkgversion}-%{github_name}
%{desc}

This package provides the Python 3 implementation.
%endif
%endif

#################################################################################
%prep
%autosetup -n %{github_name}-%{github_commit} -p1
# no need for this to be executable
chmod ugo-x httpbin/templates/forms-post.html

%build
%py2_build

# use of read() without an explicit codec in setup.py will use 'ascii'
# codec in Fedora build env, which can fail if text has non-ascii chars
%if %{with python3}
LANG=en_US.UTF-8 %py3_build

%if 0%{?with_python3_other}
%py3_other_build
%endif
%endif


%install
%py2_install

# use of read() without an explicit codec in setup.py will use 'ascii'
# codec in Fedora build env, which can fail if text has non-ascii chars
%if %{with python3}
LANG=en_US.UTF-8 %py3_install

%if 0%{?with_python3_other}
LANG=en_US.UTF-8 %py3_other_install
%endif
%endif

#################################################################################
%check
%{__python2} test_httpbin.py
%if %{with python3}
%{__python3} test_httpbin.py
%endif

#################################################################################
%files -n python2-%{github_name}
%{python2_sitelib}/%{github_name}*
%license LICENSE
%doc README.rst AUTHORS

%if %{with python3}
%files -n python%{python3_pkgversion}-%{github_name}
%{python3_sitelib}/%{github_name}*
%license LICENSE
%doc README.rst AUTHORS

%if 0%{?with_python3_other}
%files -n python%{python3_other_pkgversion}-%{github_name}
%{python3_other_sitelib}/%{github_name}*
%license LICENSE
%doc README.rst AUTHORS
%endif
%endif

#################################################################################
%changelog
* Wed Dec 21 2016 Adam Williamson <awilliam@redhat.com> - 0.5.0-3
- properly own all directories
- fix the mode of a template (doesn't need to be executable)

* Wed Dec 21 2016 Adam Williamson <awilliam@redhat.com> - 0.5.0-2
- add missing runtime deps to python3 package
- add comment explaining use of LANG

* Wed Dec 21 2016 Adam Williamson <awilliam@redhat.com> - 0.5.0-1
- initial package