#!/usr/bin/env python
"""
Module SETUPUTILS -- Utilities to automate boilerplate in Python setup scripts
Copyright (C) 2012 by Peter A. Donis
Released under the Python Software Foundation License.
The purpose of this module is to help automate away much of the
boilerplate that goes into Python setup scripts. Typical usage:
# declare variables here, for example...
name = "myprog"
description = "My Python Program"
# other variables depending on what you need, but the autodiscovery
# capabilities of setuputils remove the need for a lot of manual
# declarations, or at least make them easier
if __name__ == '__main__':
from distutils.core import setup
from setuputils import setup_vars
setup(**setup_vars(globals()))
Or, you can take more fine-grained control over things by only
invoking particular sub-functions, for example:
if __name__ == '__main__':
from distutils.core import setup
from setuputils import autodiscover_packages
setup(
name="myprog",
description="My Python Program",
packages=autodiscover_packages(globals()),
# other args
)
You can even mix the two methods, disabling general autodiscovery
but using it for particular things:
from setuputils import autodiscover_packages, setup_vars
name = "myprog"
description = "My Python Program"
packages = autodiscover_packages(globals())
if __name__ == '__main__':
from distutils.core import setup
setup(**setup_vars(globals(), autodiscover=False))
See the docstrings of the individual functions below for more
information.
"""
import os
from datetime import datetime
from distutils.core import Extension
from functools import partial
from itertools import chain, dropwhile, islice, izip, takewhile
def underline(line, underline='~'):
"""Return an underline string for ``line``.
Intended for use with level 3 and lower headings.
Note that the default for ``underline`` assumes that the level
1 and 2 underlines are the standard ``=`` and ``-``. You can
pass a different underline character to this function if needed.
"""
if line.endswith('\n'):
line = line[:-1]
return "{}\n".format(underline * len(line))
h3_prefix = '### '
def _rst_from_md(basename, template=None, startline=None, **kwds):
# Convert Markdown text from file named basename.md to RST
# text saved to file named basename
with open("{}.md".format(basename), 'rU') as f:
lines = f.readlines()
outlines = []
# Allow adding a header to the RST version (which can
# be filtered out when generating PKG_INFO if desired)
if template:
outlines.extend(
"{}\n".format(line) for line in
template.format(basename=basename, **kwds).splitlines()
)
# Normally you will want to pass an integer in as the
# startline keyword argument, since the Markdown file
# will probably have a title at the start, and the RST
# files used to provide PKG_INFO to PyPI should not have
# title lines (since PyPI adds a title itself)
for line in islice(lines, startline, None):
is_h3line = line.startswith(h3_prefix)
if is_h3line:
line = line[len(h3_prefix):]
outlines.append(line)
if is_h3line:
outlines.append(underline(line))
with open(basename, 'w') as f:
f.writelines(outlines)
def convert_md_to_rst(template=None,
dirname=".", mdnames=None,
**kwds):
"""Convert Markdown text files to RST text files.
Useful for projects where "official" releases are on PyPI but
development source is visible somewhere else that uses Markdown
instead of ReStructuredText as its default text doc format,
such as github. The ``mdnames`` parameter gives the base names
of files to be converted; this defaults to every text file in
directory ``dirname`` (which defaults to the directory your
setup script is run from) with an ``.md`` extension.
"""
if mdnames is None:
mdnames = [
os.path.splitext(basename)[0]
for basename in os.listdir(dirname)
if os.path.splitext(basename)[1] == ".md"
]
for basename in mdnames:
_rst_from_md(basename, template=template, **kwds)
def current_date(fmt):
return datetime.now().strftime(fmt)
def long_description(varmap, filename="README",
startline=None, startspec=None,
endline=None, endspec=None):
"""Extract long description suitable for PyPI from RST text file.
Useful to automate generating the ``long_description``
setup parameter. Looks in ``filename``, which should be
a ReStructuredText file, and returns all the text from
the given starting line (which is included in the result)
to the given ending line (which is not included in the
result). Lines can be specified either by line number
(``startline`` or ``endline``) or a string the line
starts with (``startspec`` or ``endspec``). Defaults
to using the ``README`` file.
"""
startline = startline or varmap.get('startline')
startspec = startspec or varmap.get('startspec')
endline = endline or varmap.get('endline')
endspec = endspec or varmap.get('endspec')
with open(filename, 'rU') as f:
lines = f.readlines()
if startline or endline:
innerlines = islice(lines, startline, endline)
else:
innerlines = lines
if startspec:
inner = dropwhile(
lambda line: not line.startswith(startspec),
innerlines
)
else:
inner = innerlines
if endspec:
desclines = takewhile(
lambda line: not line.startswith(endspec),
inner
)
else:
desclines = inner
return "".join(desclines)
def pypi_url(varmap):
"""Return the PyPI URL for program ``name`` from the setup vars.
"""
return "http://pypi.python.org/pypi/{}".format(varmap['name'])
def provides(varmap):
"""Return a minimal ``provides`` list from the setup vars.
"""
try:
return ["{} ({})".format(varmap['name'], varmap['version'])]
except KeyError:
return [varmap['name']]
def add_vars(varmap):
"""Automate adding ``long_description``, ``url``, and ``provides`` setup vars.
"""
if 'long_description' not in varmap:
varmap['long_description'] = long_description(varmap)
if 'url' not in varmap:
varmap['url'] = pypi_url(varmap)
if 'provides' not in varmap:
varmap['provides'] = provides(varmap)
def convert_lists(varmap,
listnames=('classifiers', 'requires', 'provides', 'obsoletes')):
"""Convert long strings to lists of strings.
Allows variable names in ``listnames`` to be specified as
long strings instead of lists, for easier typing. The
``license_map`` and ``devstatus_trove`` strings below give
examples of the kind of long strings that can be used.
"""
listnames = varmap.get('listnames', listnames)
for listname in listnames:
try:
var = varmap[listname]
except KeyError:
pass
else:
if isinstance(var, basestring):
varmap[listname] = var.strip().splitlines()
def add_classifier_python(varmap):
"""Automate adding the Python language classifier.
Since most programs using this module will be Python
programs, this makes it easy to ensure that the Python
language Trove classifier is present.
"""
classifiers = varmap.setdefault('classifiers', [])
if all(not c.startswith("Programming Language ::") for c in classifiers):
classifiers.append("Programming Language :: Python")
license_map = d
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共98个文件
py:93个
pkg-info:1个
readme:1个
资源分类:Python库 所属语言:Python 资源全名:plib.io-0.9.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
plib.io-0.9.tar.gz (98个子文件)
plib.io-0.9
PKG-INFO 10KB
plib
test
__init__.py 347B
io
test_nopoll.py 3KB
testlib_async.py 2KB
test_chat_replies.py 2KB
test_io.py 5KB
test_multirequest.py 5KB
testlib_persistent.py 1KB
test_err.py 5KB
testlib_blocking.py 3KB
__main__.py 605B
__init__.py 271B
test_api.py 3KB
testlib.py 18KB
test_persistent_nopoll.py 2KB
test_persistent.py 2KB
__init__.py 342B
io
base
__init__.py 493B
BaseCommunicator.py 11KB
BaseData.py 5KB
BaseIO.py 2KB
utils.py 8KB
data
ShutdownReadWrite.py 2KB
ReadWrite.py 4KB
__init__.py 618B
TerminatorReadWrite.py 3KB
socket
_socket.py 6KB
ConnectMixin.py 692B
BaseRequest.py 562B
__init__.py 613B
BaseClient.py 865B
BaseServer.py 3KB
async
PersistentSocketMixin.py 952B
ClientMixin.py 681B
PersistentMixin.py 476B
SerialDispatcher.py 861B
_async.py 9KB
AsyncCommunicator.py 1KB
SerialServerMixin.py 512B
SocketDispatcher.py 7KB
SocketClientMixin.py 641B
__init__.py 749B
SerialClientMixin.py 664B
SocketBase.py 590B
RequestBase.py 741B
AsyncConnectMixin.py 948B
SerialBase.py 495B
SocketServer.py 3KB
ServerMixin.py 518B
mixins
SigChldServerMixin.py 3KB
EchoRequestMixin.py 828B
SigIntServerMixin.py 2KB
SelfPipeServerMixin.py 1KB
__init__.py 478B
ChildWrapperMixin.py 2KB
__init__.py 4KB
classes
SerialTelnet.py 1KB
PTCPClient.py 679B
PClientBase.py 3KB
PAsyncClient.py 691B
PServerBase.py 8KB
__init__.py 2KB
chat_replies.py 2KB
ReadWriteMonitor.py 5KB
PTCPServer.py 1KB
PAsyncServer.py 1KB
SerialPseudoSocket.py 1KB
comm
PersistentCommunicator.py 7KB
ServerCommunicator.py 2KB
__init__.py 519B
ClientCommunicator.py 4KB
blocking
ClientMixin.py 1KB
SerialServerMixin.py 518B
SocketClientMixin.py 910B
__init__.py 635B
ThreadingServer.py 796B
SerialClientMixin.py 518B
SocketBase.py 1KB
RequestBase.py 985B
ForkingServer.py 2KB
SerialBase.py 498B
SocketServer.py 6KB
ServerMixin.py 948B
serial
_serial.py 6KB
__init__.py 613B
BaseClient.py 521B
BaseServer.py 848B
setuputils.py 27KB
TODO 2KB
LICENSE 18KB
CHANGES 70KB
README 9KB
examples
echo
echo_server.py 5KB
echo_client.py 2KB
chat
chat_server.py 4KB
chat_client.py 3KB
setup.py 1KB
scripts
plib-setup-io-examples.py 633B
共 98 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- html动态爱心代码一(附源码)
- c40539bc-071a-486c-9d52-9d0c18d62dac 4.html
- 基于物理的非视域成像(NLOS)算法,利用了nerf+python源码+文档说明
- yuluer知更鸟.7z(1).001
- 基于Qt实现医院信息管理系统c++源码+文档说明+数据库(期末大作业)
- 基于python实现的医院信息管理系统完整源码+sql数据库+详细注释(高分课程设计)
- 基于python的眼底图像视杯视盘分割项目源码+文档说明+截图演示+详细注释(高分课程设计)
- ImageBasedModellingEdu-贰壹贰叁零
- DFFmeasurement-数据预处理
- ImageBasedModellingEdu-回文素数c语言
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功