# Buggy code
def run(self):
    # Run build.run function
    build.run(self)
    if getattr(self.distribution, "running_salt_install", False):
        # If our install attribute is present and set to True, we'll go
        # ahead and write our install time python modules.

        # Write the version file
        version_file_path = os.path.join(self.build_lib, "salt", "_version.py")
        open(version_file_path, "w").write(
            INSTALL_VERSION_TEMPLATE.format(
                date=datetime.utcnow(),
                version=__version__,
                version_info=__version_info__,
            )
        )

        # Write the system paths file
        system_paths_file_path = os.path.join(self.build_lib, "salt", "_syspaths.py")
        open(system_paths_file_path, "w").write(
            install_syspaths_template.format(
                date=datetime.utcnow(),
                root_dir=self.salt_root_dir,
                config_dir=self.salt_config_dir,
                cache_dir=self.salt_cache_dir,
                sock_dir=self.salt_sock_dir,
                srv_root_dir=self.salt_srv_root_dir,
                base_file_roots_dir=self.salt_base_file_roots_dir,
                base_pillar_roots_dir=self.salt_base_pillar_roots_dir,
                base_master_roots_dir=self.salt_base_master_roots_dir,
                logs_dir=self.salt_logs_dir,
                pidfile_dir=self.salt_pidfile_dir,
            )
        )


# Traceback (AttributeError)
root@sgtpepper:/usr/local/src/salt# python setup.py install
0.16.0-2614-g45f816c
running install
running build
running build_py
running build_scripts
Traceback (most recent call last):
File "setup.py", line 408, in <module>
setup(**SETUP_KWARGS)
File "/usr/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 248, in run
install.run(self)
File "/usr/lib/python2.7/distutils/command/install.py", line 601, in run
self.run_command('build')
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 180, in run
root_dir=self.salt_root_dir,
File "/usr/lib/python2.7/distutils/cmd.py", line 105, in __getattr__
raise AttributeError, attr
AttributeError: salt_root_dir

# Fixed code
def run(self):
    # Run build.run function
    build.run(self)
    if getattr(self.distribution, "running_salt_install", False):
        # If our install attribute is present and set to True, we'll go
        # ahead and write our install time python modules.

        # Write the version file
        version_file_path = os.path.join(self.build_lib, "salt", "_version.py")
        open(version_file_path, "w").write(
            INSTALL_VERSION_TEMPLATE.format(
                date=datetime.utcnow(),
                version=__version__,
                version_info=__version_info__,
            )
        )

        # Write the system paths file
        system_paths_file_path = os.path.join(self.build_lib, "salt", "_syspaths.py")
        open(system_paths_file_path, "w").write(
            install_syspaths_template.format(
                date=datetime.utcnow(),
                root_dir=self.distribution.salt_root_dir,
                config_dir=self.distribution.salt_config_dir,
                cache_dir=self.distribution.salt_cache_dir,
                sock_dir=self.distribution.salt_sock_dir,
                srv_root_dir=self.distribution.salt_srv_root_dir,
                base_file_roots_dir=self.distribution.salt_base_file_roots_dir,
                base_pillar_roots_dir=self.distribution.salt_base_pillar_roots_dir,
                base_master_roots_dir=self.distribution.salt_base_master_roots_dir,
                logs_dir=self.distribution.salt_logs_dir,
                pidfile_dir=self.distribution.salt_pidfile_dir,
            )
        )