コード例 #1
0
    def test_home_installation_scheme(self):
        # This ensure two things:
        # - that --home generates the desired set of directory names
        # - test --home is supported on all platforms
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, "installation")

        dist = Distribution({"name": "foopkg"})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(builddir, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(build_base=builddir, build_lib=os.path.join(builddir, "lib"))

        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()

        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, "lib", "python")
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers, os.path.join(destination, "include", "python", "foopkg"))
        check_path(cmd.install_scripts, os.path.join(destination, "bin"))
        check_path(cmd.install_data, destination)
コード例 #2
0
    def _test_user_site(self):
        for key in ("nt_user", "unix_user", "os2_home"):
            self.assert_(key in INSTALL_SCHEMES)

        dist = Distribution({"name": "xx"})
        cmd = install(dist)

        # making sure the user option is there
        options = [name for name, short, lable in cmd.user_options]
        self.assert_("user" in options)

        # setting a value
        cmd.user = 1

        # user base and site shouldn't be created yet
        self.assert_(not os.path.exists(self.user_base))
        self.assert_(not os.path.exists(self.user_site))

        # let's run finalize
        cmd.ensure_finalized()

        # now they should
        self.assert_(os.path.exists(self.user_base))
        self.assert_(os.path.exists(self.user_site))

        self.assert_("userbase" in cmd.config_vars)
        self.assert_("usersite" in cmd.config_vars)
コード例 #3
0
ファイル: locations.py プロジェクト: 31415us/trajectory
def distutils_scheme(dist_name, user=False, home=None):
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}
    d = Distribution({'name': dist_name})
    i = install(d)
    i.user = user or i.user
    i.home = home or i.home
    i.finalize_options()
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, 'install_'+key)

    #be backward-compatible with what pip has always done?
    scheme['scripts'] = bin_py

    if running_under_virtualenv():
        scheme['headers'] = os.path.join(sys.prefix,
                                    'include',
                                    'site',
                                    'python' + sys.version[:3],
                                    dist_name)

    return scheme
コード例 #4
0
    def test_handle_extra_path(self):
        dist = Distribution({"name": "xx", "extra_path": "path,dirs"})
        cmd = install(dist)

        # two elements
        cmd.handle_extra_path()
        self.assertEqual(cmd.extra_path, ["path", "dirs"])
        self.assertEqual(cmd.extra_dirs, "dirs")
        self.assertEqual(cmd.path_file, "path")

        # one element
        cmd.extra_path = ["path"]
        cmd.handle_extra_path()
        self.assertEqual(cmd.extra_path, ["path"])
        self.assertEqual(cmd.extra_dirs, "path")
        self.assertEqual(cmd.path_file, "path")

        # none
        dist.extra_path = cmd.extra_path = None
        cmd.handle_extra_path()
        self.assertEqual(cmd.extra_path, None)
        self.assertEqual(cmd.extra_dirs, "")
        self.assertEqual(cmd.path_file, None)

        # three elements (no way !)
        cmd.extra_path = "path,dirs,again"
        self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
コード例 #5
0
ファイル: common.py プロジェクト: scone/canari
def get_bin_dir():
    """
    Returns the absolute path of the installation directory for the Canari scripts.
    """
    d = install(Distribution())
    d.finalize_options()
    return d.install_scripts
コード例 #6
0
    def _test_user_site(self):
        for key in ('nt_user', 'unix_user', 'os2_home'):
            self.assertTrue(key in INSTALL_SCHEMES)

        dist = Distribution({'name': 'xx'})
        cmd = install(dist)

        # making sure the user option is there
        options = [name for name, short, lable in
                   cmd.user_options]
        self.assertTrue('user' in options)

        # setting a value
        cmd.user = 1

        # user base and site shouldn't be created yet
        self.assertTrue(not os.path.exists(self.user_base))
        self.assertTrue(not os.path.exists(self.user_site))

        # let's run finalize
        cmd.ensure_finalized()

        # now they should
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))

        self.assertTrue('userbase' in cmd.config_vars)
        self.assertTrue('usersite' in cmd.config_vars)
コード例 #7
0
ファイル: test_install.py プロジェクト: 524777134/cpython
    def test_record(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(py_modules=['hello'],
                                             scripts=['sayhi'])
        os.chdir(project_dir)
        self.write_file('hello.py', "def main(): print('o hai')")
        self.write_file('sayhi', 'from hello import main; main()')

        cmd = install(dist)
        dist.command_obj['install'] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'filelist')
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = ['hello.py', 'hello.%s.pyc' % imp.get_tag(), 'sayhi',
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #8
0
    def test_record_extensions(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(ext_modules=[Extension("xx", ["xxmodule.c"])])
        os.chdir(project_dir)
        support.copy_xxmodule_c(project_dir)

        buildextcmd = build_ext(dist)
        support.fixup_build_ext(buildextcmd)
        buildextcmd.ensure_finalized()

        cmd = install(dist)
        dist.command_obj["install"] = cmd
        dist.command_obj["build_ext"] = buildextcmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, "filelist")
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = [_make_ext_name("xx"), "UNKNOWN-0.0.0-py%s.%s.egg-info" % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #9
0
ファイル: test_install.py プロジェクト: Orav/kbengine
    def test_record(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(py_modules=["hello"], scripts=["sayhi"])
        os.chdir(project_dir)
        self.write_file("hello.py", "def main(): print('o hai')")
        self.write_file("sayhi", "from hello import main; main()")

        cmd = install(dist)
        dist.command_obj["install"] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, "filelist")
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = [
            "hello.py",
            "hello.%s.pyc" % sys.implementation.cache_tag,
            "sayhi",
            "UNKNOWN-0.0.0-py%s.%s.egg-info" % sys.version_info[:2],
        ]
        self.assertEqual(found, expected)
コード例 #10
0
    def test_record_extensions(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(ext_modules=[
            Extension('xx', ['xxmodule.c'])])
        self.addCleanup(os.chdir, os.getcwd())
        os.chdir(project_dir)
        support.copy_xxmodule_c(project_dir)

        buildextcmd = build_ext(dist)
        support.fixup_build_ext(buildextcmd)
        buildextcmd.ensure_finalized()

        cmd = install(dist)
        dist.command_obj['install'] = cmd
        dist.command_obj['build_ext'] = buildextcmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'RECORD')
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = [_make_ext_name('xx'),
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #11
0
ファイル: test_install.py プロジェクト: 1st1/cpython
    def test_record_extensions(self):
        cmd = test_support.missing_compiler_executable()
        if cmd is not None:
            self.skipTest('The %r command is not found' % cmd)
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(ext_modules=[
            Extension('xx', ['xxmodule.c'])])
        os.chdir(project_dir)
        support.copy_xxmodule_c(project_dir)

        buildextcmd = build_ext(dist)
        support.fixup_build_ext(buildextcmd)
        buildextcmd.ensure_finalized()

        cmd = install(dist)
        dist.command_obj['install'] = cmd
        dist.command_obj['build_ext'] = buildextcmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'filelist')
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = [_make_ext_name('xx'),
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #12
0
ファイル: test_install.py プロジェクト: 524777134/cpython
    def test_handle_extra_path(self):
        dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
        cmd = install(dist)

        # two elements
        cmd.handle_extra_path()
        self.assertEqual(cmd.extra_path, ['path', 'dirs'])
        self.assertEqual(cmd.extra_dirs, 'dirs')
        self.assertEqual(cmd.path_file, 'path')

        # one element
        cmd.extra_path = ['path']
        cmd.handle_extra_path()
        self.assertEqual(cmd.extra_path, ['path'])
        self.assertEqual(cmd.extra_dirs, 'path')
        self.assertEqual(cmd.path_file, 'path')

        # none
        dist.extra_path = cmd.extra_path = None
        cmd.handle_extra_path()
        self.assertEqual(cmd.extra_path, None)
        self.assertEqual(cmd.extra_dirs, '')
        self.assertEqual(cmd.path_file, None)

        # three elements (no way !)
        cmd.extra_path = 'path,dirs,again'
        self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
コード例 #13
0
ファイル: test_install.py プロジェクト: plirof/minibloq_v0.83
    def test_user_site(self):
        # site.USER_SITE was introduced in 2.6
        if sys.version < "2.6":
            return

        # preparing the environment for the test
        self.old_user_base = site.USER_BASE
        self.old_user_site = site.USER_SITE
        self.tmpdir = self.mkdtemp()
        self.user_base = os.path.join(self.tmpdir, "B")
        self.user_site = os.path.join(self.tmpdir, "S")
        site.USER_BASE = self.user_base
        site.USER_SITE = self.user_site
        install_module.USER_BASE = self.user_base
        install_module.USER_SITE = self.user_site

        def _expanduser(path):
            return self.tmpdir

        self.old_expand = os.path.expanduser
        os.path.expanduser = _expanduser

        def cleanup():
            site.USER_BASE = self.old_user_base
            site.USER_SITE = self.old_user_site
            install_module.USER_BASE = self.old_user_base
            install_module.USER_SITE = self.old_user_site
            os.path.expanduser = self.old_expand

        self.addCleanup(cleanup)

        for key in ("nt_user", "unix_user", "os2_home"):
            self.assertIn(key, INSTALL_SCHEMES)

        dist = Distribution({"name": "xx"})
        cmd = install(dist)

        # making sure the user option is there
        options = [name for name, short, lable in cmd.user_options]
        self.assertIn("user", options)

        # setting a value
        cmd.user = 1

        # user base and site shouldn't be created yet
        self.assertFalse(os.path.exists(self.user_base))
        self.assertFalse(os.path.exists(self.user_site))

        # let's run finalize
        cmd.ensure_finalized()

        # now they should
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))

        self.assertIn("userbase", cmd.config_vars)
        self.assertIn("usersite", cmd.config_vars)
コード例 #14
0
ファイル: test_install.py プロジェクト: 524777134/cpython
    def test_user_site(self):
        # test install with --user
        # preparing the environment for the test
        self.old_user_base = site.USER_BASE
        self.old_user_site = site.USER_SITE
        self.tmpdir = self.mkdtemp()
        self.user_base = os.path.join(self.tmpdir, 'B')
        self.user_site = os.path.join(self.tmpdir, 'S')
        site.USER_BASE = self.user_base
        site.USER_SITE = self.user_site
        install_module.USER_BASE = self.user_base
        install_module.USER_SITE = self.user_site

        def _expanduser(path):
            return self.tmpdir
        self.old_expand = os.path.expanduser
        os.path.expanduser = _expanduser

        def cleanup():
            site.USER_BASE = self.old_user_base
            site.USER_SITE = self.old_user_site
            install_module.USER_BASE = self.old_user_base
            install_module.USER_SITE = self.old_user_site
            os.path.expanduser = self.old_expand

        self.addCleanup(cleanup)

        for key in ('nt_user', 'unix_user'):
            self.assertIn(key, INSTALL_SCHEMES)

        dist = Distribution({'name': 'xx'})
        cmd = install(dist)

        # making sure the user option is there
        options = [name for name, short, lable in
                   cmd.user_options]
        self.assertIn('user', options)

        # setting a value
        cmd.user = 1

        # user base and site shouldn't be created yet
        self.assertFalse(os.path.exists(self.user_base))
        self.assertFalse(os.path.exists(self.user_site))

        # let's run finalize
        cmd.ensure_finalized()

        # now they should
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))

        self.assertIn('userbase', cmd.config_vars)
        self.assertIn('usersite', cmd.config_vars)
コード例 #15
0
ファイル: teststest_install.py プロジェクト: aevitas/wotsdk
 def test_finalize_options(self):
     dist = Distribution({'name': 'xx'})
     cmd = install(dist)
     cmd.prefix = 'prefix'
     cmd.install_base = 'base'
     self.assertRaises(DistutilsOptionError, cmd.finalize_options)
     cmd.install_base = None
     cmd.home = 'home'
     self.assertRaises(DistutilsOptionError, cmd.finalize_options)
     cmd.prefix = None
     cmd.user = '******'
     self.assertRaises(DistutilsOptionError, cmd.finalize_options)
     return
コード例 #16
0
def _looks_like_red_hat_scheme() -> bool:
    """Red Hat patches ``sys.prefix`` and ``sys.exec_prefix``.

    Red Hat's ``00251-change-user-install-location.patch`` changes the install
    command's ``prefix`` and ``exec_prefix`` to append ``"/local"``. This is
    (fortunately?) done quite unconditionally, so we create a default command
    object without any configuration to detect this.
    """
    from distutils.command.install import install
    from distutils.dist import Distribution

    cmd: Any = install(Distribution())
    cmd.finalize_options()
    return (cmd.exec_prefix == f"{os.path.normpath(sys.exec_prefix)}/local"
            and cmd.prefix == f"{os.path.normpath(sys.prefix)}/local")
コード例 #17
0
    def test_record(self):

        install_dir = self.mkdtemp()
        pkgdir, dist = self.create_dist()

        dist = Distribution()
        cmd = install(dist)
        dist.command_obj['install'] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(pkgdir, 'RECORD')
        cmd.ensure_finalized()

        cmd.run()

        # let's check the RECORD file was created with one
        # line (the egg info file)
        with open(cmd.record) as f:
            self.assertEquals(len(f.readlines()), 1)
コード例 #18
0
    def test_record(self):

        install_dir = self.mkdtemp()
        pkgdir, dist = self.create_dist()

        dist = Distribution()
        cmd = install(dist)
        dist.command_obj['install'] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(pkgdir, 'RECORD')
        cmd.ensure_finalized()

        cmd.run()

        # let's check the RECORD file was created with one
        # line (the egg info file)
        with open(cmd.record) as f:
            self.assertEquals(len(f.readlines()), 1)
コード例 #19
0
 def test_handle_extra_path(self):
     dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
     cmd = install(dist)
     cmd.handle_extra_path()
     self.assertEqual(cmd.extra_path, ['path', 'dirs'])
     self.assertEqual(cmd.extra_dirs, 'dirs')
     self.assertEqual(cmd.path_file, 'path')
     cmd.extra_path = ['path']
     cmd.handle_extra_path()
     self.assertEqual(cmd.extra_path, ['path'])
     self.assertEqual(cmd.extra_dirs, 'path')
     self.assertEqual(cmd.path_file, 'path')
     dist.extra_path = cmd.extra_path = None
     cmd.handle_extra_path()
     self.assertEqual(cmd.extra_path, None)
     self.assertEqual(cmd.extra_dirs, '')
     self.assertEqual(cmd.path_file, None)
     cmd.extra_path = 'path,dirs,again'
     self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
コード例 #20
0
    def test_finalize_options(self):
        dist = Distribution({'name': 'xx'})
        cmd = install(dist)

        # must supply either prefix/exec-prefix/home or
        # install-base/install-platbase -- not both
        cmd.prefix = 'prefix'
        cmd.install_base = 'base'
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)

        # must supply either home or prefix/exec-prefix -- not both
        cmd.install_base = None
        cmd.home = 'home'
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)

        # can't combine user with with prefix/exec_prefix/home or
        # install_(plat)base
        cmd.prefix = None
        cmd.user = '******'
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)
コード例 #21
0
    def test_finalize_options(self):
        dist = Distribution({"name": "xx"})
        cmd = install(dist)

        # must supply either prefix/exec-prefix/home or
        # install-base/install-platbase -- not both
        cmd.prefix = "prefix"
        cmd.install_base = "base"
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)

        # must supply either home or prefix/exec-prefix -- not both
        cmd.install_base = None
        cmd.home = "home"
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)

        # can't combine user with prefix/exec_prefix/home or
        # install_(plat)base
        cmd.prefix = None
        cmd.user = "******"
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)
コード例 #22
0
ファイル: test_install.py プロジェクト: 524777134/cpython
    def test_finalize_options(self):
        dist = Distribution({'name': 'xx'})
        cmd = install(dist)

        # must supply either prefix/exec-prefix/home or
        # install-base/install-platbase -- not both
        cmd.prefix = 'prefix'
        cmd.install_base = 'base'
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)

        # must supply either home or prefix/exec-prefix -- not both
        cmd.install_base = None
        cmd.home = 'home'
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)

        # can't combine user with prefix/exec_prefix/home or
        # install_(plat)base
        cmd.prefix = None
        cmd.user = '******'
        self.assertRaises(DistutilsOptionError, cmd.finalize_options)
コード例 #23
0
ファイル: teststest_install.py プロジェクト: aevitas/wotsdk
 def test_handle_extra_path(self):
     dist = Distribution({'name': 'xx',
      'extra_path': 'path,dirs'})
     cmd = install(dist)
     cmd.handle_extra_path()
     self.assertEqual(cmd.extra_path, ['path', 'dirs'])
     self.assertEqual(cmd.extra_dirs, 'dirs')
     self.assertEqual(cmd.path_file, 'path')
     cmd.extra_path = ['path']
     cmd.handle_extra_path()
     self.assertEqual(cmd.extra_path, ['path'])
     self.assertEqual(cmd.extra_dirs, 'path')
     self.assertEqual(cmd.path_file, 'path')
     dist.extra_path = cmd.extra_path = None
     cmd.handle_extra_path()
     self.assertEqual(cmd.extra_path, None)
     self.assertEqual(cmd.extra_dirs, '')
     self.assertEqual(cmd.path_file, None)
     cmd.extra_path = 'path,dirs,again'
     self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
     return
コード例 #24
0
ファイル: teststest_install.py プロジェクト: aevitas/wotsdk
    def test_user_site(self):
        self.old_user_base = site.USER_BASE
        self.old_user_site = site.USER_SITE
        self.tmpdir = self.mkdtemp()
        self.user_base = os.path.join(self.tmpdir, 'B')
        self.user_site = os.path.join(self.tmpdir, 'S')
        site.USER_BASE = self.user_base
        site.USER_SITE = self.user_site
        install_module.USER_BASE = self.user_base
        install_module.USER_SITE = self.user_site

        def _expanduser(path):
            return self.tmpdir

        self.old_expand = os.path.expanduser
        os.path.expanduser = _expanduser

        def cleanup():
            site.USER_BASE = self.old_user_base
            site.USER_SITE = self.old_user_site
            install_module.USER_BASE = self.old_user_base
            install_module.USER_SITE = self.old_user_site
            os.path.expanduser = self.old_expand

        self.addCleanup(cleanup)
        for key in ('nt_user', 'unix_user', 'os2_home'):
            self.assertIn(key, INSTALL_SCHEMES)

        dist = Distribution({'name': 'xx'})
        cmd = install(dist)
        options = [ name for name, short, lable in cmd.user_options ]
        self.assertIn('user', options)
        cmd.user = 1
        self.assertFalse(os.path.exists(self.user_base))
        self.assertFalse(os.path.exists(self.user_site))
        cmd.ensure_finalized()
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))
        self.assertIn('userbase', cmd.config_vars)
        self.assertIn('usersite', cmd.config_vars)
コード例 #25
0
    def test_user_site(self):
        self.old_user_base = site.USER_BASE
        self.old_user_site = site.USER_SITE
        self.tmpdir = self.mkdtemp()
        self.user_base = os.path.join(self.tmpdir, 'B')
        self.user_site = os.path.join(self.tmpdir, 'S')
        site.USER_BASE = self.user_base
        site.USER_SITE = self.user_site
        install_module.USER_BASE = self.user_base
        install_module.USER_SITE = self.user_site

        def _expanduser(path):
            return self.tmpdir

        self.old_expand = os.path.expanduser
        os.path.expanduser = _expanduser

        def cleanup():
            site.USER_BASE = self.old_user_base
            site.USER_SITE = self.old_user_site
            install_module.USER_BASE = self.old_user_base
            install_module.USER_SITE = self.old_user_site
            os.path.expanduser = self.old_expand

        self.addCleanup(cleanup)
        for key in ('nt_user', 'unix_user', 'os2_home'):
            self.assertIn(key, INSTALL_SCHEMES)

        dist = Distribution({'name': 'xx'})
        cmd = install(dist)
        options = [name for name, short, lable in cmd.user_options]
        self.assertIn('user', options)
        cmd.user = 1
        self.assertFalse(os.path.exists(self.user_base))
        self.assertFalse(os.path.exists(self.user_site))
        cmd.ensure_finalized()
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))
        self.assertIn('userbase', cmd.config_vars)
        self.assertIn('usersite', cmd.config_vars)
コード例 #26
0
    def test_home_installation_scheme(self):
        # This ensure two things:
        # - that --home generates the desired set of directory names
        # - test --home is supported on all platforms
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, "installation")

        dist = Distribution({"name": "foopkg"})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(builddir, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(
            build_base=builddir,
            build_lib=os.path.join(builddir, "lib"),
        )

        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()

        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        if check_impl_detail():
            libdir = os.path.join(destination, "lib", "python")

            check_path(cmd.install_lib, libdir)
            check_path(cmd.install_platlib, libdir)
            check_path(cmd.install_purelib, libdir)
            check_path(
                cmd.install_headers,
                os.path.join(destination, "include", "python", "foopkg"))
            check_path(cmd.install_scripts, os.path.join(destination, "bin"))
            check_path(cmd.install_data, destination)
コード例 #27
0
def distutils_scheme(dist_name, user=False, home=None):
    """
    Return a distutils install scheme
    """
    from distutils.dist import Distribution

    scheme = {}
    d = Distribution({'name': dist_name})
    i = install(d)
    i.user = user or i.user
    i.home = home or i.home
    i.finalize_options()
    for key in SCHEME_KEYS:
        scheme[key] = getattr(i, 'install_' + key)

    #be backward-compatible with what pip has always done?
    scheme['scripts'] = bin_py

    if running_under_virtualenv():
        scheme['headers'] = os.path.join(sys.prefix, 'include', 'site',
                                         'python' + sys.version[:3], dist_name)

    return scheme
コード例 #28
0
ファイル: teststest_install.py プロジェクト: aevitas/wotsdk
    def test_home_installation_scheme(self):
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, 'installation')
        dist = Distribution({'name': 'foopkg'})
        dist.script_name = os.path.join(builddir, 'setup.py')
        dist.command_obj['build'] = support.DummyCommand(build_base=builddir, build_lib=os.path.join(builddir, 'lib'))
        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()
        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, 'lib', 'python')
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers, os.path.join(destination, 'include', 'python', 'foopkg'))
        check_path(cmd.install_scripts, os.path.join(destination, 'bin'))
        check_path(cmd.install_data, destination)
コード例 #29
0
    def test_record(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(scripts=['hello'])
        self.addCleanup(os.chdir, os.getcwd())
        os.chdir(project_dir)
        self.write_file('hello', "print('o hai')")

        cmd = install(dist)
        dist.command_obj['install'] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'RECORD')
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = ['hello',
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #30
0
    def test_record(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(py_modules=['hello'], scripts=['sayhi'])
        os.chdir(project_dir)
        self.write_file('hello.py', "def main(): print 'o hai'")
        self.write_file('sayhi', 'from hello import main; main()')
        cmd = install(dist)
        dist.command_obj['install'] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'filelist')
        cmd.ensure_finalized()
        cmd.run()
        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [ os.path.basename(line) for line in content.splitlines() ]
        expected = ['hello.py',
         'hello.pyc',
         'sayhi',
         'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #31
0
    def test_home_installation_scheme(self):
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, 'installation')
        dist = Distribution({'name': 'foopkg'})
        dist.script_name = os.path.join(builddir, 'setup.py')
        dist.command_obj['build'] = support.DummyCommand(build_base=builddir, build_lib=os.path.join(builddir, 'lib'))
        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()
        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, 'lib', 'python')
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers, os.path.join(destination, 'include', 'python', 'foopkg'))
        check_path(cmd.install_scripts, os.path.join(destination, 'bin'))
        check_path(cmd.install_data, destination)
