## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    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

%bcond tests 1

# 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-pyscaffold
Version:        4.6
Release:        %autorelease
Summary:        Template tool for putting up the scaffold of a Python project

# The entire source is MIT, except for the template files under
# pyscaffold.templates, which are 0BSD.
License:        MIT and 0BSD
URL:            https://pyscaffold.org/
Source0:        %{pypi_source pyscaffold}
# Man page written by hand in groff_man(7) format for Fedora based on --help
# output. Note that help2man(1) could autogenerate a decent man page if needed:
#   help2man --no-info --output=putup.1 putup
# but the hand-written one is better-formatted and contains better
# cross-references.
Source1:        putup.1

# Downstream-only: do not run coverage analysis
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/#_linters
Patch:          PyScaffold-4.5-no-coverage.patch
# Downstream-only: remove animated demo from docs since this cannot be included
# in a PDF
Patch:          PyScaffold-4.1-no-animated-doc-demo.patch

BuildArch:      noarch

BuildRequires:  python3-devel

%if %{with tests}
BuildRequires:  git-core
# Needs vim (vim-enhanced) or vi (vim-minimal); we choose the lighter-weight BR
BuildRequires:  vim-minimal
BuildRequires:  python-unversioned-command
%endif

%if %{with doc_pdf}
BuildRequires:  make
BuildRequires:  python3-sphinx-latex
BuildRequires:  latexmk
BuildRequires:  /usr/bin/xindy
BuildRequires:  tex-xetex-bin
BuildRequires:  /usr/bin/rsvg-convert
%endif

%global common_description %{expand: \
PyScaffold is a project generator for bootstrapping high quality Python
packages, ready to be shared on PyPI and installable via pip. It is easy to use
and encourages the adoption of the best tools and practices of the Python
ecosystem, helping you and your team to stay sane, happy and productive. The
best part? It is stable and has been used by thousands of developers for over
half a decade!}

%description
%{common_description}


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

%description -n python3-pyscaffold
%{common_description}


%package doc
Summary:        %{summary}

%description doc
Documentation for %{name}.


# We do not package the “all” extra as a metapackage, because it has the
# following dependencies not currently packaged:
#
#   python3dist(pyscaffoldext-markdown) >= 0.4
#   python3dist(pyscaffoldext-custom-extension) >= 0.6
#   python3dist(pyscaffoldext-dsproject) >= 0.5
#   python3dist(pyscaffoldext-django) >= 0.1.1
#   python3dist(pyscaffoldext-cookiecutter) >= 0.1
#   python3dist(pyscaffoldext-travis) >= 0.3
#
# We do not package the “md” extra as a metapackage, because it has the
# following dependencies not currently packaged:
#
#   python3dist(pyscaffoldext-markdown) >= 0.4
#
# We do not package the “ds” extra as a metapackage, because it has the
# following dependencies not currently packaged:
#
#   python3dist(pyscaffoldext-dsproject) >= 0.5


%prep
%autosetup -n pyscaffold-%{version} -p1

# Correct all shebangs in tests and templates
%py3_shebang_fix tests

# 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
# Since pdflatex cannot handle Unicode inputs in general:
echo "latex_engine = 'xelatex'" >> docs/conf.py
# Cannot use SVG images when building PDF documentation; rewrite to use PDFs,
# which we will generate in %%build
find docs -type f -exec \
    gawk '/\.svg/ { print FILENAME; nextfile }' '{}' '+' |
  xargs -r -t sed -r -i 's/\.svg/\.pdf/g'
# Drop “furo” HTML theme dependency, since we do not need it to build a PDF.
sed -r -i '/\bfuro\b/d' docs/requirements.txt
# Drop sphinx-github-role dependency; it is not packaged and the degradation
# without it is trivial.
sed -r -i '/\bsphinx-github-role\b/d' docs/requirements.txt
sed -r -i 's/^([[:blank:]]*)("sphinx_github_role",?)$/\1# \2/' docs/conf.py

# Cannot install “all” extra for testing
sed -r -i 's/^([[:blank:]]*)(all)\b/\1# \2/' tox.ini

# Relax the upper bound of the platformdirs dependency
sed -r -i '/\bplatformdirs\b/ s/<4/<5/' setup.cfg


%generate_buildrequires
# Missing dependencies for “all”, “md”, and “ds” extras
%pyproject_buildrequires %{?with_tests:-t} %{?with_doc_pdf:docs/requirements.txt}


%build
%pyproject_wheel

%if %{with doc_pdf}
# Cannot use SVG images when building PDF documentation; convert to PDFs
find docs -type f -name '*.svg' |
  while read -r fn
  do
    rsvg-convert --format=pdf \
        --output="$(dirname "${fn}")/$(basename "${fn}" .svg).pdf" "${fn}"
  done

PYTHONPATH="${PWD}" %make_build -C docs latex SPHINXOPTS='%{?_smp_mflags}'
%make_build -C docs/_build/latex LATEXMKOPTS='-quiet'
%endif


