Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Mac/pythonw
Misc/python.pc
Misc/python-embed.pc
Misc/python-config.sh
Modules/Setup.bootstrap
Modules/Setup.config
Modules/Setup.local
Modules/Setup.stdlib
Expand Down
5 changes: 4 additions & 1 deletion Lib/distutils/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,10 @@ def test_check_environ_getpwuid(self):
util._environ_checked = 0
os.environ.pop('HOME', None)

import pwd
try:
import pwd
except ImportError:
raise unittest.SkipTest("Test requires pwd module.")

# only set pw_dir field, other fields are not used
result = pwd.struct_passwd((None, None, None, None, None,
Expand Down
12 changes: 10 additions & 2 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ def expanduser(path):
i = len(path)
if i == 1:
if 'HOME' not in os.environ:
import pwd
try:
import pwd
except ImportError:
# pwd module unavailable, return path unchanged
return path
try:
userhome = pwd.getpwuid(os.getuid()).pw_dir
except KeyError:
Expand All @@ -251,7 +255,11 @@ def expanduser(path):
else:
userhome = os.environ['HOME']
else:
import pwd
try:
import pwd
except ImportError:
# pwd module unavailable, return path unchanged
return path
name = path[1:i]
if isinstance(name, bytes):
name = str(name, 'ASCII')
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,9 @@ def _test_home(self, p):
self.assertIs(type(p), type(q))
self.assertTrue(p.is_absolute())

@unittest.skipIf(
pwd is None, reason="Test requires pwd module to get homedir."
)
def test_home(self):
with os_helper.EnvironmentVarGuard() as env:
self._test_home(self.cls.home())
Expand Down
7 changes: 6 additions & 1 deletion Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
import time
import os
import platform
import pwd
import stat
import tempfile
import unittest
import warnings
import textwrap
from contextlib import contextmanager

try:
import pwd
except ImportError:
pwd = None

_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
os_helper.TESTFN + '-dummy-symlink')

Expand Down Expand Up @@ -126,6 +130,7 @@ def test_setresgid_exception(self):

@unittest.skipUnless(hasattr(posix, 'initgroups'),
"test needs os.initgroups()")
@unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")
def test_initgroups(self):
# It takes a string and an integer; check that it raises a TypeError
# for other argument lists.
Expand Down
14 changes: 9 additions & 5 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,9 @@ Modules/Setup.local:
@# Create empty Setup.local when file was deleted by user
echo "# Edit this file for local setup changes" > $@

Modules/Setup.bootstrap: $(srcdir)/Modules/Setup.bootstrap.in config.status
./config.status $@

Modules/Setup.stdlib: $(srcdir)/Modules/Setup.stdlib.in config.status
./config.status $@

Expand All @@ -925,13 +928,13 @@ Makefile Modules/config.c: Makefile.pre \
$(MAKESETUP) \
$(srcdir)/Modules/Setup \
Modules/Setup.local \
$(srcdir)/Modules/Setup.bootstrap \
Modules/Setup.bootstrap \
Modules/Setup.stdlib
$(SHELL) $(MAKESETUP) -c $(srcdir)/Modules/config.c.in \
-s Modules \
Modules/Setup.local \
@MODULES_SETUP_STDLIB@ \
$(srcdir)/Modules/Setup.bootstrap \
Modules/Setup.bootstrap \
$(srcdir)/Modules/Setup
@mv config.c Modules
@echo "The Makefile was updated, you may need to re-run make."
Expand Down Expand Up @@ -2146,7 +2149,7 @@ libainstall: @DEF_MAKE_RULE@ python-config
$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
$(INSTALL_DATA) $(srcdir)/Modules/Setup $(DESTDIR)$(LIBPL)/Setup
$(INSTALL_DATA) $(srcdir)/Modules/Setup.bootstrap $(DESTDIR)$(LIBPL)/Setup.bootstrap
$(INSTALL_DATA) Modules/Setup.bootstrap $(DESTDIR)$(LIBPL)/Setup.bootstrap
$(INSTALL_DATA) Modules/Setup.stdlib $(DESTDIR)$(LIBPL)/Setup.stdlib
$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
Expand Down Expand Up @@ -2381,8 +2384,9 @@ distclean: clobber
for file in $(srcdir)/Lib/test/data/* ; do \
if test "$$file" != "$(srcdir)/Lib/test/data/README"; then rm "$$file"; fi; \
done
-rm -f core Makefile Makefile.pre config.status Modules/Setup.local \
Modules/Setup.stdlib Modules/ld_so_aix Modules/python.exp Misc/python.pc \
-rm -f core Makefile Makefile.pre config.status Modules/Setup.local
Modules/Setup.bootstrap Modules/Setup.stdlib \
Modules/ld_so_aix Modules/python.exp Misc/python.pc \
Misc/python-embed.pc Misc/python-config.sh
-rm -f python*-gdb.py
# Issue #28258: set LC_ALL to avoid issues with Estonian locale.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :mod:`pwd` module is now optional. :func:`os.path.expanduser` returns the path when the :mod:`pwd` module is not available.
2 changes: 1 addition & 1 deletion Modules/Setup.bootstrap → Modules/Setup.bootstrap.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ _stat _stat.c
_symtable symtablemodule.c

# for systems without $HOME env, used by site._getuserbase()
pwd pwdmodule.c
@MODULE_PWD_TRUE@pwd pwdmodule.c
53 changes: 48 additions & 5 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4153,7 +4153,7 @@ AC_CHECK_FUNCS([ \
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
getgrnam_r getgrouplist getgroups getitimer getloadavg getlogin \
getpeername getpgid getpid getppid getpriority _getpty \
getpwent getpwnam_r getpwuid_r getresgid getresuid getrusage getsid getspent \
getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \
getspnam getuid getwd if_nameindex initgroups kill killpg lchown linkat \
lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \
mknod mknodat mktime mmap mremap nice openat opendir pathconf pause pipe \
Expand Down Expand Up @@ -6396,6 +6396,7 @@ AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
grp
nis
ossaudiodev
pwd
resource
readline
spwd
Expand All @@ -6418,6 +6419,7 @@ AS_CASE([$ac_sys_system/$ac_sys_emscripten_target],
grp
nis
ossaudiodev
pwd
spwd
syslog
])"
Expand Down Expand Up @@ -6556,6 +6558,7 @@ dnl platform specific extensions
PY_STDLIB_MOD([grp], [], [test "$ac_cv_func_getgrgid" = yes -o "$ac_cv_func_getgrgid_r" = yes])
PY_STDLIB_MOD([ossaudiodev],
[], [test "$ac_cv_header_linux_soundcard_h" = yes -o "$ac_cv_header_sys_soundcard_h" = yes])
PY_STDLIB_MOD([pwd], [], [test "$ac_cv_func_getpwuid" = yes -o "$ac_cv_func_getpwuid_r" = yes])
PY_STDLIB_MOD([resource], [], [test "$ac_cv_header_sys_resource_h" = yes])
PY_STDLIB_MOD([_scproxy],
[test "$ac_sys_system" = "Darwin"], [],
Expand Down Expand Up @@ -6645,7 +6648,7 @@ AC_SUBST([MODULE_BLOCK])

# generate output files
AC_CONFIG_FILES(Makefile.pre Misc/python.pc Misc/python-embed.pc Misc/python-config.sh)
AC_CONFIG_FILES([Modules/Setup.stdlib])
AC_CONFIG_FILES([Modules/Setup.bootstrap Modules/Setup.stdlib])
AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix])
AC_OUTPUT

Expand All @@ -6658,7 +6661,7 @@ fi
AC_MSG_NOTICE([creating Makefile])
$SHELL $srcdir/Modules/makesetup -c $srcdir/Modules/config.c.in \
-s Modules \
Modules/Setup.local $MODULES_SETUP_STDLIB $srcdir/Modules/Setup.bootstrap $srcdir/Modules/Setup
Modules/Setup.local $MODULES_SETUP_STDLIB Modules/Setup.bootstrap $srcdir/Modules/Setup
mv config.c Modules

if test -z "$PKG_CONFIG"; then
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@
/* Define to 1 if you have the `getpwnam_r' function. */
#undef HAVE_GETPWNAM_R

/* Define to 1 if you have the `getpwuid' function. */
#undef HAVE_GETPWUID

/* Define to 1 if you have the `getpwuid_r' function. */
#undef HAVE_GETPWUID_R

Expand Down