#2 Install fails on CentOS, `distribution.script_name` is None
Closed: Fixed Opened by btimby.

Since the release last week, I can no longer install python-daemon.

Downloading/unpacking python-daemon (from -r requirements.txt (line 9))
  Downloading python-daemon-2.1.2.tar.gz (76kB): 76kB downloaded
  Running setup.py egg_info for package python-daemon
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/home/jenkins/workspace/Upgrayedd/venv/build/python-daemon/setup.py", line 86, in <module>
        "Topic :: Software Development :: Libraries :: Python Modules",
      File "/usr/lib64/python2.7/distutils/core.py", line 112, in setup
        _setup_distribution = dist = klass(attrs)
      File "version.py", line 640, in __init__
        super(ChangelogAwareDistribution, self).__init__(*args, **kwargs)
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/setuptools/dist.py", line 265, in __init__
        self.fetch_build_eggs(attrs.pop('setup_requires'))
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/setuptools/dist.py", line 289, in fetch_build_eggs
        parse_requirements(requires), installer=self.fetch_build_egg
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/pkg_resources.py", line 618, in resolve
        dist = best[req.key] = env.best_match(req, self, installer)
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/pkg_resources.py", line 862, in best_match
        return self.obtain(req, installer) # try and download/install
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/pkg_resources.py", line 874, in obtain
        return installer(requirement)
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/setuptools/dist.py", line 337, in fetch_build_egg
        cmd.ensure_finalized()
      File "/usr/lib64/python2.7/distutils/cmd.py", line 109, in ensure_finalized
        self.finalize_options()
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 230, in finalize_options
        'dist_version': self.distribution.get_version(),
      File "version.py", line 656, in get_version
        version_info = self.get_version_info()
      File "version.py", line 651, in get_version_info
        changelog_path = get_changelog_path(self)
      File "version.py", line 552, in get_changelog_path
        setup_dirname = os.path.dirname(distribution.script_name)
      File "/home/jenkins/workspace/Upgrayedd/venv/lib64/python2.7/posixpath.py", line 120, in dirname
        i = p.rfind('/') + 1
    AttributeError: 'NoneType' object has no attribute 'rfind'

This is CentOS, with python 2.7.2. I can gather more info if needed.

On 01-Nov-2016, Ben Timby wrote:

Since the release last week, I can no longer install python-daemon.

Thank you for reporting this.

Downloading/unpacking python-daemon (from -r requirements.txt (line 9=

))
Downloading python-daemon-2.1.2.tar.gz (76kB): 76kB downloaded
Running setup.py egg_info for package python-daemon
Traceback (most recent call last):
File "", line 16, in
File "/home/jenkins/workspace/Upgrayedd/venv/build/python-daemo=
n/setup.py", line 86, in

This demonstrates that Python knows the correct path to the =E2=80=98setup.=
py=E2=80=99
script file.

      File "/usr/lib64/python2.7/distutils/core.py", line 112, in set=

up
_setup_distribution =3D dist =3D klass(attrs)

At this point, Distutils has already assigned the =E2=80=98script_name=E2=
=80=99
parameter to the script filename from the command line.

      File "version.py", line 640, in __init__
        super(ChangelogAwareDistribution, self).__init__(*args, **kwa=

rgs)

The Distribution subclass asks the superclass to initialise it. This
should set the necessary attributes from the =E2=80=98attrs=E2=80=99 collec=
tion,
including =E2=80=98script_name=E2=80=99.

      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site=

-packages/setuptools/dist.py", line 265, in init
self.fetch_build_eggs(attrs.pop('setup_requires'))

This is Setuptools interceding before the Distribution is properly
initialised, and running a Setuptools command on it. Grrr.

      [=E2=80=A6]
      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site=

-packages/setuptools/dist.py", line 337, in fetch_build_egg
cmd.ensure_finalized()
File "/usr/lib64/python2.7/distutils/cmd.py", line 109, in ensu=
re_finalized
self.finalize_options()

In order to run the command, Distutils needs Command instance ready
for use.

      File "/home/jenkins/workspace/Upgrayedd/venv/lib/python2.7/site=

-packages/setuptools/command/easy_install.py", line 230, in finalize_options
'dist_version': self.distribution.get_version(),

Which in turn needs the Distribution instance ready for use. But it's
not, because Setuptools hasn't done that yet.

      [=E2=80=A6]
      File "version.py", line 552, in get_changelog_path
        setup_dirname =3D os.path.dirname(distribution.script_name)

So the Distribution doesn't yet have an attribute that Distutils would
otherwise have set up correctly.

So this is IMO a bug in Setuptools: it should not be calling commands
on an un-initialised Distribution.

I'll need to come up with a work-around for that failure.

