用于Python3.8位置参数语法的后端口编译器。
python-poseur的Python项目详细描述
装腔作势
Write positional-only parameters in Python 3.8 flavour, and let
poseur
worry about back-port issues :beer:
自从PEP 570以来,python引入了positional only参数
版本3.8中的语法。对于那些希望在代码中使用positional-only参数的人,poseur
提供了
通过删除positional-only参数语法,智能地解决了backport编译器
为运行时检查引入一个decorator,它保证您始终在python中编写positional-only参数。
3.8风味,然后编译,以便以后兼容。
安装
Note that
poseur
only supports Python versions since 3.3 ?
对于MacOS用户,poseur
现在可以通过Homebrew:
brew tap jarryshaw/tap
brew install poseur
# or simply, a one-liner
brew install jarryshaw/tap/poseur
只需运行以下命令即可从pypi安装当前版本:
pip install poseur
或从Git存储库安装最新版本:
git clone https://github.com/JarryShaw/poseur.git cd poseur pip install -e . # and to update at any time git pull
基本用法
cli
使用poseur
:
context in
${...}
changes dynamically according to runtime environment
usage: poseur [options] <python source files and folders...> Convert f-string to str.format for Python 3 compatibility. positional arguments: SOURCE python source files and folders to be converted (${CWD}) optional arguments: -h, --help show this help message and exit -V, --version show program's version number and exit -q, --quiet run in quiet mode archive options: duplicate original files in case there's any issue -n, --no-archive do not archive original files -p PATH, --archive-path PATH path to archive original files (${CWD}/archive) convert options: compatibility configuration for none-unicode files -c CODING, --encoding CODING encoding to open source files (${LOCALE_ENCODING}) -v VERSION, --python VERSION convert against Python version (${LATEST_VERSION}) -s SEP, --linesep SEP line separator to process source files (${OS_LINESEP}) -d, --dismiss dismiss runtime checks for positional-only parameters -nl, --no-linting do not lint converted codes -r VAR, --decorator VAR name of decorator for runtime checks (${DECORATOR})
poseur
将读取并转换每个python中所有的位置参数语法
此路径下的文件。如果转换有问题,poseur
将
在进程之前,将要修改的所有原始文件复制到archive
目录中,
如果未设置-n
。
另外,为了保持api对用户的一致性,poseur
附带了一个decorator
如果未设置-nl
,则此类函数在运行时仅检查位置参数。
开发人员参考
环境
poseur
当前支持三个环境参数:
F2FORMAT_QUIET
——在安静模式下运行(与cli中的--quiet
选项相同)F2FORMAT_VERSION
——根据python版本进行转换(与cli中的--python
选项相同)F2FORMAT_ENCODING
——对开源文件进行编码(与cli中的--encoding
选项相同)POSEUR_LINSEP
——处理源文件的行分隔符(与cli中的--linesep
选项相同)POSEUR_DISMISS
——取消对仅位置参数的运行时检查(与cli中的--dismiss
选项相同)POSEUR_LINTING
——lint转换的代码(与cli中的--linting
选项相同)POSEUR_DECORATOR
——用于运行时检查的decorator的名称(与cli中的--decorator
选项相同)
原料药
poseur
——包装器用于转换
poseur(filename)
参数:
filename
--str
,要转换的文件
环境:
F2FORMAT_QUIET
——在安静模式下运行(与cli中的--quiet
选项相同)F2FORMAT_ENCODING
——对开源文件进行编码(与cli中的--encoding
选项相同)F2FORMAT_VERSION
——根据python版本进行转换(与cli中的--python
选项相同)POSEUR_LINSEP
——处理源文件的行分隔符(与cli中的--linesep
选项相同)POSEUR_DISMISS
——取消对仅位置参数的运行时检查(与cli中的--dismiss
选项相同)POSEUR_LINTING
——lint转换的代码(与cli中的--linting
选项相同)POSEUR_DECORATOR
——用于运行时检查的decorator的名称(与cli中的--decorator
选项相同)
提高:
ConvertError
——当parso.ParserSyntaxError
升高时
convert
——主要转换过程
convert(string,source='<unknown>')
参数:
string
--str
,要转换的上下文source
--str
,上下文的来源
环境:
F2FORMAT_VERSION
——根据python版本进行转换(与cli中的--python
选项相同)POSEUR_LINSEP
——处理源文件的行分隔符(与cli中的--linesep
选项相同)POSEUR_DISMISS
——取消对仅位置参数的运行时检查(与cli中的--dismiss
选项相同)POSEUR_LINTING
——lint转换的代码(与cli中的--linting
选项相同)
返回:
str
——转换字符串
提高:
ConvertError
——当parso.ParserSyntaxError
升高时
ConvertError
--poseur
内部异常
classConvertError(SyntaxError):pass
测试
见^{
贡献
贡献非常受欢迎,尤其是修复bug和提供测试用例。 请注意,代码必须保持有效和合理。