PBR

AttributeError: Distribution instance has no attribute 'pbr'

Bug #1493735 reported by Vincent Bernat
46
This bug affects 8 people
Affects Status Importance Assigned to Milestone
PBR
Fix Released
Critical
Sachi King

Bug Description

Hi!

I have a module not using pbr: https://github.com/vincentbernat/snimpy/

It uses "mock" as a test dependency and therefore pulls pbr indirectly. I get this stacktrace:

```
Installed /home/travis/build/vincentbernat/snimpy/.eggs/pbr-1.7.0-py2.7.egg
running egg_info
writing dependency_links to snimpy.egg-info/dependency_links.txt
writing snimpy.egg-info/PKG-INFO
writing requirements to snimpy.egg-info/requires.txt
writing entry points to snimpy.egg-info/entry_points.txt
writing top-level names to snimpy.egg-info/top_level.txt
Traceback (most recent call last):
  File "setup.py", line 68, in <module>
    'version_module_paths': ['snimpy/_version.py'],
  File "/opt/python/2.7.9/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/opt/python/2.7.9/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/opt/python/2.7.9/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/travis/build/vincentbernat/snimpy/.tox/py27/lib/python2.7/site-packages/setuptools/command/test.py", line 142, in run
    self.with_project_on_sys_path(self.run_tests)
  File "/home/travis/build/vincentbernat/snimpy/.tox/py27/lib/python2.7/site-packages/setuptools/command/test.py", line 106, in with_project_on_sys_path
    self.run_command('egg_info')
  File "/opt/python/2.7.9/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/opt/python/2.7.9/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/home/travis/build/vincentbernat/snimpy/.tox/py27/lib/python2.7/site-packages/setuptools/command/egg_info.py", line 173, in run
    writer(self, ep.name, os.path.join(self.egg_info, ep.name))
  File "/home/travis/build/vincentbernat/snimpy/.eggs/pbr-1.7.0-py2.7.egg/pbr/pbr_json.py", line 23, in write_pbr_json
    if not cmd.distribution.pbr:
AttributeError: Distribution instance has no attribute 'pbr'
ERROR: InvocationError: '/home/travis/build/vincentbernat/snimpy/.tox/py27/bin/python /home/travis/build/vincentbernat/snimpy/.tox/py27/bin/coverage run --source=snimpy setup.py test'
```

I have tried adding "pbr=False" in my setup.py. No change. It could be fixed by checking if pbr is an attribute of cmd.distribution but I think this would mask the fact that pbr is adding unwanted entry points (in this case, egg_info.writers = pbr.json = pbr.pbr_json:write_pbr_json).

Revision history for this message
Joshua Randall (jcrandall) wrote :

This effects me as well. Also with python 2.7.9 and also when being pulled in by mock (1.3.0, which requires pbr>=0.11). If I manually change the line in 'mock-1.3.0-py2.7.egg/EGG-INFO/requires.txt' to be 'pbr>=0.11,<1.7.0' everything is fine, so it seems to be an issue with pbr 1.7.0 either being incompatible with mock or having fundamental issues of its own.

Revision history for this message
Antoine "hashar" Musso (hashar) wrote :

Might be due to https://review.openstack.org/#/c/217528/1 Have pbr egg_info.writer check PBR is enabled

$ git tag --contains 8047f2fe
1.7.0
1.8.0
$

I had bunch of similar issues with pbr and mock 1.3.0 :-/

Revision history for this message
Robert Collins (lifeless) wrote :

This is a dupe of 1483067 I believe.

Revision history for this message
Robert Collins (lifeless) wrote :

Ah, no its not. Its the fix for that breaking.

For the record, pbr isn't hijacking things - setuptools has an extension interface that involves loading and running *all* extensions, and extensions need to opt-out of that process - the code to do that is failing in this case.

Changed in pbr:
status: New → Triaged
importance: Undecided → Critical
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to pbr (master)

Fix proposed to branch: master
Review: https://review.openstack.org/226088

Changed in pbr:
assignee: nobody → James Polley (tchaypo)
status: Triaged → In Progress
Revision history for this message
James Polley (tchaypo) wrote : Re: pbr hijacks unrelated setup.py

As per discussion in the linked change, I've been trying to replicate this with a simpler package - one that has a setup.py that's empty except for tests_require=['mock']

When I 'python setup.py test' on this setup.py, I do see that pbr gets downloaded and pseudo-installed (that's probably not the correct term but I'm hungry and lacking brain) so that mock can be installed. However, it doesn't cause this issue.

I'm not sure why not. I've just noticed though that the output above mentions "pbr-1.7.0" while I'm getting 1.8.0 installed, but none of the changes between those versions seem likely (from reading the commit messages) to change this behaviour.

In short - any help getting a minimal reproduction of this behaviour would be appreciated.

Revision history for this message
Vincent Bernat (vbernat) wrote :

Here is a minimal example that fails for me:

```
from setuptools import setup

setup(name="test1",
      tests_require=["mock", "nose"],
      test_suite="nose.collector")
```

Without using nose, it doesn't fail.

Revision history for this message
Vincent Bernat (vbernat) wrote :

And my tox.ini is:

```
[tox]
envlist = py27

[testenv]
commands = {envpython} setup.py test
```

Revision history for this message
James Polley (tchaypo) wrote :

Thanks Vincent - nose seems to be the factor I was overlooking

Revision history for this message
Barry Warsaw (barry) wrote :

Yep, system-image suffers the same problem

https://git.launchpad.net/ubuntu-system-image

It doesn't use pbr but yet gets a pbr.json in its egg-info when you run `python3 setup.py sdist`.

summary: - pbr hijacks unrelated setup.py
+ AttributeError: Distribution instance has no attribute 'pbr'
Revision history for this message
Ryan Petrello (ryan-petrello) wrote :

I'm also seeing this issue with pecan - despite not using pbr as a direct dependency, setup.py is failing in a similar way:

https://github.com/pecan/pecan/pull/20
https://travis-ci.org/pecan/pecan/jobs/83263910

Changed in pbr:
assignee: James Polley (tchaypo) → Sachi King (nakato)
Changed in pbr:
assignee: Sachi King (nakato) → Robert Collins (lifeless)
Changed in pbr:
assignee: Robert Collins (lifeless) → Sachi King (nakato)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to pbr (master)

Reviewed: https://review.openstack.org/226088
Committed: https://git.openstack.org/cgit/openstack-dev/pbr/commit/?id=36a2bf130999f06562b5eb063e1c49ae2d6e35a7
Submitter: Jenkins
Branch: master

commit 36a2bf130999f06562b5eb063e1c49ae2d6e35a7
Author: James Polley <email address hidden>
Date: Tue Sep 22 09:20:15 2015 +1000

    Handle the case where cmd.distribution has no pbr attribute

    This can arise if pbr has been installed indirectly (for instance,
    because a package depends on mock which requires pbr) - pbr will be
    running, but the cmd.distribution object has no pbr attribute. In this
    case, pbr code should not run.

    Change-Id: Ib7db0c8ab78e3cb700671f6a123ec603b4dbfdbe
    Closes-bug: 1493735
    Co-Authored-By: Sachi King <email address hidden>

Changed in pbr:
status: In Progress → Fix Committed
Changed in pbr:
milestone: none → 1.8.1
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.