Skip to content

Commit 215cbcf

Browse files
committed
Changes for generating rpm spec files for projects with data files (#545)
1 parent 52c80b7 commit 215cbcf

7 files changed

Lines changed: 156 additions & 156 deletions

File tree

data/templates/setup.py/bdist_rpm

Lines changed: 10 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,8 @@
1-
2-
3-
if not bdist_rpm:
4-
BdistRPMCommand = None
5-
else:
6-
class BdistRPMCommand(bdist_rpm):
7-
"""Custom handler for the bdist_rpm command."""
8-
9-
def _make_spec_file(self):
10-
"""Generates the text of an RPM spec file.
11-
12-
Returns:
13-
list[str]: lines of the RPM spec file.
14-
"""
15-
# Note that bdist_rpm can be an old style class.
16-
if issubclass(BdistRPMCommand, object):
17-
spec_file = super(BdistRPMCommand, self)._make_spec_file()
18-
else:
19-
spec_file = bdist_rpm._make_spec_file(self)
20-
21-
if sys.version_info[0] < 3:
22-
python_package = 'python2'
23-
else:
24-
python_package = 'python3'
25-
26-
description = []
27-
summary = ''
28-
in_description = False
29-
30-
python_spec_file = []
31-
for line in iter(spec_file):
32-
if line.startswith('Summary: '):
33-
summary = line
34-
35-
elif line.startswith('BuildRequires: '):
36-
line = 'BuildRequires: {0:s}-setuptools, {0:s}-devel'.format(
37-
python_package)
38-
39-
elif line.startswith('Requires: '):
40-
if python_package == 'python3':
41-
line = line.replace('python-', 'python3-')
42-
line = line.replace('python2-', 'python3-')
43-
44-
elif line.startswith('%description'):
45-
in_description = True
46-
47-
elif line.startswith('python setup.py build'):
48-
if python_package == 'python3':
49-
line = '%py3_build'
50-
else:
51-
line = '%py2_build'
52-
53-
elif line.startswith('python setup.py install'):
54-
if python_package == 'python3':
55-
line = '%py3_install'
56-
else:
57-
line = '%py2_install'
58-
591
elif line.startswith('%files'):
602
lines = [
613
'%files -n {0:s}-%{{name}}'.format(python_package),
624
'%defattr(644,root,root,755)',
5+
'%license ${rpm_license_file}',
636
'%doc ${rpm_doc_files}']
647

658
if python_package == 'python3':
@@ -79,15 +22,16 @@ ${python2_package_files}])
7922
python_spec_file.append(
8023
'%package -n {0:s}-%{{name}}'.format(python_package))
8124
if python_package == 'python2':
82-
python_spec_file.append(
83-
'Obsoletes: python-${project_name} < %{version}')
84-
python_spec_file.append(
85-
'Provides: python-${project_name} = %{version}')
25+
python_spec_file.extend([
26+
'Obsoletes: python-${project_name} < %{version}',
27+
'Provides: python-${project_name} = %{version}'])
28+
29+
python_spec_file.extend([
30+
'Requires: {0:s}'.format(requires),
31+
'{0:s}'.format(summary),
32+
'',
33+
'%description -n {0:s}-%{{name}}'.format(python_package)])
8634

87-
python_spec_file.append('{0:s}'.format(summary))
88-
python_spec_file.append('')
89-
python_spec_file.append(
90-
'%description -n {0:s}-%{{name}}'.format(python_package))
9135
python_spec_file.extend(description)
9236

9337
elif in_description:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
3+
if not bdist_rpm:
4+
BdistRPMCommand = None
5+
else:
6+
class BdistRPMCommand(bdist_rpm):
7+
"""Custom handler for the bdist_rpm command."""
8+
9+
def _make_spec_file(self):
10+
"""Generates the text of an RPM spec file.
11+
12+
Returns:
13+
list[str]: lines of the RPM spec file.
14+
"""
15+
# Note that bdist_rpm can be an old style class.
16+
if issubclass(BdistRPMCommand, object):
17+
spec_file = super(BdistRPMCommand, self)._make_spec_file()
18+
else:
19+
spec_file = bdist_rpm._make_spec_file(self)
20+
21+
if sys.version_info[0] < 3:
22+
python_package = 'python2'
23+
else:
24+
python_package = 'python3'
25+
26+
description = []
27+
requires = ''
28+
summary = ''
29+
in_description = False
30+
31+
python_spec_file = []
32+
for line in iter(spec_file):
33+
if line.startswith('Summary: '):
34+
summary = line
35+
36+
elif line.startswith('BuildRequires: '):
37+
line = 'BuildRequires: {0:s}-setuptools, {0:s}-devel'.format(
38+
python_package)
39+
40+
elif line.startswith('Requires: '):
41+
requires = line[10:]
42+
if python_package == 'python3':
43+
requires = requires.replace('python-', 'python3-')
44+
requires = requires.replace('python2-', 'python3-')
45+
46+
elif line.startswith('%description'):
47+
in_description = True
48+
49+
elif line.startswith('python setup.py build'):
50+
if python_package == 'python3':
51+
line = '%py3_build'
52+
else:
53+
line = '%py2_build'
54+
55+
elif line.startswith('python setup.py install'):
56+
if python_package == 'python3':
57+
line = '%py3_install'
58+
else:
59+
line = '%py2_install'
60+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
elif line.startswith('%files'):
2+
lines = [
3+
'%files -n %{name}-data',
4+
'%defattr(644,root,root,755)',
5+
'%license ${rpm_license_file}',
6+
'%doc ${rpm_doc_files}',
7+
'%{_datadir}/%{name}/*',
8+
'',
9+
'%files -n {0:s}-%{{name}}'.format(python_package),
10+
'%defattr(644,root,root,755)',
11+
'%license ${rpm_license_file}',
12+
'%doc ${rpm_doc_files}']
13+
14+
if python_package == 'python3':
15+
lines.extend([
16+
${python3_package_files}])
17+
18+
else:
19+
lines.extend([
20+
${python2_package_files}])
21+
22+
python_spec_file.extend(lines)
23+
break
24+
25+
elif line.startswith('%prep'):
26+
in_description = False
27+
28+
python_spec_file.extend([
29+
'%package -n %{name}-data',
30+
'Summary: Data files for {0:s}'.format(summary),
31+
'',
32+
'%description -n %{name}-data'])
33+
34+
python_spec_file.extend(description)
35+
36+
python_spec_file.append(
37+
'%package -n {0:s}-%{{name}}'.format(python_package))
38+
if python_package == 'python2':
39+
python_spec_file.extend([
40+
'Obsoletes: python-${project_name} < %{version}',
41+
'Provides: python-${project_name} = %{version}'])
42+
43+
python_spec_file.extend([
44+
'Requires: %{{name}}-data, {0:s}'.format(requires),
45+
'{0:s}'.format(summary),
46+
'',
47+
'%description -n {0:s}-%{{name}}'.format(python_package)])
48+
49+
python_spec_file.extend(description)
50+
51+
elif in_description:
52+
# Ignore leading white lines in the description.
53+
if not description and not line:
54+
continue
55+
56+
description.append(line)
57+
58+
python_spec_file.append(line)
59+
60+
return python_spec_file

