Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
314bb85f
Commit
314bb85f
authored
Feb 28, 2009
by
Tarek Ziadé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issues #1533164 and #5378: Added quiet and force-optimize options to Distutils bdist_rpm command
parent
8ac6d0fd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
179 additions
and
6 deletions
+179
-6
command/bdist_rpm.py
command/bdist_rpm.py
+30
-6
tests/test_bdist_rpm.py
tests/test_bdist_rpm.py
+149
-0
No files found.
command/bdist_rpm.py
View file @
314bb85f
...
...
@@ -123,10 +123,21 @@ class bdist_rpm (Command):
# Allow a packager to explicitly force an architecture
(
'force-arch='
,
None
,
"Force an architecture onto the RPM build process"
),
(
'quiet'
,
'q'
,
"Run the INSTALL phase of RPM building in quiet mode"
),
# Forces the -O1 option when calling the install command,
# so the rpm contains all files needed for proper operation under
# SELinux. Some systems checks for this on build-time and will
# fail without this.
(
'force-optimize'
,
None
,
"Forces the -O1 option when calling the install command"
),
]
boolean_options
=
[
'keep-temp'
,
'use-rpm-opt-flags'
,
'rpm3-mode'
,
'no-autoreq'
]
'no-autoreq'
,
'quiet'
,
'force-optimize'
]
negative_opt
=
{
'no-keep-temp'
:
'keep-temp'
,
'no-rpm-opt-flags'
:
'use-rpm-opt-flags'
,
...
...
@@ -176,6 +187,8 @@ class bdist_rpm (Command):
self
.
no_autoreq
=
0
self
.
force_arch
=
None
self
.
quiet
=
0
self
.
force_optimize
=
1
# initialize_options()
...
...
@@ -322,6 +335,7 @@ class bdist_rpm (Command):
if
os
.
path
.
exists
(
'/usr/bin/rpmbuild'
)
or
\
os
.
path
.
exists
(
'/bin/rpmbuild'
):
rpm_cmd
=
[
'rpmbuild'
]
if
self
.
source_only
:
# what kind of RPMs?
rpm_cmd
.
append
(
'-bs'
)
elif
self
.
binary_only
:
...
...
@@ -333,6 +347,10 @@ class bdist_rpm (Command):
'_topdir %s'
%
os
.
path
.
abspath
(
self
.
rpm_base
)])
if
not
self
.
keep_temp
:
rpm_cmd
.
append
(
'--clean'
)
if
self
.
quiet
:
rpm_cmd
.
append
(
'--quiet'
)
rpm_cmd
.
append
(
spec_path
)
# Determine the binary rpm names that should be built out of this spec
# file
...
...
@@ -486,13 +504,19 @@ class bdist_rpm (Command):
# that we open and interpolate into the spec file, but the defaults
# are just text that we drop in as-is. Hmmm.
# forcing -O1 if force-optimize
if
self
.
force_optimize
:
optimize
=
' -O1'
else
:
optimize
=
''
install_cmd
=
(
'%s install%s --root=$RPM_BUILD_ROOT '
'--record=INSTALLED_FILES'
)
%
(
def_setup_call
,
optimize
)
script_options
=
[
(
'prep'
,
'prep_script'
,
"%setup -n %{name}-%{unmangled_version}"
),
(
'build'
,
'build_script'
,
def_build
),
(
'install'
,
'install_script'
,
(
"%s install "
"--root=$RPM_BUILD_ROOT "
"--record=INSTALLED_FILES"
)
%
def_setup_call
),
(
'install'
,
'install_script'
,
install_cmd
),
(
'clean'
,
'clean_script'
,
"rm -rf $RPM_BUILD_ROOT"
),
(
'verifyscript'
,
'verify_script'
,
None
),
(
'pre'
,
'pre_install'
,
None
),
...
...
tests/test_bdist_rpm.py
0 → 100644
View file @
314bb85f
"""Tests for distutils.command.bdist_rpm."""
import
unittest
import
sys
import
os
import
tempfile
import
shutil
from
distutils.core
import
Distribution
from
distutils.command.bdist_rpm
import
bdist_rpm
from
distutils.tests
import
support
from
distutils.spawn
import
find_executable
from
distutils
import
spawn
from
distutils.errors
import
DistutilsExecError
SETUP_PY
=
"""
\
from distutils.core import setup
import foo
setup(name='foo', version='0.1', py_modules=['foo'],
url='xxx', author='xxx', author_email='xxx')
"""
class
BuildRpmTestCase
(
support
.
TempdirManager
,
support
.
LoggingSilencer
,
unittest
.
TestCase
):
def
setUp
(
self
):
super
(
BuildRpmTestCase
,
self
).
setUp
()
self
.
old_location
=
os
.
getcwd
()
self
.
old_sys_argv
=
sys
.
argv
[:]
def
tearDown
(
self
):
os
.
chdir
(
self
.
old_location
)
sys
.
argv
=
self
.
old_sys_argv
[:]
super
(
BuildRpmTestCase
,
self
).
tearDown
()
def
test_quiet
(
self
):
# XXX I am unable yet to make this test work without
# spurious sdtout/stderr output under Mac OS X
if
sys
.
platform
!=
'linux2'
:
return
# this test will run only if the rpm commands are found
if
(
find_executable
(
'rpm'
)
is
None
or
find_executable
(
'rpmbuild'
)
is
None
):
return
# let's create a package
tmp_dir
=
self
.
mkdtemp
()
pkg_dir
=
os
.
path
.
join
(
tmp_dir
,
'foo'
)
os
.
mkdir
(
pkg_dir
)
self
.
write_file
((
pkg_dir
,
'setup.py'
),
SETUP_PY
)
self
.
write_file
((
pkg_dir
,
'foo.py'
),
'#'
)
self
.
write_file
((
pkg_dir
,
'MANIFEST.in'
),
'include foo.py'
)
self
.
write_file
((
pkg_dir
,
'README'
),
''
)
dist
=
Distribution
({
'name'
:
'foo'
,
'version'
:
'0.1'
,
'py_modules'
:
[
'foo'
],
'url'
:
'xxx'
,
'author'
:
'xxx'
,
'author_email'
:
'xxx'
})
dist
.
script_name
=
'setup.py'
os
.
chdir
(
pkg_dir
)
sys
.
argv
=
[
'setup.py'
]
cmd
=
bdist_rpm
(
dist
)
cmd
.
fix_python
=
True
# running in quiet mode
cmd
.
quiet
=
1
cmd
.
ensure_finalized
()
cmd
.
run
()
dist_created
=
os
.
listdir
(
os
.
path
.
join
(
pkg_dir
,
'dist'
))
self
.
assert_
(
'foo-0.1-1.noarch.rpm'
in
dist_created
)
def
test_no_optimize_flag
(
self
):
# XXX I am unable yet to make this test work without
# spurious sdtout/stderr output under Mac OS X
if
sys
.
platform
!=
'linux2'
:
return
# http://bugs.python.org/issue1533164
# this test will run only if the rpm command is found
if
(
find_executable
(
'rpm'
)
is
None
or
find_executable
(
'rpmbuild'
)
is
None
):
return
# let's create a package that brakes bdist_rpm
tmp_dir
=
self
.
mkdtemp
()
pkg_dir
=
os
.
path
.
join
(
tmp_dir
,
'foo'
)
os
.
mkdir
(
pkg_dir
)
self
.
write_file
((
pkg_dir
,
'setup.py'
),
SETUP_PY
)
self
.
write_file
((
pkg_dir
,
'foo.py'
),
'#'
)
self
.
write_file
((
pkg_dir
,
'MANIFEST.in'
),
'include foo.py'
)
self
.
write_file
((
pkg_dir
,
'README'
),
''
)
dist
=
Distribution
({
'name'
:
'foo'
,
'version'
:
'0.1'
,
'py_modules'
:
[
'foo'
],
'url'
:
'xxx'
,
'author'
:
'xxx'
,
'author_email'
:
'xxx'
})
dist
.
script_name
=
'setup.py'
os
.
chdir
(
pkg_dir
)
sys
.
argv
=
[
'setup.py'
]
cmd
=
bdist_rpm
(
dist
)
cmd
.
fix_python
=
True
# running with force-optimize = 1
# and quiet = 1
cmd
.
quiet
=
1
cmd
.
ensure_finalized
()
cmd
.
run
()
dist_created
=
os
.
listdir
(
os
.
path
.
join
(
pkg_dir
,
'dist'
))
self
.
assert_
(
'foo-0.1-1.noarch.rpm'
in
dist_created
)
os
.
remove
(
os
.
path
.
join
(
pkg_dir
,
'dist'
,
'foo-0.1-1.noarch.rpm'
))
# XXX I am unable yet to make this test work without
# spurious stderr output
# so returning until distutils.spawn acts better
return
# running with force-optimize = 0
cmd
.
force_optimize
=
0
try
:
# XXX How to prevent the spawned
# rpmbuild command to display errors ?
# this can be a problem for buildbots
cmd
.
ensure_finalized
()
cmd
.
run
()
except
DistutilsExecError
:
# happens only under Fedora/RedHat
# and some flavors of Linux
# otherwise it's a bug
if
sys
.
platform
==
'linux2'
:
return
dist_created
=
os
.
listdir
(
os
.
path
.
join
(
pkg_dir
,
'dist'
))
self
.
assert_
(
'foo-0.1-1.noarch.rpm'
in
dist_created
)
def
test_suite
():
return
unittest
.
makeSuite
(
BuildRpmTestCase
)
if
__name__
==
'__main__'
:
test_support
.
run_unittest
(
test_suite
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment