Skip to content

Commit 47e3cec

Browse files
committed
chapter 3 & updated pdf
1 parent 19896c0 commit 47e3cec

File tree

1,467 files changed

+270720
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,467 files changed

+270720
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fornumberin [0, 1, 2, 3, 4]:
2+
print(number)

‎Scripts/chapter3/looping/Util/__init__.py‎

Whitespace-only changes.
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# don't import any costly modules
2+
importsys
3+
importos
4+
5+
6+
is_pypy='__pypy__'insys.builtin_module_names
7+
8+
9+
defwarn_distutils_present():
10+
if'distutils'notinsys.modules:
11+
return
12+
ifis_pypyandsys.version_info< (3, 7):
13+
# PyPy for 3.6 unconditionally imports distutils, so bypass the warning
14+
# https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
15+
return
16+
importwarnings
17+
18+
warnings.warn(
19+
"Distutils was imported before Setuptools, but importing Setuptools "
20+
"also replaces the `distutils` module in `sys.modules`. This may lead "
21+
"to undesirable behaviors or errors. To avoid these issues, avoid "
22+
"using distutils directly, ensure that setuptools is installed in the "
23+
"traditional way (e.g. not an editable install), and/or make sure "
24+
"that setuptools is always imported before distutils."
25+
)
26+
27+
28+
defclear_distutils():
29+
if'distutils'notinsys.modules:
30+
return
31+
importwarnings
32+
33+
warnings.warn("Setuptools is replacing distutils.")
34+
mods= [
35+
name
36+
fornameinsys.modules
37+
ifname=="distutils"orname.startswith("distutils.")
38+
]
39+
fornameinmods:
40+
delsys.modules[name]
41+
42+
43+
defenabled():
44+
"""
45+
Allow selection of distutils by environment variable.
46+
"""
47+
which=os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'local')
48+
returnwhich=='local'
49+
50+
51+
defensure_local_distutils():
52+
importimportlib
53+
54+
clear_distutils()
55+
56+
# With the DistutilsMetaFinder in place,
57+
# perform an import to cause distutils to be
58+
# loaded from setuptools._distutils. Ref #2906.
59+
withshim():
60+
importlib.import_module('distutils')
61+
62+
# check that submodules load as expected
63+
core=importlib.import_module('distutils.core')
64+
assert'_distutils'incore.__file__, core.__file__
65+
assert'setuptools._distutils.log'notinsys.modules
66+
67+
68+
defdo_override():
69+
"""
70+
Ensure that the local copy of distutils is preferred over stdlib.
71+
72+
See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
73+
for more motivation.
74+
"""
75+
ifenabled():
76+
warn_distutils_present()
77+
ensure_local_distutils()
78+
79+
80+
class_TrivialRe:
81+
def__init__(self, *patterns):
82+
self._patterns=patterns
83+
84+
defmatch(self, string):
85+
returnall(patinstringforpatinself._patterns)
86+
87+
88+
classDistutilsMetaFinder:
89+
deffind_spec(self, fullname, path, target=None):
90+
# optimization: only consider top level modules and those
91+
# found in the CPython test suite.
92+
ifpathisnotNoneandnotfullname.startswith('test.'):
93+
return
94+
95+
method_name='spec_for_{fullname}'.format(**locals())
96+
method=getattr(self, method_name, lambda: None)
97+
returnmethod()
98+
99+
defspec_for_distutils(self):
100+
ifself.is_cpython():
101+
return
102+
103+
importimportlib
104+
importimportlib.abc
105+
importimportlib.util
106+
107+
try:
108+
mod=importlib.import_module('setuptools._distutils')
109+
exceptException:
110+
# There are a couple of cases where setuptools._distutils
111+
# may not be present:
112+
# - An older Setuptools without a local distutils is
113+
# taking precedence. Ref #2957.
114+
# - Path manipulation during sitecustomize removes
115+
# setuptools from the path but only after the hook
116+
# has been loaded. Ref #2980.
117+
# In either case, fall back to stdlib behavior.
118+
return
119+
120+
classDistutilsLoader(importlib.abc.Loader):
121+
defcreate_module(self, spec):
122+
mod.__name__='distutils'
123+
returnmod
124+
125+
defexec_module(self, module):
126+
pass
127+
128+
returnimportlib.util.spec_from_loader(
129+
'distutils', DistutilsLoader(), origin=mod.__file__
130+
)
131+
132+
@staticmethod
133+
defis_cpython():
134+
"""
135+
Suppress supplying distutils for CPython (build and tests).
136+
Ref #2965 and #3007.
137+
"""
138+
returnos.path.isfile('pybuilddir.txt')
139+
140+
defspec_for_pip(self):
141+
"""
142+
Ensure stdlib distutils when running under pip.
143+
See pypa/pip#8761 for rationale.
144+
"""
145+
ifself.pip_imported_during_build():
146+
return
147+
clear_distutils()
148+
self.spec_for_distutils=lambda: None
149+
150+
@classmethod
151+
defpip_imported_during_build(cls):
152+
"""
153+
Detect if pip is being imported in a build script. Ref #2355.
154+
"""
155+
importtraceback
156+
157+
returnany(
158+
cls.frame_file_is_setup(frame) forframe, lineintraceback.walk_stack(None)
159+
)
160+
161+
@staticmethod
162+
defframe_file_is_setup(frame):
163+
"""
164+
Return True if the indicated frame suggests a setup.py file.
165+
"""
166+
# some frames may not have __file__ (#2940)
167+
returnframe.f_globals.get('__file__', '').endswith('setup.py')
168+
169+
defspec_for_sensitive_tests(self):
170+
"""
171+
Ensure stdlib distutils when running select tests under CPython.
172+
173+
python/cpython#91169
174+
"""
175+
clear_distutils()
176+
self.spec_for_distutils=lambda: None
177+
178+
sensitive_tests= (
179+
[
180+
'test.test_distutils',
181+
'test.test_peg_generator',
182+
'test.test_importlib',
183+
]
184+
ifsys.version_info< (3, 10)
185+
else [
186+
'test.test_distutils',
187+
]
188+
)
189+
190+
191+
fornameinDistutilsMetaFinder.sensitive_tests:
192+
setattr(
193+
DistutilsMetaFinder,
194+
f'spec_for_{name}',
195+
DistutilsMetaFinder.spec_for_sensitive_tests,
196+
)
197+
198+
199+
DISTUTILS_FINDER=DistutilsMetaFinder()
200+
201+
202+
defadd_shim():
203+
DISTUTILS_FINDERinsys.meta_pathorinsert_shim()
204+
205+
206+
classshim:
207+
def__enter__(self):
208+
insert_shim()
209+
210+
def__exit__(self, exc, value, tb):
211+
remove_shim()
212+
213+
214+
definsert_shim():
215+
sys.meta_path.insert(0, DISTUTILS_FINDER)
216+
217+
218+
defremove_shim():
219+
try:
220+
sys.meta_path.remove(DISTUTILS_FINDER)
221+
exceptValueError:
222+
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('_distutils_hack').do_override()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import os; var = 'SETUPTOOLS_USE_DISTUTILS' enabled = os.environ.get(var, 'local') == 'local' enabled and __import__('_distutils_hack').add_shim();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2008-present The pip developers (see AUTHORS.txt file)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Metadata-Version: 2.1
2+
Name: pip
3+
Version: 22.3.1
4+
Summary: The PyPA recommended tool for installing Python packages.
5+
Home-page: https://pip.pypa.io/
6+
Author: The pip developers
7+
Author-email: [email protected]
8+
License: MIT
9+
Project-URL: Documentation, https://pip.pypa.io
10+
Project-URL: Source, https://github.com/pypa/pip
11+
Project-URL: Changelog, https://pip.pypa.io/en/stable/news/
12+
Classifier: Development Status :: 5 - Production/Stable
13+
Classifier: Intended Audience :: Developers
14+
Classifier: License :: OSI Approved :: MIT License
15+
Classifier: Topic :: Software Development :: Build Tools
16+
Classifier: Programming Language :: Python
17+
Classifier: Programming Language :: Python :: 3
18+
Classifier: Programming Language :: Python :: 3 :: Only
19+
Classifier: Programming Language :: Python :: 3.7
20+
Classifier: Programming Language :: Python :: 3.8
21+
Classifier: Programming Language :: Python :: 3.9
22+
Classifier: Programming Language :: Python :: 3.10
23+
Classifier: Programming Language :: Python :: 3.11
24+
Classifier: Programming Language :: Python :: Implementation :: CPython
25+
Classifier: Programming Language :: Python :: Implementation :: PyPy
26+
Requires-Python: >=3.7
27+
License-File: LICENSE.txt
28+
29+
pip - The Python Package Installer
30+
==================================
31+
32+
.. image:: https://img.shields.io/pypi/v/pip.svg
33+
:target: https://pypi.org/project/pip/
34+
35+
.. image:: https://readthedocs.org/projects/pip/badge/?version=latest
36+
:target: https://pip.pypa.io/en/latest
37+
38+
pip is the `package installer`_ for Python. You can use pip to install packages from the `Python Package Index`_ and other indexes.
39+
40+
Please take a look at our documentation for how to install and use pip:
41+
42+
* `Installation`_
43+
* `Usage`_
44+
45+
We release updates regularly, with a new version every 3 months. Find more details in our documentation:
46+
47+
* `Release notes`_
48+
* `Release process`_
49+
50+
In pip 20.3, we've `made a big improvement to the heart of pip`_; `learn more`_. We want your input, so `sign up for our user experience research studies`_ to help us do it right.
51+
52+
**Note**: pip 21.0, in January 2021, removed Python 2 support, per pip's `Python 2 support policy`_. Please migrate to Python 3.
53+
54+
If you find bugs, need help, or want to talk to the developers, please use our mailing lists or chat rooms:
55+
56+
* `Issue tracking`_
57+
* `Discourse channel`_
58+
* `User IRC`_
59+
60+
If you want to get involved head over to GitHub to get the source code, look at our development documentation and feel free to jump on the developer mailing lists and chat rooms:
61+
62+
* `GitHub page`_
63+
* `Development documentation`_
64+
* `Development IRC`_
65+
66+
Code of Conduct
67+
---------------
68+
69+
Everyone interacting in the pip project's codebases, issue trackers, chat
70+
rooms, and mailing lists is expected to follow the `PSF Code of Conduct`_.
71+
72+
.. _package installer: https://packaging.python.org/guides/tool-recommendations/
73+
.. _Python Package Index: https://pypi.org
74+
.. _Installation: https://pip.pypa.io/en/stable/installation/
75+
.. _Usage: https://pip.pypa.io/en/stable/
76+
.. _Release notes: https://pip.pypa.io/en/stable/news.html
77+
.. _Release process: https://pip.pypa.io/en/latest/development/release-process/
78+
.. _GitHub page: https://github.com/pypa/pip
79+
.. _Development documentation: https://pip.pypa.io/en/latest/development
80+
.. _made a big improvement to the heart of pip: https://pyfound.blogspot.com/2020/11/pip-20-3-new-resolver.html
81+
.. _learn more: https://pip.pypa.io/en/latest/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020
82+
.. _sign up for our user experience research studies: https://pyfound.blogspot.com/2020/03/new-pip-resolver-to-roll-out-this-year.html
83+
.. _Python 2 support policy: https://pip.pypa.io/en/latest/development/release-process/#python-2-support
84+
.. _Issue tracking: https://github.com/pypa/pip/issues
85+
.. _Discourse channel: https://discuss.python.org/c/packaging
86+
.. _User IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa
87+
.. _Development IRC: https://kiwiirc.com/nextclient/#ircs://irc.libera.chat:+6697/pypa-dev
88+
.. _PSF Code of Conduct: https://github.com/pypa/.github/blob/main/CODE_OF_CONDUCT.md

0 commit comments

Comments
(0)