Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec6229e

Browse files
committed
Make distutils "install --home" support all platforms.
1 parent 8d726ee commit ec6229e

4 files changed

Lines changed: 96 additions & 34 deletions

File tree

Doc/inst/inst.tex

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -384,26 +384,26 @@ \section{Alternate Installation}
384384
of the following sections applies to you.
385385

386386

387-
\subsection{Alternate installation: \UNIX{} (the home scheme)}
387+
\subsection{Alternate installation: the home scheme}
388388
\label{alt-install-prefix}
389389

390-
Under \UNIX, there are two ways to perform an alternate installation.
391-
The ``prefix scheme'' is similar to how alternate installation works
392-
under Windows and Mac OS, but is not necessarily the most useful way to
393-
maintain a personal Python library. Hence, we document the more
394-
convenient and commonly useful ``home scheme'' first.
395-
396390
The idea behind the ``home scheme'' is that you build and maintain a
397-
personal stash of Python modules, probably under your home directory.
391+
personal stash of Python modules. This scheme's name is derived from
392+
the idea of a ``home'' directory on \UNIX, since it's not unusual for
393+
a \UNIX{} user to make their home directory have a layout similar to
394+
\file{/usr/} or \file{/usr/local/}. This scheme can be used by
395+
anyone, regardless of the operating system their installing for.
396+
398397
Installing a new module distribution is as simple as
399398

400399
\begin{verbatim}
401400
python setup.py install --home=<dir>
402401
\end{verbatim}
403402

404-
where you can supply any directory you like for the \longprogramopt{home}
405-
option. Lazy typists can just type a tilde (\code{\textasciitilde}); the
406-
\command{install} command will expand this to your home directory:
403+
where you can supply any directory you like for the
404+
\longprogramopt{home} option. On \UNIX, lazy typists can just type a
405+
tilde (\code{\textasciitilde}); the \command{install} command will
406+
expand this to your home directory:
407407

408408
\begin{verbatim}
409409
python setup.py install --home=~
@@ -417,6 +417,11 @@ \subsection{Alternate installation: \UNIX{} (the home scheme)}
417417
{home}{/bin}
418418
{home}{/share}
419419

420+
421+
\versionchanged[The \longprogramopt{home} option used to be supported
422+
only on \UNIX]{2.4}
423+
424+
420425
\subsection{Alternate installation: \UNIX{} (the prefix scheme)}
421426
\label{alt-install-home}
422427

@@ -491,14 +496,13 @@ \subsection{Alternate installation: \UNIX{} (the prefix scheme)}
491496
point to an alternate Python installation, this is immaterial.)
492497

493498

494-
\subsection{Alternate installation: Windows}
499+
\subsection{Alternate installation: Windows (the prefix scheme)}
495500
\label{alt-install-windows}
496501

497-
Since Windows has no conception of a user's home directory, and since
498-
the standard Python installation under Windows is simpler than that
499-
under \UNIX, there's no point in having separate \longprogramopt{prefix}
500-
and \longprogramopt{home} options. Just use the \longprogramopt{prefix}
501-
option to specify a base directory, e.g.
502+
Windows has no concept of a user's home directory, and since the
503+
standard Python installation under Windows is simpler than under
504+
\UNIX, the \longprogramopt{prefix} option has traditionally been used
505+
to install additional packages in separate locations on Windows.
502506

503507
\begin{verbatim}
504508
python setup.py install --prefix="\Temp\Python"

Lib/distutils/command/install.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,15 @@ def finalize_options (self):
242242
("must supply either prefix/exec-prefix/home or " +
243243
"install-base/install-platbase -- not both")
244244

