Closed Bug 1270082 Opened 8 years ago Closed 8 years ago

mach xpcshell-test: AttributeError: LooseVersion instance has no attribute 'version'

Categories

(Firefox Build System :: General, defect)

defect
Not set
normal

Tracking

(firefox49 fixed)

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: nbp, Assigned: nbp)

Details

Attachments

(2 files)

Attached file python stack trace
While running "mach xpcshell-test" under an environment setup by firefox-build-env [1], with the following command:

  $ nix-shell ~/firefox-build-env/release.nix -A build.i686-linux.gcc48 --pure --command "MOZBUILD_STATE_PATH=…; MOZCONFIG=…; mach xpcshell-test"

I get the following error message:

ParseError: could not parse: (toolkit == 'android' || toolkit == 'gonk') || (os != "win" || os_version == "5.1" || os_version == "5.2" )
exception: AttributeError: LooseVersion instance has no attribute 'version'

[1] https://github.com/nbp/firefox-build-env
So we set the `os_version` key in mozinfo using this `StringVersion` class:
https://dxr.mozilla.org/mozilla-central/rev/0a25833062a880f369e6f9f622413a94cc671bf4/testing/mozbase/mozinfo/mozinfo/mozinfo.py#125

which uses `LooseVersion` internally:
https://dxr.mozilla.org/mozilla-central/rev/0a25833062a880f369e6f9f622413a94cc671bf4/testing/mozbase/mozinfo/mozinfo/string_version.py

Looking at your stack trace, the `os_version` field seems to be an empty string: 'os_version': StringVersion ('')

So there are probably two bugs here:
1) We should handle an empty string in `StringVersion` more gracefully somehow. It looks like `LooseVersion` is pretty bad about this:
```
>>> from distutils.version import LooseVersion
>>> v = LooseVersion('')
>>> v2 = LooseVersion('1.0')
>>> v == v2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\mozilla-build\python\lib\distutils\version.py", line 296, in __cmp__
    return cmp(self.version, other.version)
AttributeError: LooseVersion instance has no attribute 'version'
```

2) You should figure out why `os_version` is coming out as an empty string on your platform:
https://dxr.mozilla.org/mozilla-central/rev/0a25833062a880f369e6f9f622413a94cc671bf4/testing/mozbase/mozinfo/mozinfo/mozinfo.py#89
(In reply to Ted Mielczarek [:ted.mielczarek] (Vacation May 5th-11th) from comment #1)
> 2) You should figure out why `os_version` is coming out as an empty string
> on your platform:
> https://dxr.mozilla.org/mozilla-central/rev/
> 0a25833062a880f369e6f9f622413a94cc671bf4/testing/mozbase/mozinfo/mozinfo/
> mozinfo.py#89

Thank, I instrumented the file and printed the following info:

platform.uname:
        system == Linux
        node == mountain-view
        release == 3.18.22
        version == #1-NixOS SMP Thu Jan 1 00:00:01 UTC 1970
        machine == x86_64
        processor == 
platform.architecture:
        bits == 32bit
        linkage == 
platform.linux_distribution:
        distro == 
        os_version == 
        codename == 

Sounds like the ARCH special case also applies to NixOS.
Ok, it seems that this problem is related to the lack of conformance to the LSB.

http://stackoverflow.com/questions/2756737/check-linux-distro-name

I guess the simple work-around would be to emit a warning that the file is missing, and/or take random default.
Setting /etc/lsb-release did not work.
I fallback on changing the code to handle the case where all three are empty.
Comment on attachment 8748644 [details] [diff] [review]
mozinfo: Use the kernel version if the distribution is not supported by python platform function.

Review of attachment 8748644 [details] [diff] [review]:
-----------------------------------------------------------------

The commit message does not match what you are doing. And you set the distro to "lfs" unconditionally in this case now. Is that "Linux from Scratch?"
Attachment #8748644 - Flags: review?(gps)
(In reply to Gregory Szorc [:gps] from comment #6)
> Comment on attachment 8748644 [details] [diff] [review]
> mozinfo: Use the kernel version if the distribution is not supported by
> python platform function.
> 
> Review of attachment 8748644 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> The commit message does not match what you are doing. And you set the distro
> to "lfs" unconditionally in this case now. Is that "Linux from Scratch?"

The commit message describes exactly what is done by this patch.  The condition match the fact that the installation of python does not support the distribution, by checking that all values of the tuple are empty strings.  (which includes ARCH and NixOS)

I used "lfs" for "Linux From Scratch", as this is likely to be the most polite description for everybody.  Unless you have a better idea on how to improve this patch, I do not see what I can change in this patch.
Flags: needinfo?(gps)
Attachment #8748644 - Flags: review+
Flags: needinfo?(gps)
Assignee: nobody → nicolas.b.pierron
Status: NEW → ASSIGNED
https://hg.mozilla.org/mozilla-central/rev/866b1aa2e02f
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: