用于Python3.8位置参数语法的后端口编译器。

python-poseur的Python项目详细描述


装腔作势

PyPI - DownloadsPyPI - VersionPyPI - FormatPyPI - Python Version

Travis CI - StatusCodecov - CoverageLicenseLICENSE

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和提供测试用例。 请注意,代码必须保持有效和合理。

另请参见

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
datetime如何使用JodaTime在Java中设置时间属性   java固定算法的性能时间   java如何从JMenu中获取所选项以更改文本区域的文本颜色?   java配置单元UDF传递数组<string>作为参数   javaapachebeam和BigQuery   java与PrintWriter之间的差异。printf和PrintWriter。格式方法   继承如何处理按Java版本更改的导入,以及在多个版本上编译   xml java。lang.noClassDefFoundant生成错误   java如何使用包含映射的JSON发送POST请求?   java如何在任何应用程序的JAR文件中绑定MySql数据库?   Java脚本解释器   sslhttpclientjava。网SocketException:未实现未连接的socket   java如何为Android应用程序创建类似于Cron作业的东西   java JButton+radiobox+复选框   java内存管理将文件写入内存   java这是计算对象实例的有效方法吗?   用于死锁情况的java代码?   JavaSpring容器作为新实体插入,而不是存储在表中