我正在尝试设置 pylint 以使用预提交。我已经查看了文档,但我仍然感到困惑。我不知道如何正确设置 .pre-commit-config.yaml。
你能提供最基本的模板吗?
- repo: myrepo
rev: '' # Don't know that to type here
hooks:
- id: pylint
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
是可能的,但我想要一个在整个项目上执行此操作的选项
我正在努力使用 isort 库,它正在对我的项目中的导入进行排序。
为了避免循环依赖,我需要按以下顺序导入包:
from foo import *
from bar import *
from eggs import *
from spam import *
Run Code Online (Sandbox Code Playgroud)
但它并没有像您所期望的那样按字母顺序对它们进行排序。
from bar import *
from eggs import *
from foo import *
from spam import *
Run Code Online (Sandbox Code Playgroud)
我尝试使用noqa
一些代码来导入行和整个文件,但没有帮助。
如何忽略/noqa orderign 进行该导入?
我正在努力将环境变量使用到预提交挂钩配置的参数部分
以下是一个示例 spinet 来展示我正在尝试做的事情
- repo: https://github.com/returntocorp/semgrep
rev: "v0.1.2"
hooks:
- id: semgrep
name: semgrep my_custom_rule
args:
[
"--config",
"https://PRIVATE-TOKEN:{$TOKEN}@gitlab.com/api/proj/packages/test-rule.yml",
"--error",
]
Run Code Online (Sandbox Code Playgroud)
我已经将 TOKEN 的值设置到环境变量中。但仍在处理中,URL 被视为 https://PRIVATE-TOKEN:{$TOKEN}@gitlab.com/api/proj/packages/test-rule.yml 而不是实际的令牌值。出于安全原因,我想避免将实际令牌放入配置中。
我正在使用 Python 3.4.6。
这里是工厂:
def create_parser():
""" Create argument parser """
# Input configuration parameters
_parser = argparse.ArgumentParser(description='Segments Engine')
# Application only parameters
_parser.add_argument(
'-V', '--version', version='%(prog)s ' + __version__,
action='version')
_pasrser.add_argument(
'-d', '--debug', action='store_true')
return _parser
Run Code Online (Sandbox Code Playgroud)
测试用例如下:
class TestCli(unittest.TestCase):
""" Test the cli.py module """
def __init__(self, *args, **kwargs):
""" Initialize Unit Test """
super(TestCli, self).__init__(*args, **kwargs)
def setup(self):
""" Setup before each test case """
setup_config(app)
setup_logging(app)
def teardown(self):
""" Tear down after each test case """
pass …
Run Code Online (Sandbox Code Playgroud) 我正在按照办公室指南创建钩子并将其添加到预提交检查过程中。我需要创建 3 个文件
.pre-commit-config.yaml
.pre-commit-hooks.yaml
theCheckFile.sh
Run Code Online (Sandbox Code Playgroud)
配置文件配置hooks文件,该文件调用theCheckFils.sh文件来检查我的代码风格。
Q.1我应该把这些文件放在哪里?我目前将它们放入我的项目文件夹中,并编辑 .gitignore 文件以忽略所有它们,有更好的建议吗?或者这样就可以了。
Q.2 pre-commit-config.yaml 文件中需要 rev,我应该在哪里找到此信息,我当前使用的代码 Repo 中没有版本信息,我可以随机创建一个数字吗?
我正在尝试遵循JupyterHub的贡献文档,但在运行时出现错误pre-commit run
该错误与我的 python 版本有关。3.6
尽管一切都安装了 Python ,但出于某种原因,它仍然在期待3.7.3
。这是运行命令的输出:
(.hub) {~/jupyter/jupyterhub} (master %)$ pre-commit run
[INFO] Initializing environment for https://github.com/asottile/reorder_python_imports.
[INFO] Initializing environment for https://github.com/ambv/black.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/asottile/reorder_python_imports.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: Command: ('/Users/nicholasbrady/jupyter/jupyterhub/.hub/bin/python3', '-mvirtualenv', '/Users/nicholasbrady/.cache/pre-commit/repo5hv9ofak/py_env-python3.6', '-p', 'python3.6')
Return code: 3
Expected return code: 0
Output:
The path python3.6 …
Run Code Online (Sandbox Code Playgroud) 我有一个Python
项目,当我尝试提交(通过 miniconda)时:
$ git add -A && git commit -m `test`
Run Code Online (Sandbox Code Playgroud)
我得到以下失败:
(base) D:\machinelearning.com-python>git commit -m 'test'
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to C:\Users\anon/.cache\pre-commit\patch1570560215.
Trim Trailing Whitespace.................................................Passed
Check for added large files..............................................Passed
Check python ast.........................................................Passed
Check JSON...........................................(no files to check)Skipped
Check for merge conflicts................................................Passed
Check Xml............................................(no files to check)Skipped
Check Yaml...........................................(no files to check)Skipped
Debug Statements (Python)................................................Passed
Fix End of Files.........................................................Passed
Fix requirements.txt.................................(no files to check)Skipped
Mixed line ending........................................................Passed
Flake8...................................................................Passed
isort....................................................................Failed
hookid: isort
Files were …
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行预提交挂钩,但是当它们遇到 isort 挂钩时会失败,该挂钩会引发以下错误:
File "/home/el/.cache/pre-commit/repoffrjhcx0/py_env-python3/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 92, in create_module
return importlib.import_module('setuptools._distutils')
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'
Run Code Online (Sandbox Code Playgroud)
我正在使用 docker,并且我已经检查了 setuptools 是否已安装在我的全局计算机和 docker 上。我不明白为什么会出现这个错误。我认为 isort 设置了它自己的环境,但是为什么它不会被安装,因为它是在配置文件pyproject.toml中定义的。
以下是我的预提交和 isort 配置:
.pre-commit-config.yaml
repos:
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
args: ["--multi-line=5", "--line-length=120", "--use-parentheses", "--filter-files"]
exclude: "migrations"
stages: [commit]
Run Code Online (Sandbox Code Playgroud)
毒物文件
[isort]
line_length=120
skip_glob=*migrations*
multi_line_output=5
sections=FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
use_parentheses=true
include_trailing_comma=true
lines_between_types=1
lines_after_imports=2
[testenv:isort]
deps =
isort
commands =
isort . --check-only --diff
Run Code Online (Sandbox Code Playgroud)
系统上的Python版本:3.10.1 …
python-3.x ×4
python ×3
git ×2
isort ×2
pre-commit ×2
pytest ×2
allure ×1
anaconda ×1
argparse ×1
flake8 ×1
githooks ×1
jupyterhub ×1
miniconda ×1
pylint ×1
python-3.7 ×1
semgrep ×1