Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update template #289

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/iterative/py-template",
"commit": "15ee26df315020399731c6291d61bef81a3fc5d3",
"commit": "454eb9a60092e980778877f1248072b45a92bb74",
"context": {
"cookiecutter": {
"project_name": "scmrepo",
Expand Down
13 changes: 0 additions & 13 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,10 @@ updates:
interval: "weekly"
labels:
- "maintenance"
# Update via cruft
ignore:
- dependency-name: "mkdocs*"
- dependency-name: "pytest*"
- dependency-name: "pylint"
- dependency-name: "mypy"

- directory: "/"
package-ecosystem: "github-actions"
schedule:
interval: "weekly"
labels:
- "maintenance"
# Update via cruft
ignore:
- dependency-name: "actions/checkout"
- dependency-name: "actions/setup-python"
- dependency-name: "pypa/gh-action-pypi-publish"
- dependency-name: "codecov/codecov-action"
- dependency-name: "peter-evans/create-pull-request"
12 changes: 3 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -14,25 +14,19 @@ repos:
exclude: "README.rst"
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ['--fix=lf']
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.5'
rev: 'v0.1.13'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py38-plus]
78 changes: 78 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,81 @@ ignore_missing_imports = true

[tool.codespell]
ignore-words-list = "cachable, keypair"

[tool.ruff]
ignore = [
"S101", # assert
"PLR2004", # magic-value-comparison
"PLW2901", # redefined-loop-name
"ISC001", # single-line-implicit-string-concatenation
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp
"D203", # one blank line before class
"D213", # multi-line-summary-second-line
"RET501", # unnecessary-return-none
"RET502", # implicit-return-value
"RET503", # implicit-return
"SIM117", # multiple-with-statements
"N818", # error-suffix-on-exception-name
]
select = [
"A", # flake8-buitlins
"ASYNC", # flake8-async
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # mccabe
"DTZ", # flake8-datetimez
"E", # pycodestyle - Error
"EXE", # flake8-executable
"F", # pyflakes
"FLY", # flynt-rules
"G", # flake8-logging-format
"I", # isort
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"PERF101", # perflint
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"Q", # flae8-quotes
"RET", # flake8-return
"RSE", # flake8-raise
"RUF", # ruff
"S", # flake8-bandit
"SIM", # flake8-simplify
"SLOT", # flake8-slots
"T10", # flake8-debugger
"T20", # flake8-print
"TCH", # flake8-type-checking
"TCH", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle - Warning
"YTT", # flake8-2020
]
show-source = true
show-fixes = true

[tool.ruff.per-file-ignores]
"noxfile.py" = ["D", "PTH"]
"tests/**" = ["S", "ARG001", "ARG002", "ANN"]
"docs/**" = ["INP"]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false
parametrize-names-type = "csv"

[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.lint.isort]
known-first-party = ["scmrepo"]

[tool.ruff.pylint]
max-args = 10
4 changes: 1 addition & 3 deletions src/scmrepo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def root_dir(self) -> str:
return self._root_dir

def __repr__(self):
return "{class_name}: '{directory}'".format(
class_name=type(self).__name__, directory=self.dir
)
return f"{type(self).__name__}: '{self.dir}'"

def __exit__(self, exc_type, exc_value, traceback):
self.close()
Expand Down
14 changes: 8 additions & 6 deletions src/scmrepo/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class GitFileSystem(AbstractFileSystem):

def __init__(
self,
path: str = None,
rev: str = None,
path: Optional[str] = None,
rev: Optional[str] = None,
scm: "Git" = None,
trie: "GitTrie" = None,
rev_resolver: Callable[["Git", str], str] = None,
rev_resolver: Optional[Callable[["Git", str], str]] = None,
**kwargs,
):
from scmrepo.git import Git
Expand Down Expand Up @@ -213,8 +213,10 @@ def info(self, path: str, **kwargs: Any) -> Dict[str, Any]:
ret = self.trie.info(key)
ret["name"] = path
return ret
except KeyError:
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path)
except KeyError as exc:
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), path
) from exc

