## START: Set by rpmautospec
## (rpmautospec version 0.3.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 13;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Sphinx-generated HTML documentation is not suitable for packaging; see
# https://bugzilla.redhat.com/show_bug.cgi?id=2006555 for discussion.
#
# We can generate PDF documentation as a substitute.
%bcond doc_pdf 1

Name:           python-ncclient
Version:        0.6.13
Release:        %autorelease
Summary:        Python library for the NETCONF protocol

# The entire source is Apache-2.0, except:
#   - The script versioneer.py and the file ncclient/_version.py, which was
#     generated by it, are both CC0-1.0. While CC0-1.0 is not allowed for code
#     in Fedora, this case is allowed under the exception: “Existing uses of
#     CC0-1.0 on code files in Fedora packages prior to 2022-08-01, and
#     subsequent upstream versions of those files in those packages, continue
#     to be allowed. We encourage Fedora package maintainers to ask upstreams
#     to relicense such files.”
#     (https://gitlab.com/fedora/legal/fedora-license-data/-/issues/91#note_1151947383)
#
#     Upstream for ncclient cannot update the vendored versioneer to a version
#     that has been relicensed to Unlicense until ncclient drops support for
#     end-of-life Python versions 2.7, 3.5, and 3.6.
#
#     However, in this package, we now remove and replace/update both of these
#     files in %%prep in order to support Python 3.12; since we use a
#     sufficiently recent version of versioneer, the replacement files are
#     Unlicense instead of CC0-1.0.
License:        Apache-2.0 AND Unlicense
URL:            https://github.com/ncclient/ncclient
Source:         %{url}/archive/v%{version}/ncclient-%{version}.tar.gz

BuildArch:      noarch

BuildRequires:  python3-devel

# Update vendored versioneer.py for Python 3.12 compatibility
#
# python-ncclient fails to build with Python 3.12: AttributeError: module
# 'configparser' has no attribute 'SafeConfigParser'.
# https://bugzilla.redhat.com/show_bug.cgi?id=2175185
#
# Note that SafeConfigParser was renamed to ConfigParser in Python 3.2:
# https://docs.python.org/3/whatsnew/3.2.html#configparser
#
# The minimum version ensures that we have correctly incorporated the license
# of the generated _version.py as Unlicense rather than CC0-1.0.
BuildRequires:  python3dist(versioneer) >= 0.24
# The updated versioneer doesn’t pick up the version from the directory name
# for some reason, so we must create a git repository.
BuildRequires:  git-core

%global common_description %{expand:
ncclient is a Python library that facilitates client-side scripting and
application development around the NETCONF protocol. ncclient was developed by
Shikar Bhushan.net). It is now maintained by Leonidas Poulopoulos (@leopoul)
and Einar Nilsen-Nygaard (@einarnn).

Docs: http://ncclient.readthedocs.org

PyPI: https://pypi.python.org/pypi/ncclient}

%description %{common_description}


%package -n python3-ncclient
Summary:        %{summary}

%description -n python3-ncclient %{common_description}


%package doc
Summary:        Documentation and examples for python-ncclient

%if %{with doc_pdf}
BuildRequires:  make
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
%endif

%description doc
The python-ncclient-doc package contains detailed documentation and examples
for python-ncclient.


%prep
%autosetup -n ncclient-%{version}
%py3_shebang_fix examples

# Keep a dependency on deprecated python3dist(nose) from being generated.
# Upstream still prefers to use nose, but the tests have been adjusted so that
# it is no longer required.
sed -r -i '/^nose\b/d' test-requirements.txt
# Don’t generate dependencies on unnecessary linting and test coverage
# dependencies, either.
sed -r -i '/^(flake8|pytest-cov)\b/d' test-requirements.txt

# Loosen exact-version doc dependencies
sed -r -i 's/==/>=/' docs/requirements.txt
# Drop intersphinx mappings, since we can’t download remote inventories and
# can’t easily produce working hyperlinks from inventories in local
# documentation packages.
echo 'intersphinx_mapping.clear()' >> docs/conf.py

rm -vf versioneer.py ncclient/_version.py
versioneer install


%generate_buildrequires
%pyproject_buildrequires -t %{?with_doc_pdf:docs/requirements.txt}


%build
# The updated versioneer doesn’t pick up the version from the directory name
# for some reason, so we must create a git repository.
git config --global user.name 'Nobody'
git config --global user.email 'nobody@example.com'
git init
git add .
git commit -m 'Version %{version}'
git tag 'v%{version}'

%pyproject_wheel

%if %{with doc_pdf}
%make_build -C docs latex SPHINXOPTS='-j%{?_smp_build_ncpus}'
# There is an escaping problem we haven’t traced to its root cause. In the list
# of authors, “\and” is emitted, and then “\a” is interpreted as the backslash
# escape for the ASCII BEL (bell) character. This then breaks the LaTeX build.
# Find it and fix it after generating the LaTeX source and before building it.
sed -r -i 's/\x07nd/and/g' docs/build/latex/ncclient.tex
%make_build -C docs/build/latex LATEXMKOPTS='-quiet'
%endif


%install
%pyproject_install
%pyproject_save_files ncclient


%check
%tox

 
%files -n python3-ncclient -f %{pyproject_files}


%files doc
%license LICENSE
%doc Changelog
%doc NOTICE
%doc README.md
%doc README.rst
%if %{with doc_pdf}
%doc docs/build/latex/ncclient.pdf
%endif
%doc examples/


%changelog
* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.13-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Tue Jul 11 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-12
- Use a trailing slash when listing directories in files lists

* Fri Jul 07 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-11
- Use new (rpm 4.17.1+) bcond style

* Thu Jun 15 2023 Python Maint <python-maint@redhat.com> - 0.6.13-10
- Rebuilt for Python 3.12

* Fri Mar 17 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-8
- Don’t assume %%_smp_mflags is -j%%_smp_build_ncpus

* Mon Mar 06 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-7
- Rebuild with Unlicense-licensed versioneer

* Sat Mar 04 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-6
- Replace vendored versioneer.py for Python 3.12 (close RHBZ#2175185)

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.13-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Thu Nov 24 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-4
- Update License to SPDX

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.13-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jun 14 2022 Python Maint <python-maint@redhat.com> - 0.6.13-2
- Rebuilt for Python 3.11

* Mon Apr 11 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.13-1
- Update to 0.6.13 (close RHBZ#2073846)

* Mon Apr 11 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-17
- Generate doc dependencies from requirements file

* Mon Apr 11 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-16
- Drop “forge” macros, since they don’t benefit us much

* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.12-15
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Fri Jan 07 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-14
- Drop intersphinx mappings

* Fri Dec 17 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-13
- Avoid generating several unnecessary BuildRequires

* Sat Nov 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-12
- Tweak a spec file comment

* Fri Nov 26 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-11
- Reduce LaTeX PDF build verbosity

* Thu Sep 30 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-10
- Generate PDF instead of HTML Sphinx documentation.

* Mon Sep 13 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-9
- Let pyproject-rpm-macros handle the license file

* Sun Sep 12 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-8
- Drop BR on pyproject-rpm-macros, now implied by python3-devel

* Sun Sep 12 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-7
- Reduce macro indirection in the spec file

* Tue Jul 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-6
- Use forgeautosetup macro

* Tue Jul 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-5
- Move %%generate_buildrequires after %%prep to make the spec file easier
  to follow

* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.6.12-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 0.6.12-2
- Rebuilt for Python 3.10

* Sun May 30 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.12-1
- Update to 0.6.12

* Sat May 29 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.11-1
- Update to 0.6.11
- Drop upstreamed patches

* Tue Mar 16 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.10-2
- Patch out BR on deprecated python3-mock
- Patch out BR on deprecated python3-nose

* Tue Mar 16 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.10-1
- Update to 0.16.10
- Drop python-ncclient-0.6.9-shebangs.patch, now upstreamed
- Drop python3dist(setuptools) BR, redundant with pyproject-rpm-macros

* Tue Mar 02 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.9-2
- Rebuild for fixed RHBZ#1925963 in pyproject-rpm-macros-0-38
- Enable parallel Sphinx build

* Fri Jan  1 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.6.9-1
- Prepare for unretirement
- New upstream version 0.6.9
- Migrate from Python 2 to Python 3
- Use new macros for source URL and build/install/test sections, and drop old
  macros like python_provide
- Use generated Requires and BuildRequires
- Split documentation and examples into a separate -doc subpackage

* Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.7-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.7-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Fri Jan 26 2018 Iryna Shcherbina <ishcherb@redhat.com> - 0.4.7-6
- Update Python 2 dependency declarations to new packaging standards
  (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3)

* Sat Aug 19 2017 Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> - 0.4.7-5
- Python 2 binary package renamed to python2-ncclient
  See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3

* Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.7-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild

* Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.7-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild

* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.4.7-2
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

* Tue Mar 08 2016 Ihar Hrachyshka <ihrachys@redhat.com> 0.4.7-1.el7
- Update to 0.4.7

* Thu Feb 04 2016 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.2-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild

* Thu Jun 18 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.4.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild

* Fri Dec  5 2014 Ihar Hrachyshka <ihrachys@redhat.com> - 0.4.2-2
- Added missing python-setuptools as a build dependency.
- Include documentation and examples.
- Run unit tests on build.
- Rebuild egg file.
- Added python2 macros needed for el6.
- Made python macros more specific (python -> python2).
- Made python2_sitelib file inclusion wildcard a bit more strict.

* Thu Dec  4 2014 Ihar Hrachyshka <ihrachys@redhat.com> - 0.4.2-1
- Updated to upstream 0.4.2 version

* Thu Aug  7 2014 Ihar Hrachyshka <ihrachys@redhat.com> - 0.4.1-1
- Initial package for Fedora