habnabit / vcversioner

take version numbers from version control
ISC License
28 stars 16 forks source link

python2.[67] setup.py --version fails with TypeError: coercing to Unicode: need string or buffer, int found #6

Closed normalex closed 8 years ago

normalex commented 8 years ago
$ python setup.py --version
Traceback (most recent call last):
.....
  File "/usr/lib/python2.6/site-packages/setuptools/dist.py", line 232, in parse_command_line
    result = _Distribution.parse_command_line(self)
  File "/usr/lib64/python2.6/distutils/dist.py", line 451, in parse_command_line
    args = parser.getopt(args=self.script_args, object=self)
  File "/usr/lib64/python2.6/distutils/fancy_getopt.py", line 286, in getopt
    val = getattr(object, attr, 0) + 1
TypeError: coercing to Unicode: need string or buffer, int found

The issue is the current last line in vcversioner.py dist.version = dist.metadata.version = find_version(**value).version it should just be dist.metadata.version = find_version(**value).version

Tested using python2.6 and 2.7

habnabit commented 8 years ago

Sorry about the late response here. Since you appear to have dug into this, can you explain (for posterity?) why this change is necessary?

harlowja commented 8 years ago

Just my 2 cents,

$ python setup.py --version is a pretty basic and supposedly supported command. So it working would be great (vs not working). I personally sometimes use this, and packagers might use it, so having a known standard command working would be great.

habnabit commented 8 years ago

@harlowja I'm definitely not opposed to this fix; I just want to understand it. There was a reason I had to put the version in both places, but I don't remember what it was.

nhuray commented 8 years ago

@habnabit @harlowja Hi guys I got exactly the same issue. Can I help to fix it ?

nhuray commented 8 years ago

@habnabit I checked in distutils.distmodule and it seems there's no attribute version in the Distributionclass but there's one in DistributionMetadata. So that's why calling self.version on Distribution object fails.

Unfortunately, I don't know how I can link to the source code :(

nhuray commented 8 years ago

@habnabit Do you want I submit a pull request to fix this issue ?

nhuray commented 8 years ago

@harlowja @habnabit Hey guys how can we move forward with this issue ?

nhuray commented 8 years ago

Hey @habnabit could you answer my questions ?

Julian commented 8 years ago

I'm not sure where you're looking, maybe your distutils is different, but Distribution definitely does have such an attribute.

⊙  python -c 'from distutils.dist import Distribution; print Distribution().version'                julian@yoga
0
normalex commented 8 years ago

@Julian: the Distribution will get that attribute later in the execution, however in the context of where the vcversioner is plugged, the proper place is DistributionMetadata which is a wrapper over setup.py kwargs metadata.

Julian commented 8 years ago

@normalex sounds good to me, are you advising @habnabit to apply the OP's suggested change then?

dstufft commented 8 years ago

Distribution().version and DistributionMetadata().version are different things.

Distribution().version is 0 if the --version flag was not used and is 1 if the --version flag was used. It's a boolean value that indicates the options that this is being executed with.

You just want to assign to DistributionMetadata().version. Then Distribution().get_version() should return the correct version as well.