%install
%pyproject_install
# setup.py does not install the template files
install -p -m 0644 \
    -t '%{buildroot}/%{python3_sitelib}/pyscaffold/templates' \
    src/pyscaffold/templates/*.template
%pyproject_save_files -l pyscaffold
install -t '%{buildroot}%{_mandir}/man1' -D -p -m 0644 '%{SOURCE1}'


%check
%if %{with tests}
# Hopefully keep from overwriting user’s git config if building locally
TEST_HOME="$(mktemp -d)"
trap "rm -vrf '${TEST_HOME}'" INT TERM EXIT
export HOME="${TEST_HOME}"
# Required for a test
git config --global user.email 'jane@doe.com'
git config --global user.name 'jane doe'

# skip tests that need network access
k="${k-}${k+ and }not test_inplace_update"
k="${k-}${k+ and }not test_piptools_works_with_pyscaffold"
k="${k-}${k+ and }not test_update_version_3_0_to_3_1"
k="${k-}${k+ and }not test_update_version_3_0_to_3_1_pretend"
k="${k-}${k+ and }not test_install_packages"
k="${k-}${k+ and }not test_api_with_venv"
k="${k-}${k+ and }not test_cli_with_venv"
k="${k-}${k+ and }not test_pipenv_works_with_pyscaffold"
# We should be able to write:
#   %%tox -- -- -k "${k-}" …
# but for some reason this does not successfully collect any tests.
#
# While upstream explicitly supports running tests in parallel, we observe a
# race condition causing flaky failures in test_get_log_level in practice.
%pytest -k "${k-}" \
    --ignore=tests/test_install.py \
    --ignore=tests/system/test_common.py
%endif


%files -n python3-pyscaffold -f %{pyproject_files}
%doc CHANGELOG.rst
%doc CONTRIBUTING.rst
%doc README.rst

%{_bindir}/putup
%{_mandir}/man1/putup.1*


%files doc
%license LICENSE.txt
%if %{with doc_pdf}
%doc docs/_build/latex/user_guide.pdf
%endif


%changelog
## START: Generated by rpmautospec
* Mon Oct 21 2024 Sandro <devel@penguinpee.nl> - 4.6-1
- Update to 4.6 (RHBZ#2314240)

* Tue Oct 08 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 4.5-12
- Revert "Run tests in parallel"

* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.5-11
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Tue Jul 09 2024 Carl George <carlwgeorge@fedoraproject.org> - 4.5-10
- Relax platformdirs upper limit

* Sat Jun 08 2024 Python Maint <python-maint@redhat.com> - 4.5-9
- Rebuilt for Python 3.13

* Thu Mar 28 2024 Sandro <devel@penguinpee.nl> - 4.5-8
- Fall back to pkgutil when Python >= 3.13

* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.5-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 22 2024 Fedora Release Engineering <releng@fedoraproject.org> - 4.5-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Thu Jan 04 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 4.5-5
- Assert a license file is in .dist-info; don’t package duplicate
  AUTHORS.rst

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 4.5-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Wed Jul 12 2023 Python Maint <python-maint@redhat.com> - 4.5-3
- Rebuilt for Python 3.12

* Tue Jun 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 4.5-2
- Run tests in parallel

* Tue Jun 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 4.5-1
- Update to 4.5 (close RHBZ#2216270)

* Tue Jun 20 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 4.4.1-3
- Use new (rpm 4.17.1+) bcond style

* Sun Jun 18 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 4.4.1-2
- Improved platformdirs 3.x support
- Patch out new sphinx-github-role documentation dependency

* Fri Jun 09 2023 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 4.4.1-1
- feat: update to 4.4.1 (fixes rhbz#2090905)

* Tue May 30 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 4.2.1-8
- Link upstream PR for platformdirs 3.x from spec file

* Tue May 30 2023 Tomáš Hrnčiar <thrnciar@redhat.com> - 4.2.1-7
- Relax version constraint to allow compatibility with the latest
  platformdirs

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

* Tue Aug 23 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.2.1-5
- Use rsvg-convert instead of inkscape

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

* Sun Jul 10 2022 Python Maint <python-maint@redhat.com> - 4.2.1-3
- Rebuilt for Python 3.11

* Thu Apr 14 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.2.1-2
- Add a man page for “putup”

* Thu Apr 14 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.2.1-1
- Update to 4.2.1 (close RHBZ#2012951)

* Thu Apr 14 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-14
- Use pyproject-rpm-macros

* Thu Apr 14 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-13
- Correct License from MIT to (MIT and 0BSD)

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-12
- Hopefully keep from overwriting user’s git config if building locally

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-11
- Update URL and description from upstream

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-10
- Build documentation as PDF instead of HTML

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-9
- Do not run test coverage analysis

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-8
- No need to patch out sphinxemoji doc dependency anymore

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-7
- Lighten vim/vi and git/git-core BR’s

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-6
- Drop obsolete sed-patches

* Wed Apr 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 4.1-5
- Assorted style tweaks

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

* Sun Oct 03 2021 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 4.1-2
- chore: document dep review URL

* Sun Oct 03 2021 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 4.1-1
- feat: update to 4.1

* Tue Aug 17 2021 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 4.0.2-3
- fix: add missing BR to fix build

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

* Wed Jul 07 2021 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> 4.0.2-1
- feat: update to new version

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

* Fri Mar 19 2021 Miro Hrončok <miro@hroncok.cz> 3.2.1-9
- Make pyscaffold work with setuptools_scm 6+

* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> 3.2.1-8
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Tue Oct 27 2020 Tomas Hrnciar <thrnciar@redhat.com> 3.2.1-7
- Replace Python version glob with macro (needed for Python 3.10+)

* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> 3.2.1-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Tue May 26 2020 Miro Hrončok <miro@hroncok.cz> 3.2.1-5
- Rebuilt for Python 3.9

* Thu Jan 30 2020 Fedora Release Engineering <releng@fedoraproject.org> 3.2.1-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

* Thu Oct 03 2019 Miro Hrončok <mhroncok@redhat.com> - 3.2.1-3
- Rebuilt for Python 3.8.0rc1 (#1748018)

* Mon Aug 19 2019 Miro Hrončok <mhroncok@redhat.com> - 3.2.1-2
- Rebuilt for Python 3.8

* Mon Aug 05 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.2.1-1
- Update to 3.2.1
- Add rtd-theme

* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Sun Jan 27 2019 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.1-1
- Initial build

## END: Generated by rpmautospec