diff --git a/README.md b/README.md index 815f2ce..8e2dd5d 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,14 @@ However, in Fedora packages, always list executables explicitly to avoid uninten %doc README.rst %{_bindir}/downloader +If the package has no Python modules in it, you can explicitly use `-M` to denote that. + + %install + %pyproject_install + %pyproject_save_files -M + +Otherwise, at least one module-glob argument is required. + `%pyproject_save_files` can automatically mark license files with `%license` macro and language (`*.mo`) files with `%lang` macro and appropriate language code. Only license files declared via [PEP 639] `License-File` field are detected. diff --git a/macros.pyproject b/macros.pyproject index aa6ae73..e5aedd9 100644 --- a/macros.pyproject +++ b/macros.pyproject @@ -122,7 +122,7 @@ fi # https://github.com/rpm-software-management/rpm/issues/1749#issuecomment-1020420616 # Since we support both ways, we pass either 4.19 or 4.18 to the script, so it knows which one to use # Rather than passing the actual version, we let RPM compare the versions, as it is easier done here than in Python -%pyproject_save_files(lL) %{expand:\\\ +%pyproject_save_files(lLM) %{expand:\\\ %{expr:v"0%{?rpmversion}" >= v"4.18.90" ? "RPM_FILES_ESCAPE=4.19" : "RPM_FILES_ESCAPE=4.18" } \\ %{__python3} %{_rpmconfigdir}/redhat/pyproject_save_files.py \\ --output-files "%{pyproject_files}" \\ diff --git a/pyproject-rpm-macros.spec b/pyproject-rpm-macros.spec index cc8e85b..3b05197 100644 --- a/pyproject-rpm-macros.spec +++ b/pyproject-rpm-macros.spec @@ -14,8 +14,8 @@ License: MIT # Increment Y and reset Z when new macros or features are added # Increment Z when this is a bugfix or a cosmetic change # Dropping support for EOL Fedoras is *not* considered a breaking change -Version: 1.16.4 -Release: 2%{?dist} +Version: 1.17.0 +Release: 1%{?dist} # Macro files Source001: macros.pyproject @@ -167,6 +167,10 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856 %changelog +* Thu Jan 30 2025 Miro HronĨok - 1.17.0-1 +- Add the -M flag to %%pyproject_save_files +- The flag can be used to indicate no Python modules should be saved + * Sat Jan 18 2025 Fedora Release Engineering - 1.16.4-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild diff --git a/pyproject_save_files.py b/pyproject_save_files.py index 93de7a2..dd6b05c 100644 --- a/pyproject_save_files.py +++ b/pyproject_save_files.py @@ -614,8 +614,10 @@ def generate_file_list(paths_dict, module_globs, include_others=False): # Users using '*' don't care about the files in the package, so it's ok # not to fail the build when no modules are detected # There can be legitimate reasons to create a package without Python modules - if not modules and fnmatch.fnmatchcase("", glob): - done_globs.add(glob) + if not modules: + for glob in module_globs: + if fnmatch.fnmatchcase("", glob): + done_globs.add(glob) missed = module_globs - done_globs if missed: @@ -782,7 +784,7 @@ def dist_metadata(buildroot, record_path): return dist.metadata -def pyproject_save_files_and_modules(buildroot, sitelib, sitearch, python_version, pyproject_record, prefix, assert_license, varargs): +def pyproject_save_files_and_modules(buildroot, sitelib, sitearch, python_version, pyproject_record, prefix, assert_license, allow_no_modules, varargs): """ Takes arguments from the %{pyproject_save_files} macro @@ -797,6 +799,15 @@ def pyproject_save_files_and_modules(buildroot, sitelib, sitearch, python_versio sitedirs = sorted({sitelib, sitearch}) globs, include_auto = parse_varargs(varargs) + if not globs and not allow_no_modules: + raise ValueError( + "At least one module glob needs to be provided to %pyproject_save_files. " + "Alternatively, use -M to indicate no Python modules should be saved." + ) + if globs and allow_no_modules: + raise ValueError( + "%pyproject_save_files -M cannot be used together with module globs." + ) parsed_records = load_parsed_record(pyproject_record) final_file_list = [] @@ -840,6 +851,7 @@ def main(cli_args): cli_args.pyproject_record, cli_args.prefix, cli_args.assert_license, + cli_args.allow_no_modules, cli_args.varargs, ) @@ -853,7 +865,7 @@ def argparser(): prog="%pyproject_save_files", add_help=False, # custom usage to add +auto - usage="%(prog)s [-l|-L] MODULE_GLOB [MODULE_GLOB ...] [+auto]", + usage="%(prog)s [-l|-L] MODULE_GLOB|-M [MODULE_GLOB ...] [+auto]", ) parser.add_argument( '--help', action='help', @@ -878,7 +890,11 @@ def argparser(): help="Don't fail when no License-File (PEP 639) is found (the default).", ) parser.add_argument( - "varargs", nargs="+", metavar="MODULE_GLOB", + "-M", "--allow-no-modules", action="store_true", default=False, + help="Don't fail when no globs are provided, only include non-modules data in the generated filelist.", + ) + parser.add_argument( + "varargs", nargs="*", metavar="MODULE_GLOB", help="Shell-like glob matching top-level module names to save into %%{pyproject_files}", ) return parser diff --git a/tests/python-coverage-pth.spec b/tests/python-coverage-pth.spec new file mode 100644 index 0000000..e947899 --- /dev/null +++ b/tests/python-coverage-pth.spec @@ -0,0 +1,50 @@ +Name: python-coverage-pth +Version: 0.0.2 +Release: 0%{?dist} +Summary: Coverage PTH file to enable coverage at the virtualenv level +License: BSD +URL: https://github.com/dougn/coverage_pth +Source: %{pypi_source coverage_pth} + +BuildArch: noarch +BuildRequires: python3-devel + +%description +This package exists to test %%pyproject_save_files -M. +It contains no Python modules, just a single .pth file. + + +%package -n python3-coverage-pth +Summary: %{summary} + +%description -n python3-coverage-pth +... + + +%prep +%autosetup -p1 -n coverage_pth-%{version} +# support multi-digit Python versions in setup.py regexes +sed -i 's/d)/d+)/' setup.py + + +%generate_buildrequires +%pyproject_buildrequires + + +%build +%pyproject_wheel + + +%install +%pyproject_install + +# internal check for our macros: +# this should not work without -M +%pyproject_save_files -L && exit 1 || true + +# but this should: +%pyproject_save_files -LM + + +%files -n python3-coverage-pth -f %{pyproject_files} +%{python3_sitelib}/coverage_pth.pth diff --git a/tests/tests.yml b/tests/tests.yml index c795324..3fbff89 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -94,6 +94,9 @@ - virtualenv: dir: . run: ./mocktest.sh python-virtualenv + - coverage_pth: + dir: . + run: ./mocktest.sh python-coverage-pth - pello: dir: . run: ./mocktest.sh python-pello