## 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

Name:           python-watchfiles
Version:        1.0.3
Release:        %autorelease
Summary:        Simple, modern and high performance file watching and code reload in python
# The main source code is under the MIT license.
#
# The forked notify crate source is under the CC0-1.0 license. This is
# not-allowed for code in Fedora, but the rust-notify package has been in
# Fedora long enough that this falls under the following blanket 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
#
# The forked notify-types crate source is (MIT OR Apache-2.0).
#
# See the license field of the python3-watchfiles subpackage for the licenses
# of statically linked rust dependencies.
License:        MIT AND CC0-1.0 AND (MIT OR Apache-2.0)
URL:            https://github.com/samuelcolvin/watchfiles
Source0:        %{pypi_source watchfiles}
# Currently, watchfiles uses a fork of the notify crate. We asked upstream
# about a path to using a published version of notify in
# https://github.com/samuelcolvin/watchfiles/issues/312#issuecomment-2567264301.
#
# For now, we must therefore bundle the fork as prescribed in
#   https://docs.fedoraproject.org/en-US/packaging-guidelines/Rust/#_replacing_git_dependencies
#
# The dependency is on the keep-io-error branch of the fork
# https://github.com/samuelcolvin/notify; we reference the commit at the head
# of that branch at the time of packaging.
%global notify_url https://github.com/samuelcolvin/notify
%global notify_rev 0f87ab12707d231fa44180454d59478d3992eb59
%global notify_baseversion 6.1.1
%global notify_snapdate 20240826
%global notify_types_baseversion 1.0.0
# From README.md:
#   Notify is licensed under the [CC Zero 1.0][cc0].
#   notify-debouncer-mini is licensed under the [MIT] or [Apache-2.0][apache] license.
#   notify-debouncer-full is licensed under the [MIT] or [Apache-2.0][apache] license.
#   file-id is licensed under the [MIT] or [Apache-2.0][apache] license.
# Also, from file headers,
#   tests/serialise-events.rs and notify-types/src/event.rs are (Artistic-2.0 OR CC0-1.0)
%dnl Source100:      %{notify_url}/archive/%{notify_rev}/notify-%{notify_rev}.tar.gz
# To sidestep serious difficulties with unwanted workspace dependencies, and to
# avoid bringing in unwanted CC0-1.0-licensed code, we use the script in
# Source100 to generate a crate sources corresponding only to the forked
# notify/notify-types crates we need to bundle, as if they were published to
# crates.io, without any cross-references to a workspace Cargo.toml.
#
# This reads notify_* macros from the spec file in the same directory; just run
# ./gen_notify_crates.sh to obtain the crate.
#
# This script requires cargo, tomcli, and network access.
Source100:      gen_notify_crates.sh
%global notify_snapinfo %{notify_snapdate}git%{sub %{notify_rev} 1 7}
%global notify_version %{notify_baseversion}^%{notify_snapinfo}
# License: CC0-1.0
Source101:      notify-%{notify_version}.crate
%global notify_types_version %{notify_types_baseversion}^%{notify_snapinfo}
# License: (MIT OR Apache-2.0)
Source102:      notify-types-%{notify_types_version}.crate

# These patches are for the forked, bundled notify crate.
#
# * Remove "foreign" dependencies associated with other platforms
# * Remove macOS-specific features
Patch100:       notify-fix-metadata.diff

BuildRequires:  python3-devel
BuildRequires:  cargo-rpm-macros >= 24
BuildRequires:  tomcli

%global _description %{expand:
Simple, modern and high performance file watching and code reload in python.
Underlying file system notifications are handled by the Notify rust library.}


%description %_description


%package -n python3-watchfiles
Summary:        %{summary}
# The main source code is under the MIT license. This license field includes
# the license of the bundled notify fork (CC0-1.0), the license of the bundled
# notify-types fork (MIT OR Apache-2.0), and the licenses of statically linked
# rust dependencies, based on the output of %%{cargo_license_summary}:
#
# Apache-2.0 OR MIT
# BSD-3-Clause
# CC0-1.0
# ISC
# MIT
# MIT OR Apache-2.0
# Unlicense OR MIT
License:        %{shrink:
                MIT AND
                BSD-3-Clause AND
                CC0-1.0 AND
                ISC AND
                (MIT OR Apache-2.0) AND
                (Unlicense OR MIT)
                }

# These are forks of rust-notify and rust-notify-types; see the notes about
# Source100-Source102.
Provides:       bundled(crate(notify)) = %{notify_version}
Provides:       bundled(crate(notify-types)) = %{notify_types_version}


%description -n python3-watchfiles %_description


%prep
%autosetup -n watchfiles-%{version} -N
# Patches for the base package, if any:
%dnl %autopatch -p1 -M99

# Remove unnecessary Python test requirements
sed -e '/^coverage\b/d' \
    -e '/^pytest-pretty\b/d' \
    -e '/^pytest-timeout\b/d' \
    -i requirements/testing.in

# Remove pytest timeout config
tomcli set pyproject.toml del tool.pytest.ini_options.timeout

# Remove "generate-import-lib" feature for pyo3; applicable only on Windows,
# and not packaged.
tomcli set Cargo.toml lists delitem dependencies.pyo3.features \
    generate-import-lib

# Remove unused Cargo config that contains buildflags for Darwin
rm .cargo/config.toml

# See comments above Source100:
%setup -q -T -D -b 101 -n watchfiles-%{version}
ln -s '../notify-%{notify_baseversion}' notify
pushd notify
%autopatch -p1 -m100 -M199
# Switch the version dependency on notify-types back to a path one
tomcli set Cargo.toml str dependencies.notify-types.path ../notify-types
tomcli set Cargo.toml del dependencies.notify-types.version
popd
cp -p notify/LICENSE-CC0 LICENSE-notify-CC0

%setup -q -T -D -b 102 -n watchfiles-%{version}
ln -s '../notify-types-%{notify_types_baseversion}' notify-types
cp -p notify-types/LICENSE-APACHE LICENSE-notify-types-APACHE
cp -p notify-types/LICENSE-MIT LICENSE-notify-types-MIT

# Convert the git dependency on notify to a path one
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Rust/#_replacing_git_dependencies
tomcli set Cargo.toml str dependencies.notify.path notify
tomcli set Cargo.toml del dependencies.notify.git
tomcli set Cargo.toml del dependencies.notify.branch

%cargo_prep


%generate_buildrequires
%pyproject_buildrequires requirements/testing.in
pushd notify-types >/dev/null
%cargo_generate_buildrequires
popd >/dev/null
pushd notify >/dev/null
%cargo_generate_buildrequires
popd >/dev/null
%cargo_generate_buildrequires


%build
%cargo_license_summary
%{cargo_license} > LICENSES.dependencies

export RUSTFLAGS='%{build_rustflags}'
%pyproject_wheel


%install
%pyproject_install
%pyproject_save_files watchfiles

# The maturin build backend includes the license files, but currently the
# pyproject macros don't mark these files as licenses.
sed -e '/LICENSE/ s/^/%%license /' -i %{pyproject_files}


%check
# We must set the import mode during tests to avoid the watchfiles directory
# (which will not have the compiled module) taking precedence for the import.
# https://docs.pytest.org/en/7.4.x/explanation/pythonpath.html
%pytest --import-mode append -v


%files -n python3-watchfiles -f %{pyproject_files}
%doc README.md
%{_bindir}/watchfiles


%changelog
## START: Generated by rpmautospec
* Thu Jan 02 2025 Benjamin A. Beasley <code@musicinmybrain.net> - 1.0.3-1
- Update to 1.0.3

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

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

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

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

* Sun Sep 24 2023 Carl George <carlwgeorge@fedoraproject.org> - 0.20.0-1
- Initial package, resolves rhbz#2240154
## END: Generated by rpmautospec