1 from distutils
.core
import setup
2 from distutils
.util
import convert_path
3 from distutils
.core
import Command
4 from distutils
.command
.build_py
import build_py
5 from distutils
.command
.install
import install
6 from distutils
.command
.install_lib
import install_lib
7 from distutils
.command
.install_data
import install_data
8 import os
, subprocess
, sys
12 class adjust_scripts_for_home(Command
):
13 """setup.py install --home puts libraries in ~/lib/python, but Python doesn't look there.
14 If we're installing with --home, modify the scripts to add this to sys.path.
15 Don't do this otherwise; the system copy mustn't conflict with the copy in $HOME.
17 description
= "(used internally when using --home)"
20 ('scripts-dir=', 'd', "directory to install scripts to"),
21 ('lib-dir=', 'd', "directory libraries install to"),
24 def initialize_options (self
):
25 self
.scripts_dir
= None
28 def finalize_options (self
):
29 self
.set_undefined_options('install',
30 ('install_scripts', 'scripts_dir'),
31 ('install_lib', 'lib_dir'),
35 for script
in self
.distribution
.scripts
:
36 outfile
= os
.path
.join(self
.scripts_dir
, os
.path
.basename(script
))
38 stream
= open(outfile
)
42 code
= code
.replace('## PATH ##', '''
44 sys.path.insert(0, %s)''' % repr(self
.lib_dir
))
45 stream
= open(outfile
, 'w')
49 class build_with_data(build_py
):
50 """Python < 2.4 doesn't support package_data_files, so add it manually."""
51 package_data_files
= []
53 # Copy .py files and build, as usual
56 for data_file
in self
.package_data_files
:
57 outfile
= os
.path
.join(self
.build_lib
, data_file
)
58 self
.copy_file(data_file
, outfile
, preserve_mode
=0)
59 executable
= (os
.stat(data_file
).st_mode
& 0111) != 0
61 os
.chmod(outfile
, os
.stat(outfile
).st_mode |
0111)
63 class install_lib_exec(install_lib
):
65 install_lib
.run(self
) # super.run()
67 class install_data_locale(install_data
):
69 self
.data_files
.extend(self
._compile
_po
_files
())
70 install_data
.run(self
) # super.run()
72 def _compile_po_files(self
):
74 for mo
in glob
.glob("locale/*/LC_MESSAGES/zero-install.mo"):
75 dest
= os
.path
.dirname(os
.path
.join('share', mo
))
76 i18nfiles
.append((dest
, [mo
]))
79 # distutils doesn't seem to have any support for adding configuration files.
80 # Unfortunately, the freedesktop.org menu spec strangely defines part of the
81 # menu definitions as configuration.
82 class my_install(install
):
83 def finalize_options(self
):
84 install
.finalize_options(self
) # super.finalize_options()
86 self
.__config
_dir
= os
.path
.join(self
.home
, '.config')
87 elif self
.prefix
== '/usr':
88 self
.__config
_dir
= os
.path
.join(self
.root
or '/', 'etc/xdg')
90 self
.__config
_dir
= os
.path
.join(self
.root
or '/', self
.prefix
[1:], 'etc/xdg')
93 install
.run(self
) # super.run()
94 menus_dir
= os
.path
.join(self
.__config
_dir
, 'menus/applications-merged')
95 self
.mkpath(menus_dir
)
96 menu
= convert_path('share/applications/zeroinstall.menu')
97 self
.copy_file(menu
, menus_dir
)
99 setup(name
="zeroinstall-solver",
100 version
=zeroinstall
.version
,
101 description
="The Zero Install Solver (0solve)",
102 author
="Thomas Leonard",
103 author_email
="zero-install-devel@lists.sourceforge.net",
104 url
="http://0install.net",
109 'build_py': build_with_data
,
110 'install_lib': install_lib_exec
,
111 'install_data': install_data_locale
,
112 'adjust_scripts_for_home': adjust_scripts_for_home
,
113 'install': my_install
,
115 long_description
="""\
116 A running process is created by combining many different libraries (and other
117 components). In the Zero Install world, we have all versions of each library
118 available at all times. The problem then is how to choose which versions to
121 The injector solves this problem by selecting components to meet a program's
122 requirements, according to a policy you give it. The injector finds out which
123 versions are available, and downloads and runs the ones you choose.""",
124 packages
=["zeroinstall", "zeroinstall.support", "zeroinstall.zerostore", "zeroinstall.injector"])