pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/ca9689f8dac01d27e041e1dbbdae146746d48ab3

5097560d244c08.css" /> bpo-46933: Make pwd module optional (GH-31700) · python/cpython@ca9689f · GitHub
Skip to content

Commit ca9689f

Browse files
tiranErlend Egeberg Aasland
andauthored
bpo-46933: Make pwd module optional (GH-31700)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
1 parent 3b3be05 commit ca9689f

File tree

11 files changed

+496
-560
lines changed

11 files changed

+496
-560
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Mac/pythonw
7575
Misc/python.pc
7676
Misc/python-embed.pc
7777
Misc/python-config.sh
78+
Modules/Setup.bootstrap
7879
Modules/Setup.config
7980
Modules/Setup.local
8081
Modules/Setup.stdlib

Lib/distutils/tests/test_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ def test_check_environ_getpwuid(self):
248248
util._environ_checked = 0
249249
os.environ.pop('HOME', None)
250250

251-
import pwd
251+
try:
252+
import pwd
253+
except ImportError:
254+
raise unittest.SkipTest("Test requires pwd module.")
252255

253256
# only set pw_dir field, other fields are not used
254257
result = pwd.struct_passwd((None, None, None, None, None,

Lib/posixpath.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ def expanduser(path):
241241
i = len(path)
242242
if i == 1:
243243
if 'HOME' not in os.environ:
244-
import pwd
244+
try:
245+
import pwd
246+
except ImportError:
247+
# pwd module unavailable, return path unchanged
248+
return path
245249
try:
246250
userhome = pwd.getpwuid(os.getuid()).pw_dir
247251
except KeyError:
@@ -251,7 +255,11 @@ def expanduser(path):
251255
else:
252256
userhome = os.environ['HOME']
253257
else:
254-
import pwd
258+
try:
259+
import pwd
260+
except ImportError:
261+
# pwd module unavailable, return path unchanged
262+
return path
255263
name = path[1:i]
256264
if isinstance(name, bytes):
257265
name = str(name, 'ASCII')

Lib/test/test_pathlib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,9 @@ def _test_home(self, p):
14861486
self.assertIs(type(p), type(q))
14871487
self.assertTrue(p.is_absolute())
14881488

1489+
@unittest.skipIf(
1490+
pwd is None, reason="Test requires pwd module to get homedir."
1491+
)
14891492
def test_home(self):
14901493
with os_helper.EnvironmentVarGuard() as env:
14911494
self._test_home(self.cls.home())

Lib/test/test_posix.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
import time
1616
import os
1717
import platform
18-
import pwd
1918
import stat
2019
import tempfile
2120
import unittest
2221
import warnings
2322
import textwrap
2423
from contextlib import contextmanager
2524

25+
try:
26+
import pwd
27+
except ImportError:
28+
pwd = None
29+
2630
_DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
2731
os_helper.TESTFN + '-dummy-symlink')
2832

@@ -126,6 +130,7 @@ def test_setresgid_exception(self):
126130

127131
@unittest.skipUnless(hasattr(posix, 'initgroups'),
128132
"test needs os.initgroups()")
133+
@unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")
129134
def test_initgroups(self):
130135
# It takes a string and an integer; check that it raises a TypeError
131136
# for other argument lists.

Makefile.pre.in

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,9 @@ Modules/Setup.local:
917917
@# Create empty Setup.local when file was deleted by user
918918
echo "# Edit this file for local setup changes" > $@
919919

920+
Modules/Setup.bootstrap: $(srcdir)/Modules/Setup.bootstrap.in config.status
921+
./config.status $@
922+
920923
Modules/Setup.stdlib: $(srcdir)/Modules/Setup.stdlib.in config.status
921924
./config.status $@
922925

@@ -925,13 +928,13 @@ Makefile Modules/config.c: Makefile.pre \
925928
$(MAKESETUP) \
926929
$(srcdir)/Modules/Setup \
927930
Modules/Setup.local \
928-
$(srcdir)/Modules/Setup.bootstrap \
931+
Modules/Setup.bootstrap \
929932
Modules/Setup.stdlib
930933
$(SHELL) $(MAKESETUP) -c $(srcdir)/Modules/config.c.in \
931934
-s Modules \
932935
Modules/Setup.local \
933936
@MODULES_SETUP_STDLIB@ \
934-
$(srcdir)/Modules/Setup.bootstrap \
937+
Modules/Setup.bootstrap \
935938
$(srcdir)/Modules/Setup
936939
@mv config.c Modules
937940
@echo "The Makefile was updated, you may need to re-run make."
@@ -2146,7 +2149,7 @@ libainstall: @DEF_MAKE_RULE@ python-config
21462149
$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
21472150
$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
21482151
$(INSTALL_DATA) $(srcdir)/Modules/Setup $(DESTDIR)$(LIBPL)/Setup
2149-
$(INSTALL_DATA) $(srcdir)/Modules/Setup.bootstrap $(DESTDIR)$(LIBPL)/Setup.bootstrap
2152+
$(INSTALL_DATA) Modules/Setup.bootstrap $(DESTDIR)$(LIBPL)/Setup.bootstrap
21502153
$(INSTALL_DATA) Modules/Setup.stdlib $(DESTDIR)$(LIBPL)/Setup.stdlib
21512154
$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
21522155
$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
@@ -2381,8 +2384,9 @@ distclean: clobber
23812384
for file in $(srcdir)/Lib/test/data/* ; do \
23822385
if test "$$file" != "$(srcdir)/Lib/test/data/README"; then rm "$$file"; fi; \
23832386
done
2384-
-rm -f core Makefile Makefile.pre config.status Modules/Setup.local \
2385-
Modules/Setup.stdlib Modules/ld_so_aix Modules/python.exp Misc/python.pc \
2387+
-rm -f core Makefile Makefile.pre config.status Modules/Setup.local
2388+
Modules/Setup.bootstrap Modules/Setup.stdlib \
2389+
Modules/ld_so_aix Modules/python.exp Misc/python.pc \
23862390
Misc/python-embed.pc Misc/python-config.sh
23872391
-rm -f python*-gdb.py
23882392
# Issue #28258: set LC_ALL to avoid issues with Estonian locale.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :mod:`pwd` module is now optional. :func:`os.path.expanduser` returns the path when the :mod:`pwd` module is not available.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ _stat _stat.c
3232
_symtable symtablemodule.c
3333

3434
# for systems without $HOME env, used by site._getuserbase()
35-
pwd pwdmodule.c
35+
@MODULE_PWD_TRUE@pwd pwdmodule.c

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy