Skip to content

Commit e7d738f

Browse files
committed
Add %pyproject_check_import
1 parent 4588340 commit e7d738f

5 files changed

+190
-6
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ positional arguments:
3535
options:
3636
-h, --help show this help message and exit
3737
-l, --list-modifiers list all available modifiers and exit
38-
-i MODIFIER, --info MODIFIER
39-
display documentation for given modifier
40-
-x MODIFIER [MODIFIER ...], --exclude MODIFIER [MODIFIER ...]
38+
-i, --info MODIFIER display documentation for given modifier
39+
-x, --exclude MODIFIER [MODIFIER ...]
4140
exclude given modifier
42-
-o MODIFIER, --only MODIFIER
43-
run only one given modifier
44-
-s SOURCEDIR, --sourcedir SOURCEDIR
41+
-o, --only MODIFIER run only one given modifier
42+
-s, --sourcedir SOURCEDIR
4543
path to the source directory, relevant for %include etc. (default: spec's parent)
4644
4745
If you wish to process multiple specfiles at a time, run this tool via parallel, etc. If you wish to
@@ -55,6 +53,7 @@ $ python pyprojectize.py ampy.spec # 16a7deeb
5553
✅ py3_install_to_pyproject_install: replaced %py3_install with %pyproject_install in %install
5654
✅ egginfo_to_distinfo: replaced .egg-info with .dist-info in %files
5755
✅ add_pyproject_files: %{python3_sitelib}/%{python3_sitearch} lines replaced with %{pyproject_files}
56+
✅ add_pyproject_check_import: existing %check prepended with %pyproject_check_import
5857
👌 update_extras_subpkg: %{?python_extras_subpkg:%python_extras_subpkg ...} not found
5958
✅ remove_python_provide: %python_provide removed or replaced with %py_provides
6059
✅ remove_python_enable_dependency_generator: %python_enable_dependency_generator removed
@@ -127,6 +126,13 @@ In case the `%license` files match patterns recognized by setuptools' defaults,
127126
uses `%pyproject_save_files` with `-l` and removes them.
128127

129128

129+
### add_pyproject_check_import
130+
131+
If `%pyproject_save_files` is used in `%install` and `%pyproject_check_import`
132+
is not used in `%check`, add `%pyproject_check_import` to the beginning of `%check`
133+
(create the section if needed).
134+
135+
130136
### update_extras_subpkg
131137

132138
Replace `%python_extras_subpkg -i ...` with `%pyproject_extras_subpkg`,

pyprojectize.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,53 @@ def add_pyproject_files(spec: Specfile, sections: Sections) -> ResultMsg:
471471
)
472472

473473

