summaryrefslogtreecommitdiffstats
path: root/pre_commit/store.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:22 +0000
commitce6763317433ca8509f45bd1d471fb4ad2eeffdd (patch)
treea648ad7d54a5d3ffaa8519e7c73ea27541105c9b /pre_commit/store.py
parentReleasing debian version 2.21.0-1. (diff)
downloadpre-commit-ce6763317433ca8509f45bd1d471fb4ad2eeffdd.tar.xz
pre-commit-ce6763317433ca8509f45bd1d471fb4ad2eeffdd.zip
Merging upstream version 3.0.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--pre_commit/store.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/pre_commit/store.py b/pre_commit/store.py
index effebfb..6ddc7c4 100644
--- a/pre_commit/store.py
+++ b/pre_commit/store.py
@@ -36,6 +36,26 @@ def _get_default_directory() -> str:
return os.path.realpath(ret)
+_LOCAL_RESOURCES = (
+ 'Cargo.toml', 'main.go', 'go.mod', 'main.rs', '.npmignore',
+ 'package.json', 'pre-commit-package-dev-1.rockspec',
+ 'pre_commit_placeholder_package.gemspec', 'setup.py',
+ 'environment.yml', 'Makefile.PL', 'pubspec.yaml',
+ 'renv.lock', 'renv/activate.R', 'renv/LICENSE.renv',
+)
+
+
+def _make_local_repo(directory: str) -> None:
+ for resource in _LOCAL_RESOURCES:
+ resource_dirname, resource_basename = os.path.split(resource)
+ contents = resource_text(f'empty_template_{resource_basename}')
+ target_dir = os.path.join(directory, resource_dirname)
+ target_file = os.path.join(target_dir, resource_basename)
+ os.makedirs(target_dir, exist_ok=True)
+ with open(target_file, 'w') as f:
+ f.write(contents)
+
+
class Store:
get_default_directory = staticmethod(_get_default_directory)
@@ -185,37 +205,9 @@ class Store:
return self._new_repo(repo, ref, deps, clone_strategy)
- LOCAL_RESOURCES = (
- 'Cargo.toml', 'main.go', 'go.mod', 'main.rs', '.npmignore',
- 'package.json', 'pre-commit-package-dev-1.rockspec',
- 'pre_commit_placeholder_package.gemspec', 'setup.py',
- 'environment.yml', 'Makefile.PL', 'pubspec.yaml',
- 'renv.lock', 'renv/activate.R', 'renv/LICENSE.renv',
- )
-
def make_local(self, deps: Sequence[str]) -> str:
- def make_local_strategy(directory: str) -> None:
- for resource in self.LOCAL_RESOURCES:
- resource_dirname, resource_basename = os.path.split(resource)
- contents = resource_text(f'empty_template_{resource_basename}')
- target_dir = os.path.join(directory, resource_dirname)
- target_file = os.path.join(target_dir, resource_basename)
- os.makedirs(target_dir, exist_ok=True)
- with open(target_file, 'w') as f:
- f.write(contents)
-
- env = git.no_git_env()
-
- # initialize the git repository so it looks more like cloned repos
- def _git_cmd(*args: str) -> None:
- cmd_output_b('git', *args, cwd=directory, env=env)
-
- git.init_repo(directory, '<<unknown>>')
- _git_cmd('add', '.')
- git.commit(repo=directory)
-
return self._new_repo(
- 'local', C.LOCAL_REPO_VERSION, deps, make_local_strategy,
+ 'local', C.LOCAL_REPO_VERSION, deps, _make_local_repo,
)
def _create_config_table(self, db: sqlite3.Connection) -> None: