rpm-software-management / spec-cleaner

spec-cleaner
BSD 3-Clause "New" or "Revised" License
27 stars 33 forks source link

[1.2.0] Crash if remove "}" from BuildRequires in python .spec file #284

Closed kevinsmia1939 closed 3 years ago

kevinsmia1939 commented 3 years ago

Hello,

Spec-cleaner crash when I remove } from spec file. openSUSE Tumbleweed KDE spec-cleaner version 1.2.0

Example:

#
# spec file for package python-felicette
#
# Copyright (c) 2020 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#

%define packagename felicette
%define skip_python2 1
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name:           python-felicette
Version:        0.1.9
Release:        0
Summary:        Generate JPEG earth imagery from coordinates/location name with publicly available satellite data.
License:        MIT
Group:          Development/Languages/Python
URL:            https://github.com/plant99/felicette
Source:         https://files.pythonhosted.org/packages/a2/f/felicette/felicette-%{version}.tar.gz
BuildRequires:  %{python_module click >= 7.1.2
BuildRequires:  %{python_module numpy >= 1.19.1}
BuildRequires:  %{python_module opencv >= 4.3.0}
BuildRequires:  %{python_module pillow >= 7.2.0}
BuildRequires:  %{python_module pytest}
BuildRequires:  %{python_module rasterio >= 1.1.5}
BuildRequires:  %{python_module requests >= 2.24.0}
BuildRequires:  %{python_module rich >= 3.3.2}
BuildRequires:  %{python_module rio-color >= 1.0.0}
BuildRequires:  %{python_module sat-search >= 0.2.3}
BuildRequires:  %{python_module setuptools}
BuildRequires:  %{python_module tqdm >= 4.48.0}
BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
Requires:       python-click >= 7.1.2
Requires:       python-numpy >= 1.19.1
Requires:       python-opencv >= 4.3.0
Requires:       python-pillow >= 7.2.0
Requires:       python-rasterio >= 1.1.5
Requires:       python-requests >= 2.24.0
Requires:       python-rich >= 3.3.2
Requires:       python-rio-color >= 1.0.0
Requires:       python-sat-search >= 0.2.3
Requires:       python-tqdm >= 4.48.0
BuildArch:      noarch
%python_subpackages

%description
Generate JPEG earth imagery from coordinates/location name with publicly
available satellite data.

%prep
%setup -q -n %{packagename}-%{version}

%build
%python_build

%install
%python_install
%python_expand %fdupes %{buildroot}%{$python_sitelib}

%check
%pytest

%files %{python_files}
%doc README.md
%license LICENSE
%dir %{_datadir}/%{packagename}/
%{python_sitelib}/*egg-info/
%{python_sitelib}/%{packagename}

%changelog

Noticed the BuildRequires: %{python_module click >= 7.1.2

The error is

Traceback (most recent call last):
  File "/usr/bin/spec-cleaner", line 11, in <module>
    load_entry_point('spec-cleaner==1.2.0', 'console_scripts', 'spec-cleaner')()
  File "/usr/lib/python3.8/site-packages/spec_cleaner/__init__.py", line 163, in main
    cleaner.run()
  File "/usr/lib/python3.8/site-packages/spec_cleaner/rpmcleaner.py", line 390, in run
    self.current_section.add(line)
  File "/usr/lib/python3.8/site-packages/spec_cleaner/rpmpreamble.py", line 659, in add
    self._add_line_value_to(category, match.group(len(match.groups())))
  File "/usr/lib/python3.8/site-packages/spec_cleaner/rpmpreamble.py", line 334, in _add_line_value_to
    values = self._fix_list_of_packages(value, category)
  File "/usr/lib/python3.8/site-packages/spec_cleaner/rpmpreamble.py", line 291, in _fix_list_of_packages
    tokens = DependencyParser(value).flat_out()
  File "/usr/lib/python3.8/site-packages/spec_cleaner/dependency_parser.py", line 151, in __init__
    self.string, self.next, self.next_type = read_next_chunk(self.string)
  File "/usr/lib/python3.8/site-packages/spec_cleaner/dependency_parser.py", line 116, in read_next_chunk
    chunk, rest = read_macro(string)
  File "/usr/lib/python3.8/site-packages/spec_cleaner/dependency_parser.py", line 85, in read_macro
    return find_end_of_bracketed_macro(string, re_brackets[opening], opening, closing)
  File "/usr/lib/python3.8/site-packages/spec_cleaner/dependency_parser.py", line 53, in find_end_of_bracketed_macro
    raise Exception('Unexpectedly met end of string when looking for end of macro')
Exception: Unexpectedly met end of string when looking for end of macro

Could spec-file be made to add } automatically? Thanks

scarabeusiv commented 3 years ago

Nope spec-cleaner really can't know where the bracket could be added, in theory you can even have more of them than one per line, and as it is lua embedded code there is no chance of expansion. Simply put the braces need to be balanced in the whole file. It will crash even in rpmbuild so there is not much more we can do.

kevinsmia1939 commented 3 years ago

ok thanks