Merge pull request #957 from danigm/python-sitelib-glob

SpecCheck: Add python_sitelib glob check
This commit is contained in:
Martin Liška 2022-10-27 11:03:40 +02:00 committed by GitHub
commit d1f4307541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 180 additions and 0 deletions

View File

@ -80,6 +80,7 @@ tarball_regex = re.compile(r'\.(?:t(?:ar|[glx]z|bz2?)|zip)\b', re.IGNORECASE)
python_setup_test_regex = re.compile(r'^[^#]*(setup.py test)')
python_module_def_regex = re.compile(r'^[^#]*%{\?!python_module:%define python_module()')
python_sitelib_glob_regex = re.compile(r'^[^#]*%{python_site(lib|arch)}/\*\s*$')
UNICODE_NBSP = '\xa0'
@ -366,6 +367,7 @@ class SpecCheck(AbstractCheck):
self._checkline_macros_in_comments(line)
self._checkline_python_setup_test(line)
self._checkline_python_module_def(line)
self._checkline_python_sitelib_glob(line)
# If statement, starts
if ifarch_regex.search(line):
@ -751,3 +753,12 @@ class SpecCheck(AbstractCheck):
"""
if python_module_def_regex.search(line):
self.output.add_info('W', self.pkg, 'python-module-def', line[:-1])
def _checkline_python_sitelib_glob(self, line):
"""Test if %{python_sitelib}/* is present in %files section."""
if self.current_section != 'files':
return
if python_sitelib_glob_regex.match(line):
self.output.add_info('W', self.pkg, 'python-sitelib-glob-in-files',
line[:-1])

View File

@ -194,3 +194,10 @@ macro is present in recent versions of python-rpm-macros.
The following conditional python_module macro definition can be removed:
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
"""
python-sitelib-glob-in-files="""
The %files section contains "%{python_sitelib}/*" or "%{python_sitearch}/*"
that can get something not wanted in the package. Please use a more specific
file path like:
%{python_sitelib}/packagename
%{python_sitelib}/packagename-%{version}*-info
"""

View File

@ -0,0 +1,45 @@
#
# spec file for package python-sitearch-glob
#
# Copyright (c) specCURRENT_YEAR SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: python-sitearch-glob
Version: 0.1
Release: 0
Summary: Cool Python package
License: GPL-2.0-or-later
# FIXME: use correct group, see "https://en.opensuse.org/openSUSE:Package_group_guidelines"
Group: Development/Libraries/Python
Url: http://rpmlint.zarb.org/#%{name}
BuildRequires: python-rpm-macros
%{python_subpackages}
%description
Cool Python Package
%prep
%autosetup -p1
%build
%python_build
%install
%python_install
%files %{python_files}
%{python_sitearch}/*
%changelog

View File

@ -0,0 +1,46 @@
#
# spec file for package python-sitelib-glob
#
# Copyright (c) specCURRENT_YEAR SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: python-sitelib-glob
Version: 0.1
Release: 0
Summary: Cool Python package
License: GPL-2.0-or-later
# FIXME: use correct group, see "https://en.opensuse.org/openSUSE:Package_group_guidelines"
Group: Development/Libraries/Python
Url: http://rpmlint.zarb.org/#%{name}
BuildRequires: python-rpm-macros
%{python_subpackages}
%description
Cool Python Package
%prep
%autosetup -p1
%build
%python_build
%install
%python_install
%files %{python_files}
%{python_sitelib}/*
%changelog

View File

@ -0,0 +1,48 @@
#
# spec file for package python-sitelib
#
# Copyright (c) specCURRENT_YEAR SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: python-sitelib
Version: 0.1
Release: 0
Summary: Cool Python package
License: GPL-2.0-or-later
# FIXME: use correct group, see "https://en.opensuse.org/openSUSE:Package_group_guidelines"
Group: Development/Libraries/Python
Url: http://rpmlint.zarb.org/#%{name}
BuildRequires: python-rpm-macros
%{python_subpackages}
%description
Cool Python Package
%prep
%autosetup -p1
%build
%python_build
%install
%python_install
%files %{python_files}
%{python_sitelib}/sitelib
%{python_sitelib}/sitelib/*
%{python_sitelib}/sitelib-%{version}*-info
%changelog

View File

@ -1129,3 +1129,26 @@ def test_python_module_definition_not_present(package, speccheck):
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-module-def' not in out
@pytest.mark.parametrize('package', [
'spec/python-sitelib-glob',
'spec/python-sitearch-glob',
])
def test_python_sitelib_glob(package, speccheck):
"""Test if %{python_sitelib}/* is present in %files section."""
output, test = speccheck
pkg = get_tested_spec_package(package)
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-sitelib-glob-in-files' in out
@pytest.mark.parametrize('package', ['spec/python-sitelib'])
def test_python_sitelib(package, speccheck):
"""Test if %{python_sitelib}/* is present in %files section."""
output, test = speccheck
pkg = get_tested_spec_package(package)
test.check_spec(pkg)
out = output.print_results(output.results)
assert 'W: python-sitelib-glob-in-files' not in out