474+
@register
475+
def add_pyproject_check_import(spec: Specfile, sections: Sections) -> ResultMsg:
476+
"""
477+
If `%pyproject_save_files` is used in `%install` and `%pyproject_check_import`
478+
is not used in `%check`, add `%pyproject_check_import` to the beginning of `%check`
479+
(create the section if needed).
480+
"""
481+
if "install" not in sections:
482+
return Result.ERROR, "no %install section"
483+
for idx, line in enumerate(sections.install):
484+
if re.search(r"(?<!%)%({\??)?pyproject_save_files\b", line):
485+
break
486+
else:
487+
return (
488+
Result.NOT_IMPLEMENTED,
489+
"%install does not use %pyproject_save_files",
490+
)
491+
492+
if "check" not in sections:
493+
endlines = 0
494+
for line in reversed(sections.install):
495+
if line.strip():
496+
break
497+
endlines += 1
498+
pci = ["%pyproject_check_import"] + [""] * endlines
499+
check = Section("check", data=pci)
500+
index = sections.index(sections.install) + 1
501+
sections.insert(index, check)
502+
return (
503+
Result.UPDATED,
504+
"%check with %pyproject_check_import added",
505+
)
506+
507+
for line in sections.check:
508+
if re.search(r"(?<!%)%({\??)?pyproject_check_import\b", line):
509+
return (
510+
Result.NOT_NEEDED,
511+
"%check already has %pyproject_check_import",
512+
)
513+
514+
sections.check[:0] = ["%pyproject_check_import", ""]
515+
return (
516+
Result.UPDATED,
517+
"existing %check prepended with %pyproject_check_import",
518+
)
519+
520+
474521
@register
475522
def update_extras_subpkg(spec: Specfile, sections: Sections) -> ResultMsg:
476523
"""

tests/__all__.spec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export CYTHON_COMPILE=1
4747

4848

4949
%check
50+
%pyproject_check_import
51+
5052
%{__python3} setup.py test
5153

5254

tests/add_pyproject_check_import.spec

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Created by pyp2rpm-3.2.2
2+
%global srcname XwhyZ
3+
%global modname xyz
4+
Name: python-%{srcname}
5+
Version: 3.2.1.0
6+
Release: %autorelease
7+
Summary: Blah blah blah
8+
License: MIT
9+
URL: https://github.com/hroncok/pyprojectize
10+
Source0: %{pypi_source}
11+
BuildArch: noarch
12+
13+
BuildRequires: python3-devel
14+
BuildRequires: python3-setuptools
15+
BuildRequires: python3-setuptools_scm
16+
17+
%?python_enable_dependency_generator
18+
19+
%description
20+
This is an artificial spec file created for testing purposes.
21+
22+
23+
%package -n python3-%{srcname}
24+
Summary: %{summary}
25+
Provides: python3-%{modname} = %{version}-%{release}
26+
%{?python_provide:%python_provide python3-%{srcname}}
27+
%{?python_provide:%python_provide python3-%{modname}}
28+
29+
%description -n python3-%{srcname}
30+
...
31+
32+
%{?python_extras_subpkg:%python_extras_subpkg -n python3-%{srcname} -i %{python3_sitelib}/*.egg-info cool}
33+
34+
35+
%prep
36+
%autosetup -n %{srcname}-%{version}
37+
# Remove bundled egg-info
38+
rm -rf %{srcname}.egg-info
39+
40+
41+
%build
42+
CYTHON_COMPILE=1 %py3_build -- --use-the-force-luke
43+
44+
45+
%install
46+
#%%py3_install
47+
48+
%{?with_python3:%py3_install}
49+
50+
51+
%check
52+
%{__python3} setup.py test
53+
54+
55+
%files -n python3-%{srcname}
56+
%doc README.md
57+
%license LICENSE
58+
%{_bindir}/%{srcname}
59+
%{python3_sitelib}/%{modname}/
60+
%pycached %{python3_sitelib}/_%{modname}.py
61+
%{python3_sitelib}/%{srcname}-%{version}-py%{python3_version}.egg-info
62+
63+
64+
%changelog
65+
%autochangelog
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Created by pyp2rpm-3.2.2
2+
%global srcname XwhyZ
3+
%global modname xyz
4+
Name: python-%{srcname}
5+
Version: 3.2.1.0
6+
Release: %autorelease
7+
Summary: Blah blah blah
8+
License: MIT
9+
URL: https://github.com/hroncok/pyprojectize
10+
Source0: %{pypi_source}
11+
BuildArch: noarch
12+
13+
BuildRequires: python3-devel
14+
BuildRequires: python3-setuptools
15+
BuildRequires: python3-setuptools_scm
16+
17+
%?python_enable_dependency_generator
18+
19+
%description
20+
This is an artificial spec file created for testing purposes.
21+
22+
23+
%package -n python3-%{srcname}
24+
Summary: %{summary}
25+
Provides: python3-%{modname} = %{version}-%{release}
26+
%{?python_provide:%python_provide python3-%{srcname}}
27+
%{?python_provide:%python_provide python3-%{modname}}
28+
29+
%description -n python3-%{srcname}
30+
...
31+
32+
%{?python_extras_subpkg:%python_extras_subpkg -n python3-%{srcname} -i %{python3_sitelib}/*.egg-info cool}
33+
34+
35+
%prep
36+
%autosetup -n %{srcname}-%{version}
37+
# Remove bundled egg-info
38+
rm -rf %{srcname}.egg-info
39+
40+
41+
%build
42+
CYTHON_COMPILE=1 %py3_build -- --use-the-force-luke
43+
44+
45+
%install
46+
#%%py3_install
47+
48+
%{?with_python3:%pyproject_install}
49+
%pyproject_save_files -l %{modname} _%{modname}
50+
51+
52+
%check
53+
%pyproject_check_import
54+
55+
%{__python3} setup.py test
56+
57+
58+
%files -n python3-%{srcname} -f %{pyproject_files}
59+
%doc README.md
60+
%{_bindir}/%{srcname}
61+
62+
63+
%changelog
64+
%autochangelog

0 commit comments

Comments
 (0)