コード例 #32
0
    def test_record(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(scripts=['hello'])
        self.addCleanup(os.chdir, os.getcwd())
        os.chdir(project_dir)
        self.write_file('hello', "print('o hai')")

        cmd = install(dist)
        dist.command_obj['install'] = cmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'RECORD')
        cmd.ensure_finalized()
        cmd.run()

        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [os.path.basename(line) for line in content.splitlines()]
        expected = ['hello',
                    'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #33
0
    def test_record_extensions(self):
        install_dir = self.mkdtemp()
        project_dir, dist = self.create_dist(ext_modules=[Extension('xx', ['xxmodule.c'])])
        os.chdir(project_dir)
        support.copy_xxmodule_c(project_dir)
        buildextcmd = build_ext(dist)
        support.fixup_build_ext(buildextcmd)
        buildextcmd.ensure_finalized()
        cmd = install(dist)
        dist.command_obj['install'] = cmd
        dist.command_obj['build_ext'] = buildextcmd
        cmd.root = install_dir
        cmd.record = os.path.join(project_dir, 'filelist')
        cmd.ensure_finalized()
        cmd.run()
        f = open(cmd.record)
        try:
            content = f.read()
        finally:
            f.close()

        found = [ os.path.basename(line) for line in content.splitlines() ]
        expected = [_make_ext_name('xx'), 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
        self.assertEqual(found, expected)
コード例 #34
0
def setup():
	print("***", os.path.abspath(sys.argv[0]), " ".join(sys.argv[1:]))

	bdist_bbfreeze = "bdist_bbfreeze" in sys.argv[1:]
	bdist_dumb = "bdist_dumb" in sys.argv[1:]
	bdist_win = "bdist_msi" in sys.argv[1:] or "bdist_wininst" in sys.argv[1:]
	debug = 0
	do_full_install = False
	do_install = False
	do_py2app = "py2app" in sys.argv[1:]
	do_py2exe = "py2exe" in sys.argv[1:]
	do_uninstall = "uninstall" in sys.argv[1:]
	doc_layout = "deb" if os.path.exists("/etc/debian_version") else ""
	dry_run = "-n" in sys.argv[1:] or "--dry-run" in sys.argv[1:]
	help = False
	install_data = None # data files install path (only if given)
	is_rpm_build = "bdist_rpm" in sys.argv[1:] or os.path.abspath(sys.argv[0]).endswith(
		os.path.join(os.path.sep, "rpm", "BUILD", name + "-" + version, 
		os.path.basename(os.path.abspath(sys.argv[0]))))
	prefix = ""
	recordfile_name = None # record installed files to this file
	sdist = "sdist" in sys.argv[1:]
	setuptools = None
	skip_instrument_conf_files = "--skip-instrument-configuration-files" in \
		sys.argv[1:]
	skip_postinstall = "--skip-postinstall" in sys.argv[1:]
	use_distutils = not bdist_bbfreeze and not do_py2app
	use_setuptools = not use_distutils or "--use-setuptools" in \
		sys.argv[1:] or (os.path.exists("use-setuptools") and 
						 not "--use-distutils" in sys.argv[1:])
	use_sdl = "--use-sdl" in sys.argv[1:]

	sys.path.insert(1, os.path.join(os.path.dirname(pydir), "util"))

	current_findall = distutils.filelist.findall

	if use_setuptools:
		if "--use-setuptools" in sys.argv[1:] and not \
		   os.path.exists("use-setuptools"):
			open("use-setuptools", "w").close()
		try:
			from ez_setup import use_setuptools as ez_use_setuptools
			ez_use_setuptools()
		except ImportError:
			pass
		try:
			from setuptools import setup, Extension
			setuptools = True
			print("using setuptools")
			current_findall = distutils.filelist.findall
		except ImportError:
			pass
	else:
		if os.path.exists("use-setuptools"):
			os.remove("use-setuptools")

	if distutils.filelist.findall is current_findall:
		# Fix traversing unneeded dirs which can take a long time (minutes)
		def findall(dir=os.curdir, original=distutils.filelist.findall, listdir=os.listdir,
					basename=os.path.basename):
			os.listdir = lambda path: [entry for entry in listdir(path) if entry not in ("build",
																		 "dist") and
														   not entry.startswith(".")]
			try:
				return original(dir)
			finally:
				os.listdir = listdir

		distutils.filelist.findall = findall

	if not setuptools:
		from distutils.core import setup, Extension
		print("using distutils")
	
	if do_py2exe:
		import py2exe
		# ModuleFinder can't handle runtime changes to __path__, but win32com 
		# uses them
		try:
			# if this doesn't work, try import modulefinder
			import py2exe.mf as modulefinder
			import win32com
			for p in win32com.__path__[1:]:
				modulefinder.AddPackagePath("win32com", p)
			for extra in ["win32com.shell"]:
				__import__(extra)
				m = sys.modules[extra]
				for p in m.__path__[1:]:
					modulefinder.AddPackagePath(extra, p)
		except ImportError:
			# no build path setup, no worries.
			pass
	
	if do_py2exe:
		origIsSystemDLL = py2exe.build_exe.isSystemDLL
		systemroot = os.getenv("SystemRoot").lower()
		def isSystemDLL(pathname):
			if (os.path.basename(pathname).lower() in ("gdiplus.dll", 
													   "mfc90.dll") or
				os.path.basename(pathname).lower().startswith("python") or
				os.path.basename(pathname).lower().startswith("pywintypes")):
				return 0
			return pathname.lower().startswith(systemroot + "\\")
		py2exe.build_exe.isSystemDLL = isSystemDLL

		# Numpy DLL paths fix
		def numpy_dll_paths_fix():
			import numpy
			paths = set()
			numpy_path = numpy.__path__[0]
			for dirpath, dirnames, filenames in os.walk(numpy_path):
				for item in filenames:
					if item.lower().endswith(".dll"):
						paths.add(dirpath)
			sys.path.extend(paths)
		numpy_dll_paths_fix()

	if do_uninstall:
		i = sys.argv.index("uninstall")
		sys.argv = sys.argv[:i] + ["install"] + sys.argv[i + 1:]
		install.create_home_path = lambda self: None

	if skip_instrument_conf_files:
		i = sys.argv.index("--skip-instrument-configuration-files")
		sys.argv = sys.argv[:i] + sys.argv[i + 1:]
	
	if skip_postinstall:
		i = sys.argv.index("--skip-postinstall")
		sys.argv = sys.argv[:i] + sys.argv[i + 1:]

	if "--use-distutils" in sys.argv[1:]:
		i = sys.argv.index("--use-distutils")
		sys.argv = sys.argv[:i] + sys.argv[i + 1:]

	if "--use-setuptools" in sys.argv[1:]:
		i = sys.argv.index("--use-setuptools")
		sys.argv = sys.argv[:i] + sys.argv[i + 1:]

	argv = list(sys.argv[1:])
	for i, arg in enumerate(reversed(argv)):
		n = len(sys.argv) - i - 1
		if arg in ("install", "install_lib", "install_headers", 
				   "install_scripts", "install_data"):
			if arg == "install":
				do_full_install = True
			do_install = True
		elif arg == "-d" and len(sys.argv[1:]) > i:
			dist_dir = sys.argv[i + 2]
		else:
			arg = arg.split("=")
			if arg[0] == "--debug":
				debug = 1 if len(arg) == 1 else int(arg[1])
				sys.argv = sys.argv[:n] + sys.argv[n + 1:]
			elif len(arg) == 2:
				if arg[0] == "--dist-dir":
					dist_dir = arg[1]
				elif arg[0] == "--doc-layout":
					doc_layout = arg[1]
					sys.argv = sys.argv[:n] + sys.argv[n + 1:]
				elif arg[0] == "--install-data":
					install_data = arg[1]
				elif arg[0] == "--prefix":
					prefix = arg[1]
				elif arg[0] == "--record":
					recordfile_name = arg[1]
			elif arg[0] == "-h" or arg[0].startswith("--help"):
				help = True

	if not recordfile_name and (do_full_install or do_uninstall):
		recordfile_name = "INSTALLED_FILES"
		# if not do_uninstall:
			# sys.argv.append("--record=" + "INSTALLED_FILES")

	if sys.platform in ("darwin", "win32") or "bdist_egg" in sys.argv[1:]:
		doc = data = "." if do_py2app or do_py2exe or bdist_bbfreeze else name
	else:
		# Linux/Unix
		data = name
		if doc_layout.startswith("deb"):
			doc = os.path.join("doc", name.lower())
		elif "suse" in doc_layout:
			doc = os.path.join("doc", "packages", name)
		else:
			doc = os.path.join("doc", name + "-" + version)
		if not install_data:
			data = os.path.join("share", data)
			doc = os.path.join("share", doc)
			if is_rpm_build:
				doc = os.path.join(os.path.sep, "usr", doc)

	# Use CA file from certifi project
	if do_py2app or do_py2exe:
		import certifi
		cacert = certifi.where()
		if cacert:
			shutil.copyfile(cacert, os.path.join(pydir, "cacert.pem"))
			config["package_data"][name].append("cacert.pem")
		else:
			print("WARNING: cacert.pem from certifi project not found!")

	# on Mac OS X and Windows, we want data files in the package dir
	# (package_data will be ignored when using py2exe)
	package_data = {
		name: config["package_data"][name]
			  if sys.platform in ("darwin", "win32") and not do_py2app and not 
			  do_py2exe else []
	}
	if sdist and sys.platform in ("darwin", "win32"):
		package_data[name].extend(["theme/icons/22x22/*.png",
								   "theme/icons/24x24/*.png"])
	if sys.platform == "win32" and not do_py2exe:
		package_data[name].append("theme/icons/*.ico")
	# Scripts
	if sys.platform == 'darwin':
		scripts = get_scripts(excludes=[appname.lower() + '-apply-profiles'])
	else:
		scripts = get_scripts()
	# Doc files
	data_files = []
	if not is_rpm_build or doc_layout.startswith("deb"):
		data_files += get_data(doc, "doc", excludes=["LICENSE.txt"])
	if data_files:
		if doc_layout.startswith("deb"):
			data_files.append((doc, [os.path.join(pydir, "..", "dist", 
												  "copyright")]))
			data_files.append((os.path.join(os.path.dirname(data), "doc-base"), 
							   [os.path.join(pydir, "..", "misc", 
											 appname.lower() + "-readme")]))
		else:
			data_files.append((doc, [os.path.join(pydir, "..", "LICENSE.txt")]))
	if sys.platform not in ("darwin", "win32") or do_py2app or do_py2exe:
		# Linux/Unix or py2app/py2exe
		data_files += get_data(data, "package_data", name,
							   excludes=["theme/icons/*"])
		data_files += get_data(data, "data")
		data_files += get_data(data, "xtra_package_data", name, sys.platform)
		if sys.platform == "win32":
			# Add python and pythonw
			data_files.extend([(os.path.join(data, "lib"), [sys.executable,
				os.path.join(os.path.dirname(sys.executable), "pythonw.exe")])])
			if use_sdl:
				# SDL DLLs for audio module
				sdl2 = ctypes.util.find_library("SDL2")
				sdl2_mixer = ctypes.util.find_library("SDL2_mixer")
				if sdl2:
					sdl2_libs = [sdl2]
					if sdl2_mixer:
						sdl2_libs.append(sdl2_mixer)
						data_files.append((os.path.join(data, "lib"), sdl2_libs))
						config["excludes"]["all"].append("pyglet")
					else:
						print("WARNING: SDL2_mixer not found!")
				else:
					print("WARNING: SDL2 not found!")
			if not "pyglet" in config["excludes"]["all"]:
				# OpenAL DLLs for pyglet
				openal32 = ctypes.util.find_library("OpenAL32.dll")
				wrap_oal = ctypes.util.find_library("wrap_oal.dll")
				if openal32:
					oal = [openal32]
					if wrap_oal:
						oal.append(wrap_oal)
					else:
						print("WARNING: wrap_oal.dll not found!")
					data_files.append((data, oal))
				else:
					print("WARNING: OpenAL32.dll not found!")
		elif sys.platform != "darwin":
			# Linux
			data_files.append((os.path.join(os.path.dirname(data), "metainfo"),
							   [os.path.join(pydir, "..", "dist", 
											 appstream_id + ".appdata.xml")]))
			data_files.append((os.path.join(os.path.dirname(data), 
											"applications"), 
							   [os.path.join(pydir, "..", "misc", name.lower() + 
											 ".desktop")] +
							   safe_glob(os.path.join(pydir, "..", "misc",
													  name.lower() + "-*.desktop"))))
			data_files.append((autostart if os.geteuid() == 0 or prefix.startswith("/")
							   else autostart_home, 
							   [os.path.join(pydir, "..", "misc", 
											 "z-%s-apply-profiles.desktop" % name.lower())]))
			data_files.append((os.path.join(os.path.dirname(data), "man", "man1"), 
							   safe_glob(os.path.join(pydir, "..", "man", "*.1"))))
			if not skip_instrument_conf_files:
				# device configuration / permission stuff
				if is_rpm_build:
					# RPM postinstall script will install these to the correct
					# locations. This allows us compatibility with Argyll
					# packages which may also contain same udev rules / hotplug
					# scripts, thus avoiding file conflicts
					data_files.append((os.path.join(data, "usb"), [os.path.join(
									   pydir, "..", "misc", "45-Argyll.rules")]))
					data_files.append((os.path.join(data, "usb"), [os.path.join(
									   pydir, "..", "misc", "55-Argyll.rules")]))
					data_files.append((os.path.join(data, "usb"), [os.path.join(
									   pydir, "..", "misc", "Argyll")]))
					data_files.append((os.path.join(data, "usb"), [os.path.join(
									   pydir, "..", "misc", "Argyll.usermap")]))
				else:
					devconf_files = []
					if os.path.isdir("/etc/udev/rules.d"):
						if safe_glob("/dev/bus/usb/*/*"):
							# USB and serial instruments using udev, where udev 
							# already creates /dev/bus/usb/00X/00X devices
							devconf_files.append(
								("/etc/udev/rules.d", [os.path.join(
									pydir, "..", "misc", "55-Argyll.rules")]))
						else:
							# USB using udev, where there are NOT /dev/bus/usb/00X/00X 
							# devices
							devconf_files.append(
								("/etc/udev/rules.d", [os.path.join(
									pydir, "..", "misc", "45-Argyll.rules")]))
					else:
						if os.path.isdir("/etc/hotplug"):
							# USB using hotplug and Serial using udev
							# (older versions of Linux)
							devconf_files.append(
								("/etc/hotplug/usb", [os.path.join(pydir, "..", "misc", 
																   fname) for fname in 
													  ["Argyll", "Argyll.usermap"]]))
					for entry in devconf_files:
						for fname in entry[1]:
							if os.path.isfile(fname):
								data_files.extend([(entry[0], [fname])])
		for dname in ("10x10", "16x16", "22x22", "24x24", "32x32", "48x48",
					  "72x72", "128x128", "256x256", "512x512"):
			# Get all the icons needed, depending on platform
			# Only the icon sizes 10, 16, 32, 72, 256 and 512 include icons
			# that are used exclusively for UI elements.
			# These should be installed in an app-specific location, e.g.
			# under Linux $XDG_DATA_DIRS/DisplayCAL/theme/icons/
			# The app icon sizes 16, 32, 48 and 256 (128 under Mac OS X),
			# which are used for taskbar icons and the like, as well as the
			# other sizes can be installed in a generic location, e.g.
			# under Linux $XDG_DATA_DIRS/icons/hicolor/<size>/apps/
			# Generally, icon filenames starting with the lowercase app name
			# should be installed in the generic location.
			icons = []
			desktopicons = []
			if sys.platform == "darwin":
				largest_iconbundle_icon_size = "128x128"
			else:
				largest_iconbundle_icon_size = "256x256"
			for iconpath in safe_glob(os.path.join(pydir, "theme", "icons", 
												   dname, "*.png")):
				if not os.path.basename(iconpath).startswith(name.lower()) or (
					sys.platform in ("darwin", "win32") and 
					dname in ("16x16", "32x32", "48x48",
							  largest_iconbundle_icon_size)):
					# In addition to UI element icons, we also need all the app
					# icons we use in get_icon_bundle under macOS/Windows,
					# otherwise they wouldn't be included (under Linux, these
					# are included for installation to the system-wide icon
					# theme location instead)
					icons.append(iconpath)
				elif sys.platform not in ("darwin", "win32"):
					desktopicons.append(iconpath)
			if icons:
				data_files.append((os.path.join(data, "theme", "icons", dname), 
								   icons))
			if desktopicons:
				data_files.append((os.path.join(os.path.dirname(data), "icons", 
											 "hicolor", dname, "apps"), 
								   desktopicons))
	if do_py2app:
		data_files.append((os.path.join(data, "scripts"),
						   [os.path.join(pydir, "..", "scripts",
										 name.lower() +
										 "-eecolor-to-madvr-converter")]))

	sources = [os.path.join(name, "RealDisplaySizeMM.c")]
	if sys.platform == "win32":
		macros = [("NT", None)]
		libraries = ["user32", "gdi32"]
		link_args = None
	elif sys.platform == "darwin":
		macros = [("__APPLE__", None), ("UNIX", None)]
		libraries = None
		# XXX: Not sure which macOS version exactly removed the need
		# to specify -framework
		if intlist(platform.mac_ver()[0].split(".")) >= [10, 7]:
			link_args = None
		else:
			link_args = ["-framework Carbon", "-framework CoreFoundation", 
							   "-framework Python", "-framework IOKit"]
			if not help and ("build" in sys.argv[1:] or 
							 "build_ext" in sys.argv[1:] or 
							 (("install" in sys.argv[1:] or 
							   "install_lib" in sys.argv[1:]) and 
							  not "--skip-build" in sys.argv[1:])):
				p = sp.Popen([sys.executable, '-c', '''import os
from distutils.core import setup, Extension

setup(ext_modules=[Extension("%s.lib%s.RealDisplaySizeMM", sources=%r, 
							 define_macros=%r, extra_link_args=%r)])''' % 
							  (name, bits, sources, macros, link_args)] + sys.argv[1:], 
							 stdout = sp.PIPE, stderr = sp.STDOUT)
				lines = []
				while True:
					o = p.stdout.readline()
					if o == '' and p.poll() != None:
						break
					if o[0:4] == 'gcc ':
						lines.append(o)
					print(o.rstrip())
				if len(lines):
					os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.5'
					sp.call(lines[-1], shell = True)  # fix the library
	else:
		macros = [("UNIX", None)]
		libraries = ["X11", "Xinerama", "Xrandr", "Xxf86vm"]
		link_args = None
	if sys.platform == "darwin":
		extname = "%s.lib%s.RealDisplaySizeMM" % (name, bits)
	else:
		extname = "%s.lib%s.python%s%s.RealDisplaySizeMM" % ((name, bits) + 
															 sys.version_info[:2])
	RealDisplaySizeMM = Extension(extname, 
								  sources=sources, 
								  define_macros=macros, 
								  libraries=libraries,
								  extra_link_args=link_args)
	ext_modules = [RealDisplaySizeMM]

	requires = []
	if not setuptools or sys.platform != "win32":
		# wxPython windows installer doesn't add egg-info entry, so
		# a dependency check from pkg_resources would always fail
		requires.append(
			"wxPython (>= %s)" % ".".join(str(n) for n in wx_minversion))
	if sys.platform == "win32":
		requires.append("pywin32 (>= 213.0)")

	packages = [name, "%s.lib" % name, "%s.lib.agw" % name]
	if sdist:
		# For source desributions we want all libraries
		for tmpbits in ("32", "64"):
			for pycompat in ("26", "27"):
				packages.extend(["%s.lib%s" % (name, tmpbits),
								 "%s.lib%s.python%s" % (name, tmpbits, pycompat)])
	elif sys.platform == "darwin":
		# On Mac OS X we only want the universal binaries
		packages.append("%s.lib%s" % (name, bits))
	else:
		# On Linux/Windows we want separate libraries
		packages.extend(["%s.lib%s" % (name, bits),
						 "%s.lib%s.python%s%s" % ((name, bits) + sys.version_info[:2])])
		

	attrs = {
		"author": author_ascii,
		"author_email": author_email.replace("@", "_at_"),
		"classifiers": [
			"Development Status :: 5 - Production/Stable",
			"Environment :: MacOS X",
			"Environment :: Win32 (MS Windows)",
			"Environment :: X11 Applications",
			"Intended Audience :: End Users/Desktop",
			"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
			"Operating System :: OS Independent",
			"Programming Language :: Python :: 2.6",
			"Programming Language :: Python :: 2.7",
			"Topic :: Multimedia :: Graphics",
		],
		"data_files": data_files,
		"description": description,
		"download_url": "https://%(domain)s/download/"
						"%(name)s-%(version)s.tar.gz" % 
						{"domain": domain, "name": name, "version": version},
		"ext_modules": ext_modules,
		"license": "GPL v3",
		"long_description": longdesc,
		"name": name,
		"packages": packages,
		"package_data": package_data,
		"package_dir": {
			name: name
		},
		"platforms": [
			"Python >= %s <= %s" % (".".join(str(n) for n in py_minversion),
									".".join(str(n) for n in py_maxversion)), 
			"Linux/Unix with X11", 
			"Mac OS X >= 10.4", 
			"Windows 2000 and newer"
		],
		"requires": requires,
		"provides": [name],
		"scripts": [],
		"url": "https://%s/" % domain,
		"version": msiversion if "bdist_msi" in sys.argv[1:] else version
	}

	if setuptools:
		attrs["entry_points"] = {
			"gui_scripts": [
				"%s = %s.main:main%s" % (script, name,
					"" if script == name.lower()
					else script[len(name):].lower().replace("-", "_"))
				for script, desc in scripts
			]
		}
		attrs["exclude_package_data"] = {
			name: ["RealDisplaySizeMM.c"]
		}
		attrs["include_package_data"] = sys.platform in ("darwin", "win32") and not do_py2app
		install_requires = [req.replace("(", "").replace(")", "") for req in 
							requires]
		attrs["install_requires"] = install_requires
		attrs["zip_safe"] = False
	else:
		attrs["scripts"].extend(os.path.join("scripts", script)
								for script, desc in
								[script_desc for script_desc in scripts if script_desc[0] != name.lower() + "-apply-profiles" or
									   sys.platform != "darwin"])
	
	if bdist_bbfreeze:
		attrs["setup_requires"] = ["bbfreeze"]

	if "bdist_wininst" in sys.argv[1:]:
		attrs["scripts"].append(os.path.join("util", name + "_postinstall.py"))
		
	if do_py2app:
		mainpy = os.path.join(basedir, "main.py")
		if not os.path.exists(mainpy):
			shutil.copy(os.path.join(basedir, "scripts", name.lower()), mainpy)
		attrs["app"] = [mainpy]
		dist_dir = os.path.join(pydir, "..", "dist", 
								"py2app.%s-py%s" % (get_platform(), 
													sys.version[:3]), 
								name + "-" + version)
		from py2app.build_app import py2app as py2app_cls
		py2app_cls._copy_package_data = py2app_cls.copy_package_data
		def copy_package_data(self, package, target_dir):
			# Skip package data which is already included as data files
			if package.identifier.split('.')[0] != name:
				self._copy_package_data(package, target_dir)
		py2app_cls.copy_package_data = copy_package_data
		attrs["options"] = {
			"py2app": {
				"argv_emulation": True,
				"dist_dir": dist_dir,
				"excludes": config["excludes"]["all"] +
							config["excludes"]["darwin"],
				"iconfile": os.path.join(pydir, "theme", "icons", 
										 name + ".icns"),
				"optimize": 0,
				"plist": plist_dict
			}
		}
		if use_sdl:
			attrs["options"]["py2app"]["frameworks"] = ["SDL2", "SDL2_mixer"]
		attrs["setup_requires"] = ["py2app"]

	if do_py2exe:
		import wx
		from winmanifest_util import getmanifestxml
		if platform.architecture()[0] == "64bit":
			arch = "amd64"
		else:
			arch = "x86"
		manifest_xml = getmanifestxml(os.path.join(pydir, "..", "misc", 
			name + (".exe.%s.VC90.manifest" % arch if hasattr(sys, "version_info") and 
			sys.version_info[:2] >= (2,6) else ".exe.manifest")))
		tmp_scripts_dir = os.path.join(basedir, "build", "temp.scripts")
		if not os.path.isdir(tmp_scripts_dir):
			os.makedirs(tmp_scripts_dir)
		apply_profiles_launcher = (appname.lower() + "-apply-profiles-launcher",
								   appname + " Profile Loader Launcher")
		for script, desc in scripts + [apply_profiles_launcher]:
			shutil.copy(os.path.join(basedir, "scripts", script),
						os.path.join(tmp_scripts_dir, script2pywname(script)))
		attrs["windows"] = [Target(**{
			"script": os.path.join(tmp_scripts_dir, script2pywname(script)),
			"icon_resources": [(1, os.path.join(pydir, "theme", "icons", 
												os.path.splitext(os.path.basename(script))[0] +
												".ico"))],
			"other_resources": [(24, 1, manifest_xml)],
			"copyright": "© %s %s" % (strftime("%Y"), author),
			"description": desc
		}) for script, desc in [script_desc1 for script_desc1 in scripts if script_desc1[0] != appname.lower() +
									  "-eecolor-to-madvr-converter" and
									  not script_desc1[0].endswith("-console")]]

		# Add profile loader launcher
		attrs["windows"].append(Target(**{
			"script": os.path.join(tmp_scripts_dir,
								   script2pywname(apply_profiles_launcher[0])),
			"icon_resources": [(1, os.path.join(pydir, "theme", "icons", 
												appname + "-apply-profiles" +
												".ico"))],
			"other_resources": [(24, 1, manifest_xml)],
			"copyright": "© %s %s" % (strftime("%Y"), author),
			"description": apply_profiles_launcher[1]
		}))

		# Programs that can run with and without GUI
		console_scripts = [name + "-VRML-to-X3D-converter"]  # No "-console" suffix!
		for console_script in console_scripts:
			console_script_path = os.path.join(tmp_scripts_dir,
											   console_script + "-console")
			if not os.path.isfile(console_script_path):
				shutil.copy(os.path.join(basedir, "scripts",
										 console_script.lower() + "-console"),
							console_script_path)
		attrs["console"] = [Target(**{
			"script": os.path.join(tmp_scripts_dir,
								   script2pywname(script) + "-console"),
			"icon_resources": [(1, os.path.join(pydir, "theme", "icons", 
												os.path.splitext(os.path.basename(script))[0] +
												".ico"))],
			"other_resources": [(24, 1, manifest_xml)],
			"copyright": "© %s %s" % (strftime("%Y"), author),
			"description": desc
		}) for script, desc in [script_desc2 for script_desc2 in scripts if script2pywname(script_desc2[0]) in console_scripts]]

		# Programs without GUI
		attrs["console"].append(Target(**{
			"script": os.path.join(tmp_scripts_dir,
								   appname + "-eeColor-to-madVR-converter"),
			"icon_resources": [(1, os.path.join(pydir, "theme", "icons", 
												appname + "-3DLUT-maker.ico"))],
			"other_resources": [(24, 1, manifest_xml)],
			"copyright": "© %s %s" % (strftime("%Y"), author),
			"description": "Convert eeColor 65^3 to madVR 256^3 3D LUT "
						   "(video levels in, video levels out)"
		}))

		dist_dir = os.path.join(pydir, "..", "dist", "py2exe.%s-py%s" % 
								(get_platform(), sys.version[:3]), name + 
								"-" + version)
		attrs["options"] = {
			"py2exe": {
				"dist_dir": dist_dir,
				"dll_excludes": [
					"iertutil.dll", 
					"MPR.dll",
					"msvcm90.dll", 
					"msvcp90.dll", 
					"msvcr90.dll", 
					"mswsock.dll",
					"urlmon.dll",
					"w9xpopen.exe"
				],
				"excludes": config["excludes"]["all"] +
							config["excludes"]["win32"], 
				"bundle_files": 3 if wx.VERSION >= (2, 8, 10, 1) else 1,
				"compressed": 1,
				"optimize": 0  # 0 = don’t optimize (generate .pyc)
							   # 1 = normal optimization (like python -O) 
							   # 2 = extra optimization (like python -OO)
			}
		}
		if debug:
			attrs["options"]["py2exe"].update({
				"bundle_files": 3,
				"compressed": 0,
				"optimize": 0,
				"skip_archive": 1
			})
		if setuptools:
			attrs["setup_requires"] = ["py2exe"]
		attrs["zipfile"] = os.path.join("lib", "library.zip")

	if (do_uninstall or do_install or bdist_win or bdist_dumb) and not help:
		distutils.core._setup_stop_after = "commandline"
		dist = setup(**attrs)
		distutils.core._setup_stop_after = None
		cmd = install(dist).get_finalized_command("install")
		if debug > 0:
			for attrname in [
				"base", 
				"data", 
				"headers", 
				"lib", 
				"libbase", 
				"platbase", 
				"platlib", 
				"prefix", 
				"purelib", 
				"root", 
				"scripts", 
				"userbase"
			]:
				if attrname not in ["prefix", "root"]:
					attrname = "install_" + attrname
				if hasattr(cmd, attrname):
					print(attrname, getattr(cmd, attrname))
		if debug > 1:
			try:
				from ppdir import ppdir
			except ImportError:
				pass
			else:
				ppdir(cmd, types=[dict, list, str, tuple, type, str])
		if not install_data and sys.platform in ("darwin", "win32"):
			# on Mac OS X and Windows, we want data files in the package dir
			data_basedir = cmd.install_lib
		else:
			data_basedir = cmd.install_data
		data = change_root(data_basedir, data)
		doc = change_root(data_basedir, doc)
		# determine in which cases we want to make data file paths relative to 
		# site-packages (on Mac and Windows) and when we want to make them 
		# absolute (Linux)
		linux = sys.platform not in ("darwin", "win32") and (not cmd.root and 
															 setuptools)
		dar_win = (sys.platform in ("darwin", "win32") and 
				   (cmd.root or not setuptools)) or bdist_win
		if not do_uninstall and not install_data and (linux or dar_win) and \
		   attrs["data_files"]:
			if data_basedir.startswith(cmd.install_data + os.path.sep):
				data_basedir = relpath(data_basedir, cmd.install_data)
			print("*** changing basedir for data_files:", data_basedir)
			for i, f in enumerate(attrs["data_files"]):
				if type(f) is StringType:
					attrs["data_files"][i] = change_root(data_basedir, f)
				else:
					attrs["data_files"][i] = (change_root(data_basedir, f[0]), 
											  f[1])

	if do_uninstall and not help:

		# Quick and dirty uninstall

		if dry_run:
			print("dry run - nothing will be removed")
		else:
			from postinstall import postuninstall
			# Yeah, yeah - its actually pre-uninstall
			if cmd.root:
				postuninstall(prefix=change_root(cmd.root, cmd.prefix))
			else:
				postuninstall(prefix=cmd.prefix)

		removed = []
		visited = []

		if os.path.exists(recordfile_name):
			paths = [(change_root(cmd.root, line.rstrip("\n")) if cmd.root else 
				line.rstrip("\n")) for line in open(recordfile_name, "r")]
		else:
			paths = []
		if not paths:
			# If the installed files have not been recorded, use some fallback 
			# logic to find them
			paths = safe_glob(os.path.join(cmd.install_scripts, name))
			if sys.platform == "win32":
				if setuptools:
					paths += safe_glob(os.path.join(cmd.install_scripts, 
													name + ".exe"))
					paths += safe_glob(os.path.join(cmd.install_scripts, 
													name + "-script.py"))
				else:
					paths += safe_glob(os.path.join(cmd.install_scripts, 
													name + ".cmd"))
			paths += safe_glob(os.path.join(cmd.install_scripts, name + 
											"_postinstall.py"))
			for attrname in [
				"data", 
				"headers", 
				"lib", 
				"libbase", 
				"platlib", 
				"purelib"
			]:
				path = os.path.join(getattr(cmd, "install_" + attrname), name)
				if not path in paths:
					# Using sys.version in this way is consistent with 
					# setuptools
					paths += safe_glob(path) + safe_glob(path + 
						("-%(version)s-py%(pyversion)s*.egg" % {
							"version": version, 
							"pyversion": sys.version[:3]
						})
					) + safe_glob(path + 
						("-%(version)s-py%(pyversion)s*.egg-info" % {
							"version": version, 
							"pyversion": sys.version[:3]
						})
					)
			if os.path.isabs(data) and not data in paths:
				for fname in [
					"lang",
					"presets",
					"ref",
					"report",
					"screenshots",
					"tests",
					"theme",
					"ti1",
					"x3d-viewer",
					"CHANGES.html",
					"LICENSE.txt",
					"README.html",
					"README-fr.html",
					"beep.wav",
					"cacert.pem",
					"camera_shutter.wav",
					"ColorLookupTable.fx",
					name.lower() + ".desktop",
					name.lower() + "-3dlut-maker.desktop",
					name.lower() + "-curve-viewer.desktop",
					name.lower() + "-profile-info.desktop",
					name.lower() + "-scripting-client.desktop",
					name.lower() + "-synthprofile.desktop",
					name.lower() + "-testchart-editor.desktop",
					"pnp.ids",
					"quirk.json",
					"linear.cal",
					"test.cal"
				]:
					path = os.path.join(data, fname)
					if not path in paths:
						paths += safe_glob(path)
			if os.path.isabs(doc) and not doc in paths:
				for fname in [
					"screenshots",
					"theme",
					"CHANGES.html",
					"LICENSE.txt",
					"README.html",
					"README-fr.html"
				]:
					path = os.path.join(doc, fname)
					if not path in paths:
						paths += safe_glob(path)
			if sys.platform == "win32":
				from postinstall import get_special_folder_path
				startmenu_programs_common = get_special_folder_path(
					"CSIDL_COMMON_PROGRAMS")
				startmenu_programs = get_special_folder_path("CSIDL_PROGRAMS")
				for path in (startmenu_programs_common, startmenu_programs):
					if path:
						for filename in (name, "CHANGES", "LICENSE", "README", 
										 "Uninstall"):
							paths += safe_glob(os.path.join(path, name, 
															filename + ".lnk"))

		for path in paths:
			if os.path.exists(path):
				if path in visited:
					continue
				else:
					visited.append(path)
				if dry_run:
					print(path)
					continue
				try:
					if os.path.isfile(path):
						os.remove(path)
					elif os.path.isdir(path):
						os.rmdir(path)
				except Exception as exception:
					print("could'nt remove", path)
					print("   ", exception)
				else:
					print("removed", path)
					removed.append(path)
			while path != os.path.dirname(path):
				# remove parent directories if empty
				# could also use os.removedirs(path) but we want some status 
				# info
				path = os.path.dirname(path)
				if os.path.isdir(path):
					if len(os.listdir(path)) == 0:
						if path in visited:
							continue
						else:
							visited.append(path)
						if dry_run:
							print(path)
							continue
						try:
							os.rmdir(path)
						except Exception as exception:
							print("could'nt remove", path)
							print("   ", exception)
						else:
							print("removed", path)
							removed.append(path)
					else:
						break

		if not removed:
			print(len(visited), "entries found")
		else:
			print(len(removed), "entries removed")

	else:

		# To have a working sdist and bdist_rpm when using distutils,
		# we go to the length of generating MANIFEST.in from scratch everytime, 
		# using the information available from setup.
		manifest_in = ["# This file will be re-generated by setup.py - do not"
					   "edit"]
		manifest_in.extend(["include LICENSE.txt", "include MANIFEST", 
							"include MANIFEST.in", "include README.html", 
							"include README-fr.html", "include CHANGES.html",
							"include %s*.pyw" % name, "include %s-*.pyw" % name,
							"include %s-*.py" % name, "include use-distutils"])
		manifest_in.append("include " + os.path.basename(sys.argv[0]))
		manifest_in.append("include " + 
						   os.path.splitext(os.path.basename(sys.argv[0]))[0] + 
						   ".cfg")
		for datadir, datafiles in attrs.get("data_files", []):
			for datafile in datafiles:
				manifest_in.append("include " + (
								   relpath(os.path.sep.join(datafile.split("/")), 
										   basedir) or datafile))
		for extmod in attrs.get("ext_modules", []):
			manifest_in.extend("include " + os.path.sep.join(src.split("/")) 
							   for src in extmod.sources)
		for pkg in attrs.get("packages", []):
			pkg = os.path.join(*pkg.split("."))
			pkgdir = os.path.sep.join(attrs.get("package_dir", 
												{}).get(pkg, pkg).split("/"))
			manifest_in.append("include " + os.path.join(pkgdir, "*.py"))
			manifest_in.append("include " + os.path.join(pkgdir, "*.pyd"))
			manifest_in.append("include " + os.path.join(pkgdir, "*.so"))
			for obj in attrs.get("package_data", {}).get(pkg, []):
				manifest_in.append("include " + os.path.sep.join([pkgdir] + 
																 obj.split("/")))
		for pymod in attrs.get("py_modules", []):
			manifest_in.append("include " + os.path.join(*pymod.split(".")))
		manifest_in.append("include " + 
						   os.path.join(name, "theme", "theme-info.txt"))
		manifest_in.append("recursive-include %s %s %s" % 
						   (os.path.join(name, "theme", "icons"), 
						   "*.icns", "*.ico"))
		manifest_in.append("include " + os.path.join("man", "*.1"))
		manifest_in.append("recursive-include %s %s" % ("misc", "*"))
		if skip_instrument_conf_files:
			manifest_in.extend([
				"exclude misc/Argyll",
				"exclude misc/*.rules",
				"exclude misc/*.usermap",
			])
		manifest_in.append("include " + os.path.join("screenshots", "*.png"))
		manifest_in.append("include " + os.path.join("scripts", "*"))
		manifest_in.append("include " + os.path.join("tests", "*"))
		manifest_in.append("recursive-include %s %s" % ("theme", "*"))
		manifest_in.append("recursive-include %s %s" % ("util", 
														"*.cmd *.py *.sh"))
		if sys.platform == "win32" and not setuptools:
			# Only needed under Windows
			manifest_in.append("global-exclude .svn/*")
		manifest_in.append("global-exclude *~")
		manifest_in.append("global-exclude *.backup")
		manifest_in.append("global-exclude *.bak")
		if not dry_run:
			manifest = open("MANIFEST.in", "w")
			manifest.write("\n".join(manifest_in))
			manifest.close()
			if os.path.exists("MANIFEST"):
				os.remove("MANIFEST")

		if bdist_bbfreeze:
			i = sys.argv.index("bdist_bbfreeze")
			if not "-d" in sys.argv[i + 1:] and \
			   not "--dist-dir" in sys.argv[i + 1:]:
				dist_dir = os.path.join(pydir, "..", "dist", 
										"bbfreeze.%s-py%s" % (get_platform(), 
															  sys.version[:3]))
				sys.argv.insert(i + 1, "--dist-dir=" + dist_dir)
			if not "egg_info" in sys.argv[1:i]:
				sys.argv.insert(i, "egg_info")

		if do_py2app or do_py2exe:
			sys.path.insert(1, pydir)
			i = sys.argv.index("py2app" if do_py2app else "py2exe")
			if not "build_ext" in sys.argv[1:i]:
				sys.argv.insert(i, "build_ext")

		setup(**attrs)
		
		if dry_run or help:
			return
		
		if do_py2app:
			frameworks_dir = os.path.join(dist_dir, name + ".app",
										  "Contents", "Frameworks")
			lib_dynload_dir = os.path.join(dist_dir, name + ".app", "Contents",
										   "Resources", "lib", "python%s.%s" %
										   sys.version_info[:2], "lib-dynload")
			# Fix Pillow (PIL) dylibs not being included
			pil_dylibs = os.path.join(lib_dynload_dir, "PIL", ".dylibs")
			if not os.path.isdir(pil_dylibs):
				import PIL
				pil_installed_dylibs = os.path.join(os.path.dirname(PIL.__file__),
													".dylibs")
				print("Copying", pil_installed_dylibs, "->", pil_dylibs)
				shutil.copytree(pil_installed_dylibs,
								pil_dylibs)
				for entry in os.listdir(pil_dylibs):
					print(os.path.join(pil_dylibs, entry))
				# Remove wrongly included frameworks
				dylibs_entries = os.listdir(pil_installed_dylibs)
				for entry in os.listdir(frameworks_dir):
					if entry in dylibs_entries:
						dylib = os.path.join(frameworks_dir, entry)
						print("Removing", dylib)
						os.remove(dylib)
			import wx
			if wx.VERSION >= (4, ):
				# Fix wxPython 4 dylibs being included in wrong location
				wx_dylibs = os.path.join(lib_dynload_dir, "wx")
				for entry in os.listdir(frameworks_dir):
					if entry.startswith("libwx"):
						dylib = os.path.join(frameworks_dir, entry)
						lib_dylib = os.path.join(wx_dylibs, entry)
						print("Moving", dylib, "->", lib_dylib)
						shutil.move(dylib, lib_dylib)
			

			create_app_symlinks(dist_dir, scripts)
		
		if do_py2exe:
			shutil.copy(os.path.join(dist_dir, "python%s.dll" %
											   (sys.version[0] + sys.version[2])),
						os.path.join(dist_dir, "lib", "python%s.dll" %
											   (sys.version[0] + sys.version[2])))

		if ((bdist_bbfreeze and sys.platform == "win32") or do_py2exe) and \
		   sys.version_info[:2] >= (2,6):
			from vc90crt import name as vc90crt_name, vc90crt_copy_files
			if do_py2exe:
				vc90crt_copy_files(dist_dir)
				vc90crt_copy_files(os.path.join(dist_dir, 
												"lib"))
			else:
				vc90crt_copy_files(os.path.join(dist_dir, 
												name + "-" + version))
		
		if do_full_install and not is_rpm_build and not skip_postinstall:
			from postinstall import postinstall
			if sys.platform == "win32":
				path = os.path.join(cmd.install_lib, name)
				# Using sys.version in this way is consistent with setuptools
				for path in safe_glob(path) + safe_glob(
					os.path.join(path + (
						"-%(version)s-py%(pyversion)s*.egg" % 
						{
							"version": version, 
							"pyversion": sys.version[:3]
						}
					), name)
				):
					if cmd.root:
						postinstall(prefix=change_root(cmd.root, path))
					else:
						postinstall(prefix=path)
						
			elif cmd.root:
				postinstall(prefix=change_root(cmd.root, cmd.prefix))
			else:
				postinstall(prefix=cmd.prefix)
コード例 #35
0
def get_bin_dir():
    d = install(Distribution())
    d.finalize_options()
    return d.install_scripts
コード例 #36
0
ファイル: test_install.py プロジェクト: termim/setuptools
    def test_user_site(self):
        # test install with --user
        # preparing the environment for the test
        self.old_user_base = site.USER_BASE
        self.old_user_site = site.USER_SITE
        self.tmpdir = self.mkdtemp()
        self.user_base = os.path.join(self.tmpdir, 'B')
        self.user_site = os.path.join(self.tmpdir, 'S')
        site.USER_BASE = self.user_base
        site.USER_SITE = self.user_site
        install_module.USER_BASE = self.user_base
        install_module.USER_SITE = self.user_site

        def _expanduser(path):
            if path.startswith('~'):
                return os.path.normpath(self.tmpdir + path[1:])
            return path

        self.old_expand = os.path.expanduser
        os.path.expanduser = _expanduser

        def cleanup():
            site.USER_BASE = self.old_user_base
            site.USER_SITE = self.old_user_site
            install_module.USER_BASE = self.old_user_base
            install_module.USER_SITE = self.old_user_site
            os.path.expanduser = self.old_expand

        self.addCleanup(cleanup)

        for key in ('nt_user', 'posix_user'):
            self.assertIn(key, INSTALL_SCHEMES)

        dist = Distribution({'name': 'xx'})
        cmd = install(dist)

        # making sure the user option is there
        options = [name for name, short, lable in cmd.user_options]
        self.assertIn('user', options)

        # setting a value
        cmd.user = 1

        # user base and site shouldn't be created yet
        self.assertFalse(os.path.exists(self.user_base))
        self.assertFalse(os.path.exists(self.user_site))

        # let's run finalize
        cmd.ensure_finalized()

        # now they should
        self.assertTrue(os.path.exists(self.user_base))
        self.assertTrue(os.path.exists(self.user_site))

        self.assertIn('userbase', cmd.config_vars)
        self.assertIn('usersite', cmd.config_vars)

        actual_headers = os.path.relpath(cmd.install_headers, self.user_base)
        if os.name == 'nt':
            site_path = os.path.relpath(os.path.dirname(self.old_user_site),
                                        self.old_user_base)
            include = os.path.join(site_path, 'Include')
        else:
            include = sysconfig.get_python_inc(0, '')
        expect_headers = os.path.join(include, 'xx')

        self.assertEqual(os.path.normcase(actual_headers),
                         os.path.normcase(expect_headers))
コード例 #37
0
ファイル: bdist.py プロジェクト: yhat/pip-accel
    def build_binary_dist_helper(self, requirement):
        """
        Convert a single, unpacked source distribution to a binary
        distribution. Raises an exception if it fails to create the binary
        distribution (probably because of missing binary dependencies like
        system libraries).

        :param requirement: A :py:class:`.Requirement` object.
        :returns: The pathname of the resulting binary distribution (a string).
        :raises: :py:exc:`.BuildFailed` when the build reports an error.
        :raises: :py:exc:`.NoBuildOutput` when the build does not produce the
                 expected binary distribution archive.
        """
        build_timer = Timer()
        # Make sure the source distribution contains a setup script.
        setup_script = os.path.join(requirement.source_directory, 'setup.py')
        if not os.path.isfile(setup_script):
            msg = "Directory %s (%s %s) doesn't contain a source distribution!"
            raise InvalidSourceDistribution(
                msg % (requirement.source_directory, requirement.name,
                       requirement.version))
        # Let the user know what's going on.
        build_text = "Building %s (%s) binary distribution" % (
            requirement.name, requirement.version)
        logger.info("%s ..", build_text)
        # Cleanup previously generated distributions.
        dist_directory = os.path.join(requirement.source_directory, 'dist')
        if os.path.isdir(dist_directory):
            logger.debug(
                "Cleaning up previously generated distributions in %s ..",
                dist_directory)
            shutil.rmtree(dist_directory)
        makedirs(dist_directory)
        # Create a temporary directory for pip installing into, and set up the
        # install_lib directory structure inside it. We do this so that we can
        # pip install into this as our target.
        temporary_dir = tempfile.mkdtemp()
        distutils_inst = install(Distribution())
        distutils_inst.prefix = ''  # This will be changed if we're in a virtualenv.
        distutils_inst.finalize_options()
        pip_target = os.path.normpath(temporary_dir +
                                      distutils_inst.install_lib)
        # Compose the command line needed to build the binary distribution.
        command_line = ' '.join(
            pipes.quote(t)
            for t in ['pip', 'install', '.', '--target', pip_target])
        logger.debug("Executing external command: %s", command_line)
        # Redirect all output of the build to a temporary file.
        fd, temporary_file = tempfile.mkstemp()
        command_line = '%s > "%s" 2>&1' % (command_line, temporary_file)

        try:
            # Start the build.
            build = subprocess.Popen(['sh', '-c', command_line],
                                     cwd=requirement.source_directory)
            # Wait for the build to finish and provide feedback to the user in the mean time.
            spinner = Spinner(label=build_text, timer=build_timer)
            while build.poll() is None:
                spinner.step()
                # Don't tax the CPU too much.
                time.sleep(0.2)
            spinner.clear()

            # At this point, we may have a number of dependencies in the directory we want
            # to tar up that should not be part of the package distribution. For instance,
            # s3 will also wrap up the concurrent, futures, and requests packages. We fix
            # this by reading {name}-{version}-{py-version}.egg-info/installed-files.txt
            # and removing any files or directories that are not in it.

            # 1. Find the appropriate .egg-info/ directory.
            egg_info_dir = None
            egg_info_start = '-'.join([requirement.name, requirement.version])
            for egg_info_root, dirs, _ in os.walk(temporary_dir):
                for d in dirs:
                    if d.startswith(egg_info_start) and d.endswith(
                            '.egg-info'):
                        egg_info_dir = d
                        break
                if egg_info_dir is not None:
                    break

            # 2. If we have a .egg-info/, try to read the installed-files.txt contents.
            inst_files = set()
            if egg_info_dir is not None:
                egg_info_path = os.path.join(egg_info_root, egg_info_dir)
                inst_files_path = os.path.join(egg_info_path,
                                               'installed-files.txt')
                try:
                    with open(inst_files_path) as f:
                        for line in f:
                            abs_path = os.path.abspath(
                                os.path.join(egg_info_path, line.strip()))
                            inst_files.add(abs_path)
                            inst_files.add(os.path.dirname(abs_path))
                except IOError, ioe:
                    loger.warn('Unable to open %s: %s' %
                               (inst_files_path, ioe))

            # 3. If we were able to get a set of files and directories that belong in the
            #    distribution, then we can delete everything else before archiving it.
            if inst_files:
                dirs, files = next(os.walk(egg_info_root))[1:]
                for d in dirs:
                    d = os.path.abspath(os.path.join(egg_info_root, d))
                    if d not in inst_files:
                        logger.info('Removing %s (not part of the package)' %
                                    d)
                        shutil.rmtree(d)

                for f in files:
                    f = os.path.abspath(os.path.join(egg_info_root, f))
                    if f not in inst_files:
                        logger.info('Removing %s (not part of the package)' %
                                    f)
                        os.unlink(f)

            # Tar up the contents of temporary_dir into the correct file name and put it in the dist dir.
            tarball_path = os.path.join(temporary_dir, requirement.name)
            path = archive_util.make_archive(tarball_path,
                                             'gztar',
                                             root_dir=temporary_dir)
            shutil.copy(path, dist_directory)

            # Make sure the build succeeded and produced a binary distribution archive.
            try:
                # If the build reported an error we'll try to provide the user with
                # some hints about what went wrong.
                if build.returncode != 0:
                    raise BuildFailed(
                        "Failed to build {name} ({version}) binary distribution!",
                        name=requirement.name,
                        version=requirement.version)
                # Check if the build created the `dist' directory (the os.listdir()
                # call below will raise an exception if we don't check for this).
                if not os.path.isdir(dist_directory):
                    raise NoBuildOutput(
                        "Build of {name} ({version}) did not produce a binary distribution archive!",
                        name=requirement.name,
                        version=requirement.version)
                # Check if we can find the binary distribution archive.
                filenames = os.listdir(dist_directory)
                if len(filenames) != 1:
                    raise NoBuildOutput(
                        "Build of {name} ({version}) produced more than one distribution archive! (matches: {filenames})",
                        name=requirement.name,
                        version=requirement.version,
                        filenames=concatenate(sorted(filenames)))
            except Exception as e:
                # Decorate the exception with the output of the failed build.
                with open(temporary_file) as handle:
                    build_output = handle.read()
                enhanced_message = compact("""
                    {message}

                    Please check the build output because it will probably
                    provide a hint about what went wrong.

                    Build output:

                    {output}
                """,
                                           message=e.args[0],
                                           output=build_output.strip())
                e.args = (enhanced_message, )
                raise
            logger.info("Finished building %s (%s) in %s.", requirement.name,
                        requirement.version, build_timer)
            return os.path.join(dist_directory, filenames[0])
コード例 #38
0
ファイル: common.py プロジェクト: mattnewham/canari
def get_bin_dir():
    d = install(Distribution())
    d.finalize_options()
    return d.install_scripts
コード例 #39
0
ファイル: findInstallDir.py プロジェクト: alios/jsbsim
import sys, os
from distutils.dist import Distribution
from distutils.command.install import install

cmd = install(Distribution())
cmd.ensure_finalized()
path = cmd.install_lib

if "VIRTUAL_ENV" in os.environ:
    path = os.path.relpath(path, os.environ["VIRTUAL_ENV"])

sys.stdout.write(path)
コード例 #40
0
def get_install_command(name):
    # late binding due to potential monkeypatching
    d = dist.Distribution({'name':name})
    i = install.install(d)
    i.finalize_options()
    return i
コード例 #41
0
ファイル: setup.py プロジェクト: zhnlks/ctp-python
def get_install_data_dir():
    d = dist.Distribution()
    install_cmd = dist_install.install(d)
    install_cmd.finalize_options()
    return install_cmd.install_data