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

%global pypi_name openneuro-py
# The importable module is called 'openneuro'
%global module_name openneuro
%global forgeurl https://github.com/hoechenberger/openneuro-py

Name:           python-%{module_name}
Version:        2024.2.0
Release:        %{autorelease}
Summary:        A Python client for OpenNeuro
%forgemeta
License:        GPL-3.0-only
URL:            %forgeurl
Source:         %forgesource

# Update the typer[all] dependency to typer-slim[standard]
#
# Required for typer 0.12.1; see https://typer.tiangolo.com/release-notes/#0121
# and https://github.com/tiangolo/typer/discussions/785.
#
# https://github.com/hoechenberger/openneuro-py/pull/155
Patch:          %{forgeurl}/pull/155.patch

BuildArch:      noarch
BuildRequires:  python3-devel
# For tests
BuildRequires:  python3-pytest

%global _description %{expand:
A Python client for accessing OpenNeuro datasets.}

%description %_description


%package -n python3-%{module_name}
Summary:        %{summary}
Provides:       %{pypi_name} = %{?epoch:%{epoch}:}%{version}-%{release}

%description -n python3-%{module_name} %_description


%prep
%forgeautosetup -p1

# Exclude tests from wheel
sed -i '/^packages.*openneuro/a exclude = ["src/openneuro/tests"]' pyproject.toml


%generate_buildrequires
%pyproject_buildrequires


%build
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files -l %{module_name}

install -d \
    '%{buildroot}%{bash_completions_dir}' \
    '%{buildroot}%{zsh_completions_dir}' \
    '%{buildroot}%{fish_completions_dir}'
export PYTHONPATH='%{buildroot}%{python3_sitelib}'
export _TYPER_COMPLETE_TEST_DISABLE_SHELL_DETECTION=1
'%{buildroot}%{_bindir}/%{pypi_name}' --show-completion bash \
    > '%{buildroot}%{bash_completions_dir}/%{pypi_name}'
'%{buildroot}%{_bindir}/%{pypi_name}' --show-completion zsh \
    > '%{buildroot}%{zsh_completions_dir}/_%{pypi_name}'
'%{buildroot}%{_bindir}/%{pypi_name}' --show-completion fish \
    > '%{buildroot}%{fish_completions_dir}/%{pypi_name}.fish'


%check
# Exclude tests requiring network (they also require an API key)
k="${k-}${k+ and }not test_download"
k="${k-}${k+ and }not test_resume_download"
k="${k-}${k+ and }not test_ds000248"
k="${k-}${k+ and }not test_doi_handling"
k="${k-}${k+ and }not test_restricted_dataset"
%pytest -v ${k+-k }"${k-}"

# Also run import test since majority of tests cannot be run in mock
%pyproject_check_import


%files -n python3-%{module_name} -f %{pyproject_files}
%doc README.*
%{_bindir}/%{pypi_name}
%{bash_completions_dir}/%{pypi_name}
%{zsh_completions_dir}/_%{pypi_name}
%{fish_completions_dir}/%{pypi_name}.fish


%changelog
## START: Generated by rpmautospec
* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 2024.2.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sun Jun 09 2024 Python Maint <python-maint@redhat.com> - 2024.2.0-4
- Rebuilt for Python 3.13

* Sat Apr 06 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 2024.2.0-3
- Adjust dependencies for typer 0.12.1

* Sat Apr 06 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 2024.2.0-2
- Generate and install shell completions for bash/zsh/fish

* Mon Mar 18 2024 Sandro <devel@penguinpee.nl> - 2024.2.0-1
- Initial release (RHBZ#2257916)
- A Python client for OpenNeuro
## END: Generated by rpmautospec