def exists(self, path: str, **kwargs: Any) -> bool:
key = self._get_key(path)
Expand Down Expand Up @@ -255,7 +257,7 @@ def get_file(

with self.open(rpath, "rb", **kwargs) as f1:
if outfile is None:
outfile = open(lpath, "wb")
outfile = open(lpath, "wb") # noqa: SIM115

try:
callback.set_size(getattr(f1, "size", None))
Expand Down
18 changes: 15 additions & 3 deletions src/scmrepo/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
from collections.abc import Mapping
from contextlib import contextmanager
from functools import partialmethod
from typing import TYPE_CHECKING, Callable, Dict, Iterable, Optional, Tuple, Type, Union
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
Dict,
Iterable,
Optional,
Tuple,
Type,
Union,
)

from funcy import cached_property, first
from pathspec.patterns import GitWildMatchPattern
Expand Down Expand Up @@ -41,7 +51,7 @@


class GitBackends(Mapping):
DEFAULT: Dict[str, BackendCls] = {
DEFAULT: ClassVar[Dict[str, BackendCls]] = {
"dulwich": DulwichBackend,
"pygit2": Pygit2Backend,
"gitpython": GitPythonBackend,
Expand Down Expand Up @@ -312,7 +322,9 @@ def get_fs(self, rev: str):
return GitFileSystem(scm=self, rev=rev)

@classmethod
def init(cls, path: str, bare: bool = False, _backend: str = None) -> "Git":
def init(
cls, path: str, bare: bool = False, _backend: Optional[str] = None
) -> "Git":
for name, backend in GitBackends.DEFAULT.items():
if _backend and name != _backend:
continue
Expand Down
16 changes: 7 additions & 9 deletions src/scmrepo/git/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
from typing import TYPE_CHECKING, Callable, Iterable, Mapping, Optional, Tuple, Union

from scmrepo.exceptions import SCMError

from ..objects import GitObject
from scmrepo.git.objects import GitObject

if TYPE_CHECKING:
from scmrepo.git.config import Config
from scmrepo.git.objects import GitCommit, GitTag
from scmrepo.progress import GitProgressEvent

from ..config import Config
from ..objects import GitCommit, GitTag


class NoGitBackendError(SCMError):
def __init__(self, func):
Expand Down Expand Up @@ -50,7 +48,7 @@ def clone(
url: str,
to_path: str,
shallow_branch: Optional[str] = None,
progress: Callable[["GitProgressEvent"], None] = None,
progress: Optional[Callable[["GitProgressEvent"], None]] = None,
bare: bool = False,
mirror: bool = False,
):
Expand Down Expand Up @@ -229,7 +227,7 @@ def push_refspecs(
refspecs: Union[str, Iterable[str]],
force: bool = False,
on_diverged: Optional[Callable[[str, str], bool]] = None,
progress: Callable[["GitProgressEvent"], None] = None,
progress: Optional[Callable[["GitProgressEvent"], None]] = None,
**kwargs,
) -> Mapping[str, SyncStatus]:
"""Push refspec to a remote Git repo.
Expand All @@ -253,7 +251,7 @@ def fetch_refspecs(
refspecs: Union[str, Iterable[str]],
force: bool = False,
on_diverged: Optional[Callable[[str, str], bool]] = None,
progress: Callable[["GitProgressEvent"], None] = None,
progress: Optional[Callable[["GitProgressEvent"], None]] = None,
**kwargs,
) -> Mapping[str, SyncStatus]:
"""Fetch refspecs from a remote Git repo.
Expand Down Expand Up @@ -333,7 +331,7 @@ def diff(self, rev_a: str, rev_b: str, binary=False) -> str:
"""Return the git diff for two commits."""

@abstractmethod
def reset(self, hard: bool = False, paths: Iterable[str] = None):
def reset(self, hard: bool = False, paths: Optional[Iterable[str]] = None):
"""Reset current git HEAD."""

@abstractmethod
Expand Down
Loading
Loading