--=20
\ =E2=80=9CWith Lisp or Forth, a master programmer has unlimited po=
wer |
`\ and expressiveness. With Python, even a regular guy can reach |
_o__) for the stars.=E2=80=9D =E2=80=94Raymon=
d Hettinger |
Ben Finney ben@benfinney.id.au

Thanks Ben. I have frozen my dependency for now, and just wanted to bring this to your attention.

To use the latest release (2.1.2), I hardcoded version an maintainer as in this commit and added in setup.py the following line:

setup(
    ...
    dependency_links=['https://github.com/cemsbr/python-daemon/tarball/latest_release#egg=python-daemon-2.1.2']
    ...)

So this is IMO a bug in Setuptools: it should not be calling commands
on an un-initialised Distribution.

I'll need to come up with a work-around for that failure.

I now have an implementation to work around this Setuptools bug.

Please get the code from the branch https://pagure.io/python-daemon/branch/wip/issue/2/set-distribution-scriptname-early and let me know whether that resolves this issue.

Thanks for sharing this project!

I had this same problem attempting to add a recipe to yocto pyro targeting python 2.7 and building with bitbake. Unfortunately the code in the branch at https://pagure.io/python-daemon/branch/wip/issue/2/set-distribution-scriptname-early didn't work for me either. I got past the previous failing message but noticed this new failure message:

| DEBUG: Executing python function externalsrc_compile_prefunc
| NOTE: python-daemon: compiling from external source tree /home/dan/cust/Yocto/build-am3517/workspace/sources/python-daemon
| DEBUG: Python function externalsrc_compile_prefunc finished
| DEBUG: Executing shell function do_compile
| ERROR: python setup.py build execution failed.
| Traceback (most recent call last):
|   File "setup.py", line 86, in <module>
|     "Topic :: Software Development :: Libraries :: Python Modules",
|   File "/home/dan/cust/Yocto/build-am3517/tmp/work/armv7ahf-neon-poky-linux-gnueabi/python-daemon/2.1.2-r0/recipe-sysroot-native/usr/lib/python2.7/distutils/core.py", line 111, in setup
|     _setup_distribution = dist = klass(attrs)
|   File "/home/dan/cust/Yocto/build-am3517/workspace/sources/python-daemon/version.py", line 640, in __init__
|     super(ChangelogAwareDistribution, self).__init__(*args, **kwargs)
|   File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 316, in __init__
|   File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 371, in fetch_build_eggs
|   File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 846, in resolve
|   File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1118, in best_match
|   File "build/bdist.linux-x86_64/egg/pkg_resources/__init__.py", line 1130, in obtain
|   File "build/bdist.linux-x86_64/egg/setuptools/dist.py", line 437, in fetch_build_egg
|   File "/home/dan/cust/Yocto/build-am3517/tmp/work/armv7ahf-neon-poky-linux-gnueabi/python-daemon/2.1.2-r0/recipe-sysroot-native/usr/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
|     self.finalize_options()
|   File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 250, in finalize_options
|   File "/home/dan/cust/Yocto/build-am3517/workspace/sources/python-daemon/version.py", line 659, in get_version
|     version_info = self.get_version_info()
|   File "/home/dan/cust/Yocto/build-am3517/workspace/sources/python-daemon/version.py", line 655, in get_version_info
|     version_info = generate_version_info_from_changelog(changelog_path)
|   File "/home/dan/cust/Yocto/build-am3517/workspace/sources/python-daemon/version.py", line 496, in generate_version_info_from_changelog
|     versions_all_json = changelog_to_version_info_collection(infile)
|   File "/home/dan/cust/Yocto/build-am3517/workspace/sources/python-daemon/version.py", line 451, in changelog_to_version_info_collection
|     import docutils.core
| ImportError: No module named docutils.core
| WARNING: exit code 1 from a shell command.
| ERROR: Function failed: do_compile (log file is located at /home/dan/cust/Yocto/build-am3517/tmp/work/armv7ahf-neon-poky-linux-gnueabi/python-daemon/2.1.2-r0/temp/log.do_compile.22239)

The patch from @cemsbr at on github worked for me, so I have a solution, however if you'd like me to try a different patch in my failing environment just let me know.

I've also posted an update and link here on the stackoverflow topic mentioning this issue.

This bug should now be resolved in the release of 'python-daemon' version 2.2.0.

Metadata Update from @bignose:
- Issue close_status updated to: Fixed
- Issue status updated to: Closed (was: Open)

Since version 2.2.0 has released we have started seeing this issue (had never seen it before, found this ticket while searching).

Output:

  Downloading https://files.pythonhosted.org/packages/99/2a/75fe6aa7086e838570f29899f674e7896a42be26d9fff33f90d990e599d2/python-daemon-2.2.0.tar.gz (79kB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 353, in fetch_build_egg
        cmd = self._egg_fetcher
    AttributeError: 'ChangelogAwareDistribution' object has no attribute '_egg_fetcher'
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-f9si34v1/python-daemon/setup.py", line 102, in <module>
        setup(**setup_kwargs)
      File "/usr/lib/python3.5/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/tmp/pip-build-f9si34v1/python-daemon/version.py", line 652, in __init__
        super(ChangelogAwareDistribution, self).__init__(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 269, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 313, in fetch_build_eggs
        replace_conflicting=True,
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 826, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1092, in best_match
        return self.obtain(req, installer)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1104, in obtain
        return installer(requirement)
      File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 378, in fetch_build_egg
        cmd.ensure_finalized()
      File "/usr/lib/python3.5/distutils/cmd.py", line 107, in ensure_finalized
        self.finalize_options()
      File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 246, in finalize_options
        'dist_version': self.distribution.get_version(),
      File "/tmp/pip-build-f9si34v1/python-daemon/version.py", line 671, in get_version
        version_info = self.get_version_info()
      File "/tmp/pip-build-f9si34v1/python-daemon/version.py", line 667, in get_version_info
        version_info = generate_version_info_from_changelog(changelog_path)
      File "/tmp/pip-build-f9si34v1/python-daemon/version.py", line 495, in generate_version_info_from_changelog
        versions_all_json = changelog_to_version_info_collection(infile)
      File "/tmp/pip-build-f9si34v1/python-daemon/version.py", line 450, in changelog_to_version_info_collection
        import docutils.core
    ImportError: No module named 'docutils'

Since version 2.2.0 has released we have started seeing this issue (had never seen it before, found this ticket while searching).

You appear to be describing a new issue, please open a new issue report.

Metadata