0

Currently doing workaround in an access restricted Wndows10 VM, manipulating a git repo with pip pre-commit package under git bash and python virtualenv environment. However, got the following sqlite3 error. While at the same time, I tried in different VM with admin permission and it's working fine.

  • Is there a way to change pre-commit's default .cache path, such as to e:\workspace\.venv\.cache\pre-commit ? It's under my virtualenv folder, so it's more controllable from my side.
  • Is it possible to change it's default sqlite3 to some others data storage such as file or memory ? I wonder this VM doesn't allow me to run sqlite3 with current permission.

.pre-commit-config.yaml

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
    -   id: end-of-file-fixer
    -   id: trailing-whitespace
    files: (^src/|^tests/)
    exclude: .coveragerc

install pre-commit

$ pre-commit install
pre-commit installed at .git\hooks\pre-commit

$ ls ~/.cache/pre-commit
db.db  README  tmp0_c9m5xl
(.venv)

pre-commit run

$ pre-commit run -a
An unexpected error has occurred: OperationalError: no such table: repos
Check the log at C:\Users\kevinwu\.cache\pre-commit\pre-commit.log
(.venv)

pre-commit.log


For pre-commit run

version information

pre-commit version: 2.18.1
git --version: git version 2.35.1.windows.2
sys.version:
    3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)]
sys.executable: e:\workspace\.venv\scripts\python.exe
os.name: nt
sys.platform: win32

error information

