PEP420使__init__.py
文件成为可选文件:https : //docs.python.org/3/whatsnew/3.3.html#pep-420-implicit-namespace-packages
尽管似乎没有它们,pkgutil.walk_packages
但无法按预期运行:https : //docs.python.org/3/library/pkgutil.html#pkgutil.walk_packages
考虑以下示例:
$ tree foo
foo
??? bar
? ??? baz.py
? ??? __init__.py
??? __init__.py
??? womp.py
Run Code Online (Sandbox Code Playgroud)
和测试脚本
# test.py
import pkgutil
import foo
for _, mod, _ in pkgutil.walk_packages(foo.__path__, foo.__name__ + '.'):
print(mod)
Run Code Online (Sandbox Code Playgroud)
在python2和python3中,我都得到以下输出:
$ python2.7 test.py
foo.bar
foo.bar.baz
foo.womp
$ python3.5 test.py
foo.bar
foo.bar.baz
foo.womp
Run Code Online (Sandbox Code Playgroud)
删除__init__.py
文件,仅使用python3,我得到以下信息:
$ find -name '__init__.*' -delete
$ python3.5 test.py
foo.bar
Run Code Online (Sandbox Code Playgroud)
这些模块绝对是可导入的:
$ python3.5 -c 'import foo.bar.baz'
$
Run Code Online (Sandbox Code Playgroud)
这是错误吗?我是否被迫创建__init__.py …
我将预提交与这个 .pre-commit-config.yaml 文件(提取)一起使用:
- repo: https://github.com/pre-commit/pre-commit-hooks
sha: v0.9.2
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
Run Code Online (Sandbox Code Playgroud)
我被这个错误困住了:
Check Yaml...................Failed
hookid: check-yaml
expected a single document in the stream
in "modules.yml", line 1, column 1
but found another document
in "modules.yml", line 4, column 1
Run Code Online (Sandbox Code Playgroud)
我的 yaml 文件的开头是:
repo: ssh://git.tranquilit.local/odoo-11-oca-tis/OCB.git
root: 8.0
branch: 8.0-tis
---
repo: ssh://git.tranquilit.local/odoo-71-tis/tis-addons.git
origin: tis
branch: 8.0
modules:
#- attachment_rename
#- partner_firstname
- tis_account_analytic_recurrent_invoicing
Run Code Online (Sandbox Code Playgroud)
我尝试使用和不使用前导行 --- 但它只更改了错误的行 nb。
我没有在网络上的任何地方找到任何帮助,所以如果有人可以帮助我,我会很高兴!
提前致谢, Herve
尝试为 Python 3.7 安装 mod_wsgi 以完成 Django 的设置。但它失败并显示以下错误消息
Collecting mod-wsgi
Using cached https://files.pythonhosted.org/packages/9e/37/dd336068ece37c43957aa337f25c59a9a6afa98086e5507908a2d21ab807/mod_wsgi-4.6.4.tar.gz
Building wheels for collected packages: mod-wsgi
Running setup.py bdist_wheel for mod-wsgi ... error
Complete output from command /home/user/myproject_env/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-9hnl4thc/mod-wsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-a9t55ene --python-tag cp37:
WARNING: The Python installation you are using does not appear to have
been installed with a shared library, or in the case of MacOS X, as a
framework. Where these are not present, the …
Run Code Online (Sandbox Code Playgroud) 我想为团队添加以下内容以进行预提交:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.720'
hooks:
- id: mypy
args: [--ignore-missing-imports]
Run Code Online (Sandbox Code Playgroud)
我的团队担心这可能太严格了。为了逐步介绍,我希望这个钩子不会使提交失败,而只是为了显示问题。那可能吗?
我的项目结构如下:
\nproject/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 backend\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 api_v1\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 api_v2\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 api_v3\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 frontend\n
Run Code Online (Sandbox Code Playgroud)\n每个 API 目录 、api_v1
、api_v2
和api_v3
都有 python 文件。
仅当代码发生更改时,我才想对每个目录运行预提交。例如,mypy -p api_v1
如果目录发生更改,我想运行api_v1
。我知道密钥files
和types
预提交,但我无法找到一种方法来运行 mypy,就好像它是从目录运行一样backend
。另外,当我对其中超过 1 个目录进行更改时,我无法单独为api_v1
、api_v2
或运行 mypy。api_v3
是不可能还是我
\npre-commit
使用black
最新版本运行 python23.11.0
会导致有线InvalidManifestError
.
摘自.pre-commit-config.yaml
repos:\n- repo: https://github.com/psf/black\n rev: 23.11.0\n hooks:\n - id: black\n types: []\n files: ^.*.pyi?$ # format .py and .pyi files`\n
Run Code Online (Sandbox Code Playgroud)\n输出消息:
\n\xe2\x94\x82 \xe2\x94\x82 stdout = \'An error has occurred: InvalidManifestError: \\n==> File \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 /Users/robot/.cache/pre-c\'+329 \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 stdout_list = [ \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 \'An error has occurred: InvalidManifestError: \\n\', \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 \'==> File \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 /Users/robot/.cache/pre-commit/repoxhmwyits/.pre-commit-hooks.yaml\\n\', \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 …
Run Code Online (Sandbox Code Playgroud) 我正在搜索git命令以了解与现有分支(如果有)关联的上游。
(某种与“ write”命令相关联的“ read”命令git branch --set-upstream-to=...
)
,原因是我使用了一个分支,该分支与多个远程存储库连接,并且我想在更改分支之前检查该分支是否已经与右上游连接。
我想直接从ssh命令以交互方式运行docker容器.
我当前的代码如下所示(我echo hi
用作占位符):
$ ssh vagrant@127.0.0.1 -p 2222 "docker run -ti ubuntu:xenial echo hi"
the input device is not a TTY
Run Code Online (Sandbox Code Playgroud)
我也尝试过明确地创建一个交互式登录shell:
$ ssh vagrant@127.0.0.1 -p 2222 "bash -ilc 'docker run -ti ubuntu:xenial'"
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
the input device is not a TTY
Run Code Online (Sandbox Code Playgroud)
如果我ssh并以交互方式运行命令,它的效果很好:
$ ssh vagrant@127.0.0.1 -p 2222
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-34-generic x86_64)
* Documentation: https://help.ubuntu.com/
----------------------------------------------------------------
Ubuntu 14.04.5 …
Run Code Online (Sandbox Code Playgroud) (PYTEST_test_programs) E:\PYTEST_test_programs\Allure_report1>pytest test_file01.py --alluredir="C:\Users\Admin\Desktop\Resumes\reports"
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --alluredir=C:\Users\Admin\Desktop\Resumes\reports
inifile: None
rootdir: E:\PYTEST_test_programs\Allure_report1
Run Code Online (Sandbox Code Playgroud) 我使用双下划线__
作为转储变量而不是_
,如下所示:
needed_value, __ = do_stuff()
use_value(needed_value)
Run Code Online (Sandbox Code Playgroud)
然而,flake8 抱怨,因为它认为我没有使用这个变量。确实如此,但这是故意的。
对于这个特定的用例,有什么方法可以让 flake8 保持沉默吗?
A#noqa
是可能的,但我想要一个在整个项目上执行此操作的选项
python ×4
python-3.x ×4
pre-commit ×3
mypy ×2
allure ×1
apache ×1
centos7 ×1
django ×1
docker ×1
flake8 ×1
git ×1
git-branch ×1
mod-wsgi ×1
pytest ×1
python-black ×1
ssh ×1
yaml ×1