- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 Sphinx 来记录我的代码。但我看到了错误:
the module executes module level statement and it might call sys.exit().
import argparse
# parse command line arguments
parser = argparse.ArgumentParser(description='AWS VPN status checker.')
parser.add_argument('account', type=str, help='AWS account name.')
parser.add_argument('region', type=str, help='region of VPN tunnel.')
parser.add_argument('ipaddress', type=str, help='Tunnel IP address.')
parser.add_argument("-d", "--debug", help="debug", action="store_true")
args = parser.parse_args()
最佳答案
Sphinx 警告是一种效果,由前面的 parse_args()
引起。错误。 arg_parse()
函数被调用,在它预期解析的参数中发现一个正常错误,并且存在。
While parsing the command line, parse_args() checks for a variety of errors, including ambiguous options, invalid types, invalid options, wrong number of positional arguments, etc. When it encounters such an error, it exits and prints the error along with a usage message:
parse_args()
退出
在生成 Sphinx 文档时 , 是因为你真正调用的是
sphinx-build
或
make html
.因此,在您的 python shell 上执行的是以下签名:
Synopsis
sphinx-build [options] < sourcedir > < outputdir > [filenames …]
ArgumentParser
要求。要么运行
sphinx-build
或
make html
包括命令行参数
arg_parse()
需要
ArgumentParser()
,或者不要调用
arg_parse()
生成文档时。
How to fix this?
entry_script.py
:
from sys import argv
from pathlib import Path
import cmd_line_module
# Checking what the command line contains can be useful.
print(argv)
EXAMPLE_ARGS = ['-i', '../in_dir_test', '-o', 'out_dir_test']
# Script.
if __name__ == "__main__":
# default Namespace
print(cmd_line_params.args)
# command-line
cmd_line_module.set_args()
print(cmd_line_params.args)
# test case
cmd_line_module.set_args(EXAMPLE_ARGS)
print(cmd_line_params.args)
# Sphinx-build or make.
elif Path(argv[0]).name == "sphinx-build" or Path(argv[0]).name == "build.py":
cmd_line_module.set_args(EXAMPLE_ARGS)
# Module only.
else:
cmd_line_module.set_args(EXAMPLE_ARGS)
cmd_line_module.py
:
import argparse
_DEFAULT = argparse.Namespace(in_dir=None, out_dir=None)
args = _DEFAULT
def command_line_args():
parser = argparse.ArgumentParser(prog='entry_script', description='Does magic :) .')
parser.add_argument("-i", "--in_dir", help="Input directory/file. Use absolute or relative path.")
parser.add_argument("-o", "--out_dir", help="Output directory. Use absolute or relative path.")
return parser
def set_args(cmd_line=None):
parser = command_line_args()
global args
args = parser.parse_args(cmd_line)
关于解决方案的一些注释可能对读者有用:
cmd_line_module.py
维护
args
作为模块级别的变量,类似于
argparse tutorial尽可能的例子。
argparse
的特定 Sphinx 扩展可以找到
on this thread .
args
可能很方便,它作为建议包含在内。 (预期的默认值可以帮助测试导入模块)。
__main __
或
sphinx-build
可能没有必要,具体取决于 3
if
包括测试只是为了给问题添加上下文。
DEFAULT_ARGS
显示如何使用
parse_args()
无需阅读
sys.argv
,以及如何运行
sphinx-build
分配使用
if __name __ == "__main __":
(如果您觉得方便,出于任何原因)...
sphinx-build
的名称和路径脚本可能因操作系统而异。
parse_args()
在导入可能具有依赖于它的变量的模块之前。
6.1. More on Modules
A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the module name is encountered in an import statement. (They are also run if the file is executed as a script.)
关于 python 狮身人面像 "the module executes module level statement and it might call sys.exit().",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34570114/
在 go lang 中使用“If with a short statement”有什么好处。引用:go tour if v := math.Pow(x, n); v < lim { retur
完全错误: Warning: Unsafe statement written to the binary log using statement format since BINLOG_FORMAT
完全错误: Warning: Unsafe statement written to the binary log using statement format since BINLOG_FORMAT
我有三个存储过程 Sp1、Sp2 和 Sp3。 第一个 (Sp1) 将执行第二个 (Sp2) 并将返回的数据保存到 @tempTB1 中,第二个将执行第三个 (Sp3) 并将数据保存到 @tempTB
我已将 FLAG 设置为 1,并且正在执行 ARG 值应该仅为 DEV。但是我得到的是 ARG= DEV + CLIENTID 000023 // FLAG=1 000026 // I
我已将 FLAG 设置为 1,并且正在执行 ARG 值应该仅为 DEV。但是我得到的是 ARG= DEV + CLIENTID 000023 // FLAG=1 000026 // I
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
PMD告诉我 A switch with less than 3 branches is inefficient, use a if statement instead. 这是为什么呢?为什么是3?他
我刚开始学习 Racket,所以我仍在努力弄清楚这门语言的复杂性。我正在尝试在列表中实现我自己的搜索功能。如果函数找到它,则返回索引,否则返回 -1。 (define (find-index list
在 Kotlin 中,您可以使用类似于三元运算符的 if 语句。 我们可以选择做这样的事情: val x = if (isOdd) 1 else 2 但是如果我们有多个变量需要根据某些条件进行设置,那
在我的 Android 应用程序中,我尝试使用 XMLPullParser 使用以下代码读取 xml 文件: while (eventType != XmlPullParser.END_DOCUMEN
这个问题已经有答案了: Boolean expressions in Java (8 个回答) 已关闭 7 年前。 我遇到过一些情况,其中第一个似乎改变了 boolean 值,而第二个却没有!两者之间
我基本上想做的是: select * from request where id = 1 and created_at like (today's date); 但使用 Eloquent 。 我试过:
我不确定为什么会收到此代码。基本上我希望能够动态定位我的发射器,但是当我添加一个选项来检查位置并根据需要进行纠正时,我不断收到此错误。 添加的代码是 if (
何时使用语句而不是准备语句。我想语句用于没有参数的查询,但为什么不使用准备好的语句呢?对于没有参数的查询,哪个更快。 最佳答案 I suppose statement is used in queri
我必须创建一个表,如下所示 借款人(客户编号,贷款编号) 如果客户没有超过 3 笔贷款,则可以贷款。 我创建的表如下 create table borrower( customerno int(5),
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: Is "else if" faster than "switch() case"? What is the
typescript 版本 2.2.2 我在我的 UserRoutzr.ts 中写了这个要求 const users = require(path.join(process.cwd() + "/da
我有一个用 JPQL 编写的应用程序,它可以命中非常不同的查询(在不同的资源上)。 对于很多此类查询,我需要知道结果总数(计数),因为我没有应用任何 LIMIT/OFFSET 由于此查询的性质非常不同
我对以下 Java 语句感到困惑: ArtClass artClass0 = new ArtClass(); int int3 = 73; boolean boolean0 = artClass0.f
我是一名优秀的程序员,十分优秀!