[virt-tools-list] [PATCH v6 4/5] add option for snapshot-id suffix to __version__
Gene Czarcinski
gene at czarc.net
Sun Apr 14 23:36:37 UTC 2013
On 04/14/2013 02:35 PM, Cole Robinson wrote:
> On 04/13/2013 05:42 PM, Gene Czarcinski wrote:
>> 1. The added suffix is in the form YYYYMMDD and that is all.
>>
>> 2. Code is added to classes my_sdist and my_rpm to check and
>> see is a snapshot id is requested (--snapshot) and, if
>> requested, to append the id to the value of cliconfig.__version__
>>
>> 3. The added suffix only applies to the name of the sdist-tarball
>> and the rpm spec file it includes ... the "internal" version
>> remains unchanged.
>> .
>> Signed-off-by: Gene Czarcinski <gene at czarc.net>
>> ---
>> setup.py | 33 +++++++++++++++++++++++++++++----
>> virtcli/cliconfig.py | 2 ++
>> 2 files changed, 31 insertions(+), 4 deletions(-)
>>
>> diff --git a/setup.py b/setup.py
>> index aa712c2..ace1c3e 100644
>> --- a/setup.py
>> +++ b/setup.py
>> @@ -5,6 +5,7 @@ import fnmatch
>> import os
>> import sys
>> import unittest
>> +from datetime import date
>>
>> from distutils.core import Command, setup
>> from distutils.command.sdist import sdist
>> @@ -20,6 +21,10 @@ from DistUtilsExtra.command.build_icons import build_icons
>>
>> from virtcli import cliconfig
>>
>> +sdist.user_options.insert(0, ("snapshot", None,
>> + "add snapshot id to version"))
>> +sdist.boolean_options.insert(0, "snapshot")
>> +
> Why do it like this and not just add user_options to the my_sdist definition?
> Look at the configure example that you edited in the previous patch.
What you say here makes sense. Unfortunately, it does not work for me
... maybe I have the reverse midas touch ;(
I need to specify the user_option =[] for rpm but it is subclassed off
Command. And this should work because I am really doing the snapshot
append based on the setting of cliconfig.__snapshot__
Anyway, this code fragment does NOT work:
----------------------------------------------------------------------------------------------
# Note: cliconfig.__snapshot__ by default is 0, it can be set to 1 by
# either sdist or rpm and then means snapshot suffix is appended.
#sdist.user_options.insert(0, ("snapshot", "s",
# "add snapshot id to version"))
#sdist.boolean_options.insert(0, "snapshot")
class my_sdist(sdist_auto, sdist):
user_options = [
("snapshot", "s", "add snapshot id to version")
]
#user_option = []
description = "Update virt-manager.spec; build sdist-tarball."
def initialize_options(self):
self.snapshot = None
sdist.initialize_options(self)
def finalize_options(self):
if self.snapshot is not None:
self.snapshot = 1
cliconfig.__snapshot__ = 1
sdist.finalize_options(self)
def run(self):
ver = cliconfig.__version__
if cliconfig.__snapshot__ == 1:
ver = ver + '.' + date.today().isoformat().replace('-', '')
cliconfig.__version__ = ver
setattr(self.distribution.metadata, 'version', ver)
f1 = open('virt-manager.spec.in', 'r')
f2 = open('virt-manager.spec', 'w')
for line in f1:
f2.write(line.replace('@VERSION@', ver))
f1.close()
f2.close()
sdist_auto.run(self)
-------------------------------------------------------------------
and this code fragment does work:
-------------------------------------------------------------------------
# Note: cliconfig.__snapshot__ by default is 0, it can be set to 1 by
# either sdist or rpm and then means snapshot suffix is appended.
sdist.user_options.insert(0, ("snapshot", "s",
"add snapshot id to version"))
sdist.boolean_options.insert(0, "snapshot")
class my_sdist(sdist_auto):
#user_options = [
# ("snapshot", "s", "add snapshot id to version")
#]
user_option = []
description = "Update virt-manager.spec; build sdist-tarball."
def initialize_options(self):
self.snapshot = None
sdist.initialize_options(self)
def finalize_options(self):
if self.snapshot is not None:
self.snapshot = 1
cliconfig.__snapshot__ = 1
sdist.finalize_options(self)
def run(self):
ver = cliconfig.__version__
if cliconfig.__snapshot__ == 1:
ver = ver + '.' + date.today().isoformat().replace('-', '')
cliconfig.__version__ = ver
setattr(self.distribution.metadata, 'version', ver)
f1 = open('virt-manager.spec.in', 'r')
f2 = open('virt-manager.spec', 'w')
for line in f1:
f2.write(line.replace('@VERSION@', ver))
f1.close()
f2.close()
sdist_auto.run(self)
---------------------------------------------------------------------------
Somewhere down in the bowels of all this subclassing, something is
getting upset. I have played around trying to get this to work and,
while there are likely other solutions, the first one I found that
worked involved changing sdist's user_options list (sdist_auto does not
have one).
Here is the traceback I get with the code fragment that does not work:
-------------------------------------------------------
virt-manager]$python newsetup2.py sdist
Traceback (most recent call last):
File "newsetup2.py", line 502, in <module>
'test_urls' : TestURLFetch,
File "/usr/lib64/python2.7/distutils/core.py", line 138, in setup
ok = dist.parse_command_line()
File "/usr/lib64/python2.7/distutils/dist.py", line 467, in
parse_command_line
args = self._parse_command_opts(parser, args)
File "/usr/lib64/python2.7/distutils/dist.py", line 563, in
_parse_command_opts
parser.set_negative_aliases(negative_opt)
File "/usr/lib64/python2.7/distutils/fancy_getopt.py", line 142, in
set_negative_aliases
self._check_alias_dict(negative_alias, "negative alias")
File "/usr/lib64/python2.7/distutils/fancy_getopt.py", line 126, in
_check_alias_dict
"option '%s' not defined") % (what, alias, alias)
distutils.errors.DistutilsGetoptError: invalid negative alias
'no-defaults': option 'no-defaults' not defined
---------------------------------------------------------
You said it was like configure but configure, like my_rpm, are
subclassed off Command. If fact, I had the add the kludge with
cliconfig.__snapshot__ because my_rpm does not run my_dist directly but
by running:
self.run_command('sdist')
Maybe there is a way to do this that is not the way I did it but it is
going to take someone who is far more expert in pythonese than I am.
Anyway, I am going over the code and "spiffing it" up a bit (added short
option "s" for "snapshot") and will resubmitted tomorrow with the
current kludge of modifying sdist's user_option list ... unless some
python wizard can tell me how to do this "the right way."
BTW, it sure is nice that I can copy setup.py to another file which I
then hack away at to do the testing with getting git all upset.
Gene
More information about the virt-tools-list
mailing list