File pyhcl.spec of Package pyhcl

#
# spec file for package pyhcl
#
# Copyright (c) 2020 SUSE LLC.
#
# 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 http://bugs.opensuse.org/
#

# For some reason Fedora and CentOS8 do not build correctly debuginfo packages on OBS
%if 0%{?fedora} || 0%{?rhel} >= 8
%define debug_package %{nil}
%endif

# Python3 for everyone... (warning, this doesn't work for Leap < 15.0, but those are EoL)
%if 0%{?fedora} || 0%{?suse_version} >= 1500 || 0%{?sle_version} >= 120100 || 0%{?rhel} >= 8 || %{_vendor} == "debbuild"
%global build_py3  1
# CentOS8/RHEL8 require defining __python, so let's us it and avoid python macros from SLE
# so it is easier to stay compatible with all distributions
%define __python   /usr/bin/python3
%define python_bin %{__python}
# ...except for old SLE/openSUSE CentOS/RHEL versions (Python2)
%else
%global build_py2  1
%define python_bin %{__python}
%endif

# Avoid python macros, so it is easier to stay compatible with all distributions
%define sitelib %(%{python_bin} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")

Name:           pyhcl
Version:        0.4.2
Release:        0
Summary:        Python parser for for HashiCorp Configuration Manager (hcl)
License:        MPL-2.0
Group:          Development/Languages/Python
Url:            https://github.com/virtuald/pyhcl
Source:         https://files.pythonhosted.org/packages/source/p/pyhcl/pyhcl-%{version}.tar.gz
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

%description
Python parser for for HashiCorp Configuration Manager (hcl) (meta-package)

%if 0%{?build_py2}
%package -n python-%{name}
Summary:        Python parser for for HashiCorp Configuration Manager (hcl) (python2)
# CentOS/Fedora/RHEL do not have fdupes
%if 0%{?suse_version}
BuildRequires:  fdupes
%endif
BuildRequires:  python
BuildRequires:  python-setuptools
Requires:       python
Conflicts:      python3-%{name}

%description -n python-%{name}
Python parser for for HashiCorp Configuration Manager (hcl) (python2)
%endif

%if 0%{?build_py3}
%package -n python3-%{name}
Summary:        Python parser for for HashiCorp Configuration Manager (hcl) (python3)
# CentOS/Fedora/RHEL do not have fdupes
%if 0%{?suse_version}
BuildRequires:  fdupes
%endif
BuildRequires:  python3
BuildRequires:  python3-setuptools
Requires:       python3
Conflicts:      python-%{name}
Provides:       python-%{name}

%description -n python3-%{name}
Python parser for for HashiCorp Configuration Manager (hcl) (python3)
%endif

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

%clean
rm -rf %{buildroot}

%build
%{python_bin} setup.py build

%install
%{python_bin} setup.py install --root %{buildroot} --prefix %{_prefix} --install-lib %{sitelib}
%if 0%{?suse_version}
%fdupes %{buildroot}%{sitelib}
%endif

%if 0%{?build_py2}
%files -n python-%{name}
%defattr(-,root,root)
%dir %{sitelib}/hcl
%{sitelib}/hcl/*
%{sitelib}/pyhcl-*.egg-info
%{_bindir}/hcltool
%doc CHANGELOG.md README.rst
# Compatibility with old distributions
%{!?_licensedir:%global license %doc}
%license LICENSE
%endif

%if 0%{?build_py3}
%files -n python3-%{name}
%defattr(-,root,root)
%dir %{sitelib}/hcl
%{sitelib}/hcl/*
%{sitelib}/pyhcl-*.egg-info
%{_bindir}/hcltool
%doc CHANGELOG.md README.rst
%license LICENSE
%endif

%changelog

openSUSE Build Service is sponsored by