data/templates/setup.py/bdist_rpm_package_data

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
('${data_files_path}', glob.glob(
2+
os.path.join('data', '*'))),

data/templates/setup.py/setup_data_files_data

Lines changed: 0 additions & 2 deletions
This file was deleted.

l2tdevtools/dependency_writers/setup.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ def Write(self):
164164
description_long = '\n'.join([
165165
' \'{0:s}\''.format(line) for line in description_long])
166166

167+
if self._project_definition.name == 'artifacts':
168+
data_files_path = 'share/{0:s}'.format(
169+
self._project_definition.name)
170+
else:
171+
data_files_path = 'share/{0:s}/data'.format(
172+
self._project_definition.name)
173+
167174
doc_files = [
168175
doc_file for doc_file in self._DOC_FILES if os.path.isfile(doc_file)]
169176

@@ -231,6 +238,9 @@ def Write(self):
231238
'%exclude {0:s}/*.pyc'.format(python2_package_module_prefix),
232239
'%exclude {0:s}/*.pyo'.format(python2_package_module_prefix)])
233240

241+
if scripts_directory:
242+
python2_package_files.append('%exclude %{{_bindir}}/*.py')
243+
234244
python2_package_files = ',\n'.join([
235245
' \'{0:s}\''.format(package_file)
236246
for package_file in python2_package_files])
@@ -264,13 +274,21 @@ def Write(self):
264274
python3_package_files.append(
265275
'%exclude {0:s}/__pycache__/*'.format(python3_package_module_prefix))
266276

277+
if scripts_directory:
278+
python3_package_files.append('%exclude %{{_bindir}}/*.py')
279+
267280
python3_package_files = ',\n'.join([
268281
' \'{0:s}\''.format(package_file)
269282
for package_file in python3_package_files])
270283
python3_package_files = python3_package_files.format(
271284
self._project_definition.name)
272285

286+
rpm_doc_files = [
287+
doc_file for doc_file in doc_files if doc_file != 'LICENSE']
288+
rpm_license_file = 'LICENSE'
289+
273290
template_mappings = {
291+
'data_files_path': data_files_path,
274292
'doc_files': ', '.join([
275293
'\'{0:s}\''.format(doc_file) for doc_file in doc_files]),
276294
'description_long': description_long,
@@ -284,7 +302,8 @@ def Write(self):
284302
'project_name': self._project_definition.name,
285303
'python2_package_files': python2_package_files,
286304
'python3_package_files': python3_package_files,
287-
'rpm_doc_files': ' '.join(doc_files),
305+
'rpm_doc_files': ' '.join(rpm_doc_files),
306+
'rpm_license_file': rpm_license_file,
288307
'scripts_directory': scripts_directory,
289308
}
290309

@@ -324,13 +343,13 @@ def Write(self):
324343
'import_sdist', template_mappings)
325344
file_content.append(template_data)
326345

327-
for template_file in ('import_module', 'bdist_msi'):
346+
for template_file in ('import_module', 'bdist_msi', 'bdist_rpm-start'):
328347
template_data = self._GenerateFromTemplate(
329348
template_file, template_mappings)
330349
file_content.append(template_data)
331350

332-
if self._project_definition.name in self._PROJECTS_WITH_PACKAGE_DATA:
333-
template_file = 'bdist_rpm_package_data'
351+
if os.path.isdir('data'):
352+
template_file = 'bdist_rpm-with_data'
334353
else:
335354
template_file = 'bdist_rpm'
336355

@@ -369,7 +388,7 @@ def Write(self):
369388

370389
if os.path.isdir('data'):
371390
template_data = self._GenerateFromTemplate(
372-
'setup_data_files_data', template_mappings)
391+
'setup_data_files-with_data', template_mappings)
373392
file_content.append(template_data)
374393

375394
template_data = self._GenerateFromTemplate(

0 commit comments

Comments
 (0)