Merge packaging doc fix
diff --git a/Doc/install/index.rst b/Doc/install/index.rst
index 58b7835..bb2e9c5 100644
--- a/Doc/install/index.rst
+++ b/Doc/install/index.rst
@@ -4,7 +4,7 @@
Installing Python Projects
******************************
-:Author: Greg Ward and Packaging contributors
+:Author: The Fellowship of the Packaging
:Release: |version|
:Date: |today|
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index 134c19c..1c1c167 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -290,19 +290,18 @@
The resulting list is sorted alphabetically. For example:
>>> import struct
- >>> dir() # doctest: +SKIP
+ >>> dir() # show the names in the module namespace
['__builtins__', '__doc__', '__name__', 'struct']
- >>> dir(struct) # doctest: +NORMALIZE_WHITESPACE
+ >>> dir(struct) # show the names in the struct module
['Struct', '__builtins__', '__doc__', '__file__', '__name__',
'__package__', '_clearcache', 'calcsize', 'error', 'pack', 'pack_into',
'unpack', 'unpack_from']
- >>> class Foo:
- ... def __dir__(self):
- ... return ["kan", "ga", "roo"]
- ...
- >>> f = Foo()
- >>> dir(f)
- ['ga', 'kan', 'roo']
+ >>> class Shape(object):
+ def __dir__(self):
+ return ['area', 'perimeter', 'location']
+ >>> s = Shape()
+ >>> dir(s)
+ ['area', 'perimeter', 'location']
.. note::
@@ -333,15 +332,21 @@
:meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
tuple containing a count (from *start* which defaults to 0) and the
corresponding value obtained from iterating over *iterable*.
- :func:`enumerate` is useful for obtaining an indexed series: ``(0, seq[0])``,
- ``(1, seq[1])``, ``(2, seq[2])``, .... For example:
- >>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter']):
- ... print(i, season)
- 0 Spring
- 1 Summer
- 2 Fall
- 3 Winter
+ >>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1):
+ print(i, season)
+ 1 Spring
+ 2 Summer
+ 3 Fall
+ 4 Winter
+
+ Equivalent to::
+
+ def enumerate(sequence, start=0):
+ n = start
+ for elem in sequence:
+ yield n, elem
+ n += 1
.. function:: eval(expression, globals=None, locals=None)
@@ -652,10 +657,10 @@
One useful application of the second form of :func:`iter` is to read lines of
a file until a certain line is reached. The following example reads a file
- until ``"STOP"`` is reached: ::
+ until the :meth:`readline` method returns an empty string::
- with open("mydata.txt") as fp:
- for line in iter(fp.readline, "STOP"):
+ with open('mydata.txt') as fp:
+ for line in iter(fp.readline, ''):
process_line(line)
@@ -1169,8 +1174,9 @@
It can be called either on the class (such as ``C.f()``) or on an instance (such
as ``C().f()``). The instance is ignored except for its class.
- Static methods in Python are similar to those found in Java or C++. For a more
- advanced concept, see :func:`classmethod` in this section.
+ Static methods in Python are similar to those found in Java or C++. Also see
+ :func:`classmethod` for a variant that is useful for creating alternate class
+ constructors.
For more information on static methods, consult the documentation on the
standard type hierarchy in :ref:`types`.
@@ -1270,6 +1276,10 @@
references. The zero argument form automatically searches the stack frame
for the class (``__class__``) and the first argument.
+ For practical suggestions on how to design cooperative classes using
+ :func:`super`, see `guide to using super()
+ <http://rhettinger.wordpress.com/2011/05/26/super-considered-super/>`_.
+
.. function:: tuple([iterable])
diff --git a/Doc/packaging/index.rst b/Doc/packaging/index.rst
index 1b597d7..d3d0dec 100644
--- a/Doc/packaging/index.rst
+++ b/Doc/packaging/index.rst
@@ -4,7 +4,7 @@
Distributing Python Projects
##############################
-:Authors: Greg Ward, Anthony Baxter and Packaging contributors
+:Authors: The Fellowship of the Packaging
:Email: distutils-sig@python.org
:Release: |version|
:Date: |today|
diff --git a/Lib/packaging/run.py b/Lib/packaging/run.py
index 2d22bfd..de9dd13 100644
--- a/Lib/packaging/run.py
+++ b/Lib/packaging/run.py
@@ -9,7 +9,7 @@
from packaging import logger
from packaging.dist import Distribution
-from packaging.util import _is_archive_file
+from packaging.util import _is_archive_file, generate_setup_py
from packaging.command import get_command_class, STANDARD_COMMANDS
from packaging.install import install, install_local_project, remove
from packaging.database import get_distribution, get_distributions
@@ -38,6 +38,14 @@
Create a new Python package.
"""
+generate_usage = """\
+Usage: pysetup generate-setup
+ or: pysetup generate-setup --help
+
+Generates a setup.py script for backward-compatibility purposes.
+"""
+
+
graph_usage = """\
Usage: pysetup graph dist
or: pysetup graph --help
@@ -204,6 +212,13 @@
return main()
+@action_help(generate_usage)
+def _generate(distpatcher, args, **kw):
+ generate_setup_py()
+ print('The setup.py was generated')
+
+
+
@action_help(graph_usage)
def _graph(dispatcher, args, **kw):
name = args[1]
@@ -381,6 +396,7 @@
('list', 'Search for local projects', _list),
('graph', 'Display a graph', _graph),
('create', 'Create a Project', _create),
+ ('generate-setup', 'Generates a backward-comptatible setup.py', _generate)
]
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
index e839320..4e5bd2c 100644
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -1087,7 +1087,7 @@
Raises a PackagingFileError when a setup.py already exists.
"""
if os.path.exists("setup.py"):
- raise PackagingFileError("a setup.py file alreadyexists")
+ raise PackagingFileError("a setup.py file already exists")
with open("setup.py", "w", encoding='utf-8') as fp:
fp.write(_SETUP_TMPL % {'func': getsource(cfg_to_args)})