An unexpected error has occurred: OperationalError: no such table: repos
Traceback (most recent call last):
  File "e:\workspace\.venv\lib\site-packages\pre_commit\error_handler.py", line 73, in error_handler
    yield
  File "e:\workspace\.venv\lib\site-packages\pre_commit\main.py", line 371, in main
    return run(args.config, store, args)
  File "e:\workspace\.venv\lib\site-packages\pre_commit\commands\run.py", line 401, in run
    for hook in all_hooks(config, store)
  File "e:\workspace\.venv\lib\site-packages\pre_commit\repository.py", line 225, in all_hooks
    return tuple(
  File "e:\workspace\.venv\lib\site-packages\pre_commit\repository.py", line 228, in <genexpr>
    for hook in _repository_hooks(repo, store, root_config)
  File "e:\workspace\.venv\lib\site-packages\pre_commit\repository.py", line 203, in _repository_hooks
    return _cloned_repository_hooks(repo_config, store, root_config)
  File "e:\workspace\.venv\lib\site-packages\pre_commit\repository.py", line 169, in _cloned_repository_hooks
    manifest_path = os.path.join(store.clone(repo, rev), C.MANIFEST_FILE)
  File "e:\workspace\.venv\lib\site-packages\pre_commit\store.py", line 186, in clone
    return self._new_repo(repo, ref, deps, clone_strategy)
  File "e:\workspace\.venv\lib\site-packages\pre_commit\store.py", line 130, in _new_repo
    result = _get_result()
  File "e:\workspace\.venv\lib\site-packages\pre_commit\store.py", line 124, in _get_result
    result = db.execute(
sqlite3.OperationalError: no such table: repos

Update


pre-commit clean

$ pre-commit clean && pre-commit install-hooks
Cleaned C:\Users\kevinwu\.cache\pre-commit.
An unexpected error has occurred: OperationalError: no such table: repos
Check the log at C:\Users\kevinwu\.cache\pre-commit\pre-commit.log
(.venv)

Got the same error as the one in the beginning

error information

An unexpected error has occurred: OperationalError: no such table: repos

pre-commit package information

$ pip uninstall pre-commit
Uninstalling pre-commit-2.18.1:
  Would remove:
    e:\workspace\.venv\lib\site-packages\pre_commit-2.18.1.dist-info\*
    e:\workspace\.venv\lib\site-packages\pre_commit\*
    e:\workspace\.venv\scripts\pre-commit-validate-config.exe
    e:\workspace\.venv\scripts\pre-commit-validate-manifest.exe
    e:\workspace\.venv\scripts\pre-commit.exe
Proceed (y/n)? y
  Successfully uninstalled pre-commit-2.18.1
(.venv)

$ pip install pre-commit
Collecting pre-commit
  Using cached https://files.pythonhosted.org/packages/33/80/e95ffa9ec9649979d177229eaea8169ac9d3b32508fcb274630214d2287a/pre_commit-2.18.1-py2.py3-none-any.whl
Requirement already satisfied: pyyaml>=5.1 in e:\workspace\.venv\lib\site-packages (from pre-commit) (6.0)
Requirement already satisfied: toml in e:\workspace\.venv\lib\site-packages (from pre-commit) (0.10.2)
Requirement already satisfied: nodeenv>=0.11.1 in e:\workspace\.venv\lib\site-packages (from pre-commit) (1.6.0)
Requirement already satisfied: cfgv>=2.0.0 in e:\workspace\.venv\lib\site-packages (from pre-commit) (3.3.1)
Requirement already satisfied: identify>=1.0.0 in e:\workspace\.venv\lib\site-packages (from pre-commit) (2.4.12)
Requirement already satisfied: virtualenv>=20.0.8 in e:\workspace\.venv\lib\site-packages (from pre-commit) (20.14.0)
Requirement already satisfied: distlib<1,>=0.3.1 in e:\workspace\.venv\lib\site-packages (from virtualenv>=20.0.8->pre-commit) (0.3.4)
Requirement already satisfied: platformdirs<3,>=2 in e:\workspace\.venv\lib\site-packages (from virtualenv>=20.0.8->pre-commit) (2.5.1)
Requirement already satisfied: six<2,>=1.9.0 in e:\workspace\.venv\lib\site-packages (from virtualenv>=20.0.8->pre-commit) (1.16.0)
Requirement already satisfied: filelock<4,>=3.2 in e:\workspace\.venv\lib\site-packages (from virtualenv>=20.0.8->pre-commit) (3.6.0)
Installing collected packages: pre-commit
Successfully installed pre-commit-2.18.1
WARNING: You are using pip version 19.2.3, however version 22.0.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
(.venv)

$ pip show pre-commit
Name: pre-commit
Version: 2.18.1
Summary: A framework for managing and maintaining multi-language pre-commit hooks.
Home-page: https://github.com/pre-commit/pre-commit
Author: Anthony Sottile
Author-email: asottile@umich.edu
License: MIT
Location: e:\workspace\.venv\lib\site-packages
Requires: nodeenv, toml, identify, virtualenv, cfgv, pyyaml
Required-by:
(.venv)
nwpie
  • 665
  • 11
  • 24
  • I'm not sure how you possibly got into this state with the database existing but missing its tables -- does `pre-commit clean` fix it? – anthony sottile Apr 19 '22 at 14:54
  • @AnthonySottile clean will remove everything under that .cache folder so need to install again. Then will got error again for any run afterwards. – nwpie Apr 19 '22 at 15:13
  • can you include the full output of: `pre-commit clean && pre-commit install-hooks` ? – anthony sottile Apr 19 '22 at 15:22
  • that error indicates you have the cache open in an explorer window? try closing that and then repeating? – anthony sottile Apr 19 '22 at 16:06
  • @AnthonySottile Looks like I got exactly same error from the begining. ``` $ pre-commit clean && pre-commit install-hooks Cleaned C:\Users\kevinwu\.cache\pre-commit. An unexpected error has occurred: OperationalError: no such table: repos Check the log at C:\Users\kevinwu\.cache\pre-commit\pre-commit.log (.venv) ``` – nwpie Apr 19 '22 at 16:07
  • have you edited the `pre-commit` install in any way -- that should be impossible: https://github.com/pre-commit/pre-commit/blob/e1ce4c0bf32f905a93dd22f0bd9be26c2561ab6a/pre_commit/store.py#L60-L81 – anthony sottile Apr 19 '22 at 16:15
  • @AnthonySottile I also put `pre-commit` package information in the post. So it's showing the package is from `https://files.pythonhosted.org/packages/33/80/**hash**/pre_commit-2.18.1-py2.py3-none-any.whl` and I just installed it in normal way. – nwpie Apr 19 '22 at 16:29
  • what filesystem is the `C:\Users\kevinwu`? is it possible that `os.replace` doesn't work on it somehow and silently does nothing? – anthony sottile Apr 19 '22 at 16:31
  • @AnthonySottile As I know, I could do some stuff on disk E, got mounted by IT, while in disk C, usually need admin permission so have no idea on that looks like virtual system path maybe. – nwpie Apr 19 '22 at 16:37
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/244037/discussion-between-nwpie-and-anthony-sottile). – nwpie Apr 20 '22 at 05:31

1 Answers1

0

A workable workaround solution here by referring to source code in pre_commit/store.py

  • Setup PRE_COMMIT_HOME in the environment variable will change pre-commit's default working directory, including .cache path.

  • Modify TMPDIR, TEMP or TMP environment variables to your fully accessible directory is also necessary for workaround. Please be aware of tempfile.mkstemp is a platform-dependent function used in internal pre-commit process.

Now it's working fine on pre-commit scripts, install-hooks, run, autoupdate, etc. enter image description here Thanks @AnthonySottile and community's help!

nwpie
  • 665
  • 11
  • 24
  • @AnthonySottile, thanks for your help. Please see my workaround in this answer. – nwpie Apr 20 '22 at 05:33
  • fwiw this is [documented](https://pre-commit.com/#managing-ci-caches) -- but really you should figure out why `os.replace` is silently failing on your system – anthony sottile Apr 20 '22 at 13:46