245+
if self.home and (self.prefix or self.exec_prefix):
246+
raise DistutilsOptionError, \
247+
"must supply either home or prefix/exec-prefix -- not both"
248+
245249
# Next, stuff that's wrong (or dubious) only on certain platforms.
246-
if os.name == 'posix':
247-
if self.home and (self.prefix or self.exec_prefix):
248-
raise DistutilsOptionError, \
249-
("must supply either home or prefix/exec-prefix -- " +
250-
"not both")
251-
else:
250+
if os.name != "posix":
252251
if self.exec_prefix:
253252
self.warn("exec-prefix option ignored on this platform")
254253
self.exec_prefix = None
255-
if self.home:
256-
self.warn("home option ignored on this platform")
257-
self.home = None
258254

259255
# Now the interesting logic -- so interesting that we farm it out
260256
# to other methods. The goal of these methods is to set the final
@@ -405,15 +401,19 @@ def finalize_unix (self):
405401

406402
def finalize_other (self): # Windows and Mac OS for now
407403

408-
if self.prefix is None:
409-
self.prefix = os.path.normpath(sys.prefix)
404+
if self.home is not None:
405+
self.install_base = self.install_platbase = self.home
406+
self.select_scheme("unix_home")
407+
else:
408+
if self.prefix is None:
409+
self.prefix = os.path.normpath(sys.prefix)
410410

411-
self.install_base = self.install_platbase = self.prefix
412-
try:
413-
self.select_scheme(os.name)
414-
except KeyError:
415-
raise DistutilsPlatformError, \
416-
"I don't know how to install stuff on '%s'" % os.name
411+
self.install_base = self.install_platbase = self.prefix
412+
try:
413+
self.select_scheme(os.name)
414+
except KeyError:
415+
raise DistutilsPlatformError, \
416+
"I don't know how to install stuff on '%s'" % os.name
417417

418418
# finalize_other ()
419419

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Tests for distutils.command.install."""
2+
3+
import os
4+
import unittest
5+
6+
from distutils.command.install import install
7+
from distutils.core import Distribution
8+
9+
from distutils.tests import support
10+
11+
12+
class InstallTestCase(support.TempdirManager, unittest.TestCase):
13+
14+
def test_home_installation_scheme(self):
15+
# This ensure two things:
16+
# - that --home generates the desired set of directory names
17+
# - test --home is supported on all platforms
18+
builddir = self.mkdtemp()
19+
destination = os.path.join(builddir, "installation")
20+
21+
dist = Distribution({"name": "foopkg"})
22+
# script_name need not exist, it just need to be initialized
23+
dist.script_name = os.path.join(builddir, "setup.py")
24+
dist.command_obj["build"] = support.DummyCommand(
25+
build_base=builddir,
26+
build_lib=os.path.join(builddir, "lib"),
27+
)
28+
29+
cmd = install(dist)
30+
cmd.home = destination
31+
cmd.ensure_finalized()
32+
33+
self.assertEqual(cmd.install_base, destination)
34+
self.assertEqual(cmd.install_platbase, destination)
35+
36+
def check_path(got, expected):
37+
got = os.path.normpath(got)
38+
expected = os.path.normpath(expected)
39+
self.assertEqual(got, expected)
40+
41+
libdir = os.path.join(destination, "lib", "python")
42+
check_path(cmd.install_lib, libdir)
43+
check_path(cmd.install_platlib, libdir)
44+
check_path(cmd.install_purelib, libdir)
45+
check_path(cmd.install_headers,
46+
os.path.join(destination, "include", "python", "foopkg"))
47+
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
48+
check_path(cmd.install_data, destination)
49+
50+
51+
def test_suite():
52+
return unittest.makeSuite(InstallTestCase)
53+
54+
if __name__ == "__main__":
55+
unittest.main(defaultTest="test_suite")

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ Library
365365
- refactored site.py into functions. Also wrote regression tests for the
366366
module.
367367

368+
- The distutils install command now supports the --home option and
369+
installation scheme for all platforms.
370+
368371
- The distutils sdist command now ignores all .svn directories, in
369372
addition to CVS and RCS directories. .svn directories hold
370373
administrative files for the Subversion source control system.

0 commit comments

Comments
 (0)