我有一些 python 代码格式化程序作为 git 预提交挂钩,并且我已将我的 python 版本更改为
brew list | grep python
python@3.7
python@3.9
brew unlink python@3.7
brew unlink python@3.9
brew link python@3.7
python -V
Python 3.7.9
Run Code Online (Sandbox Code Playgroud)
并且知道似乎有些东西被破坏了,并且在 git commit 上我得到了env: python3.9: No such file or directory
,那么是什么env
?以及我如何编辑它以使用python@3.7
?
我最近从我的环境中卸载了预提交。我在 pipelinev 中执行了以下操作:
pipenv --rm
<deleted Pipfile and Pipfile.lock>
pipenv install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
我确保预提交模块不再位于requirements.txt 中。当我进行 git 提交时,我得到:
~/my_project/.venv/bin/python: No module named pre_commit
Run Code Online (Sandbox Code Playgroud)
这阻止了我提交,而且我不知道这是从哪里来的,因为未安装预提交。此外,指定的回溯路径指向 python 而不是 python3。我缺少什么?
我不确定这段代码是否会编译.
我正在使用的示例代码:
#include <iostream>
using std::cout;
using std::endl;
class Foo {
public:
template<typename T>
Foo& operator<<(const T& t) {
cout << t;
return *this;
}
};
int main() {
Foo foo;
foo << "Hello World"; // perfectly fine
foo << endl; // shit hits the fan
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
test.cpp:19:12: error: no match for ‘operator<<’ in ‘foo << std::endl’
test.cpp:19:12: note: candidates are:
test.cpp:10:14: note: template<class T> Foo& Foo::operator<<(const T&)
test.cpp:10:14: note: template argument deduction/substitution failed:
test.cpp:19:12: note: couldn't …
Run Code Online (Sandbox Code Playgroud) 我正在尝试重构一段遗留代码,并且我想要在源中的某个点定义的所有宏的快照.代码导入了一些荒谬的标题等,手动跟踪它们有点乏味.
就像是
#define FOO 1
int myFunc(...) {
PRINT_ALL_DEFINED_THINGS(stderr)
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
预计输出中的某个地方
MACRO: "FOO" value 1
Run Code Online (Sandbox Code Playgroud)
我正在使用gcc,但如果它们更容易完成此任务,则可以访问其他编译器.
编辑:
链接的问题没有给我正确的输出:
#include <stdio.h>
#define FOO 1
int main(void) {
printf("%d\n", FOO);
}
#define FOO 0
Run Code Online (Sandbox Code Playgroud)
1
运行时打印非常清晰,但gcc test.c -E -dM | grep FOO
给出0
使用包含setup_requires的以下简单包:
from setuptools import setup
setup(name='my_package', setup_requires=['cython'])
Run Code Online (Sandbox Code Playgroud)
假设我已经完成以下操作来构建它到源代码分发:
$ python setup.py sdist
并下载了Cython的源代码发行版
$ pip install --download ./dist/ --no-use-wheel Cython
所以现在我有:
$ ls dist/
my_package-0.0.0.tar.gz
Cython-0.21.1.tar.gz
Run Code Online (Sandbox Code Playgroud)
我希望能够做的是使用某些组合--find-links
等将软件包安装在网络隔离的机器上.
我想我能做点什么
pip install --no-index --find-links="file:///$(pwd)/dists" dist/my_package-0.0.0.tar.gz
但是我得到一个看起来像这样的错误:
No local packages or download links found for cython
(全文:http: //paste.pound-python.org/show/IxmzEEfQ5yZRU45i2FBM/)
我尝试过的失败了:
设置以下内容
[easy_install]
allow_hosts = ''
find_links = file:///$(pwd)/emr-sdists
Run Code Online (Sandbox Code Playgroud)
在:
/usr/lib/python2.6/distutils/distutils.cfg
~/.pydistutils.cfg
./setup.cfg
Run Code Online (Sandbox Code Playgroud)
我正在使用--net none
docker 的设置来帮助调试它,如果它让你更容易进行复制.
按照 Pre-Commit网站上的“非管理安装”说明,我运行了以下命令:
curl http://pre-commit.com/install-local.py | python
Run Code Online (Sandbox Code Playgroud)
这些说明提供了以下注释:“ (升级:再次运行,卸载:将卸载传递给 python)。 ”
现在,我想卸载预提交。我试图了解如何将卸载传递给 Python。我不确定传递uninstall
意味着什么。
我试过了:
curl http://pre-commit.com/install-local.py | python --uninstall
curl http://pre-commit.com/install-local.py | --uninstall python
curl http://pre-commit.com/install-local.py | uninstall | python
Run Code Online (Sandbox Code Playgroud)
..和其他几个可能更无意义的变化。所有这些都会导致:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Unknown option: -n
usage: /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python [option] ... [-c cmd | -m mod | file | -] [arg] …
Run Code Online (Sandbox Code Playgroud) 我将预提交与这个 .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
我想为团队添加以下内容以进行预提交:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.720'
hooks:
- id: mypy
args: [--ignore-missing-imports]
Run Code Online (Sandbox Code Playgroud)
我的团队担心这可能太严格了。为了逐步介绍,我希望这个钩子不会使提交失败,而只是为了显示问题。那可能吗?
请帮助解决来自多个进程的 python3 日志记录到同一个日志文件的问题。我有 dameon 主脚本,它在后台运行,每 15 秒调用一些其他 python 脚本,并且每个 python 脚本都使用相同的 TimedRotatingFileHandler 属性编写,并且所有日志都写入相同的日志文件。
一切正常,除了日志轮换。
lib/
??? __init__.py
??? FIRST.py
??? SECOND.py
??? THIRD.py
main_daemon.py
Run Code Online (Sandbox Code Playgroud)
主 python 守护程序文件看起来像
t1 = t2 = t3 = Thread()
my_thread = MYthreads(t1, t2, t3)
################# Daemon Class #################
class Daemon(Daemon):
def run(self):
while True:
my_thread.start_my_class()
time.sleep(15)
ProcessManager = Daemon('daemon.pid')
ProcessManager.start()
Run Code Online (Sandbox Code Playgroud)
lib/__init__.py
文件看起来不错
class MYthreads:
def __init__(self, t1, t2, t3):
self.t1 = t1
self.t2 = t2
self.t3 = t3
def start_my_class(self):
for file in List_files(path1):
self.t1 …
Run Code Online (Sandbox Code Playgroud) 我尝试在提交之前配置 start mypy + django-stubs 检查。我使用预提交。当我尝试提交时,出现错误django.core.exceptions.ImproperlyConfigured:设置 POSTGRES_DB 环境变量。该变量位于 .env 文件中,我使用 django-environ 将变量从 .env 导出到 Django 配置。当然还有 .gitignore 中的 .env。所以,据我了解:预提交从它自己的虚拟环境开始,它不知道我的 .env 文件。
最重要的是,我是否正确理解了我的情况?如果我是对的,如何将变量从 .env 文件获取到预提交环境?
我的.pre-commit-config.yaml(部分)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: ''
hooks:
- id: mypy
exclude: "[a-zA-Z]*/(migrations)/(.)*"
args: [--config=setup.cfg,
--no-strict-optional,
--ignore-missing-imports]
additional_dependencies: [django-stubs, django-environ]
Run Code Online (Sandbox Code Playgroud)
我的设置.cfg
[mypy]
python_version = 3.9
allow_redefinition = True
check_untyped_defs = True
ignore_missing_imports = True
incremental = True
strict_optional = True
show_traceback = True
warn_no_return = False
warn_unused_ignores = True
warn_redundant_casts = True …
Run Code Online (Sandbox Code Playgroud) python ×5
pre-commit ×3
mypy ×2
python-3.x ×2
c ×1
c++ ×1
distutils ×1
django ×1
django-stubs ×1
homebrew ×1
iostream ×1
logging ×1
macos ×1
macros ×1
manipulators ×1
pip ×1
pipenv ×1
setuptools ×1
templates ×1
yaml ×1