Skip to content

Commit

Permalink
update contributing, add more pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed Jan 10, 2024
1 parent c3601a2 commit fb02009
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 67 deletions.
28 changes: 7 additions & 21 deletions dbt_common/clients/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ def find_matching(
relative_path_to_root = os.path.join(relative_path_to_search, relative_path)

modification_time = os.path.getmtime(absolute_path)
if reobj.match(local_file) and (
not ignore_spec or not ignore_spec.match_file(relative_path_to_root)
):
if reobj.match(local_file) and (not ignore_spec or not ignore_spec.match_file(relative_path_to_root)):
matching.append(
{
"searched_path": relative_path_to_search,
Expand Down Expand Up @@ -389,18 +387,14 @@ def _handle_windows_error(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
cls: Type[dbt_common.exceptions.DbtBaseException] = dbt_common.exceptions.base.CommandError
if exc.errno == errno.ENOENT:
message = (
"Could not find command, ensure it is in the user's PATH "
"and that the user has permissions to run it"
"Could not find command, ensure it is in the user's PATH " "and that the user has permissions to run it"
)
cls = dbt_common.exceptions.ExecutableError
elif exc.errno == errno.ENOEXEC:
message = "Command was not executable, ensure it is valid"
cls = dbt_common.exceptions.ExecutableError
elif exc.errno == errno.ENOTDIR:
message = (
"Unable to cd: path does not exist, user does not have"
" permissions, or not a directory"
)
message = "Unable to cd: path does not exist, user does not have" " permissions, or not a directory"
cls = dbt_common.exceptions.WorkingDirectoryError
else:
message = 'Unknown error: {} (errno={}: "{}")'.format(
Expand All @@ -421,9 +415,7 @@ def _interpret_oserror(exc: OSError, cwd: str, cmd: List[str]) -> NoReturn:
_handle_posix_error(exc, cwd, cmd)

# this should not be reachable, raise _something_ at least!
raise dbt_common.exceptions.DbtInternalError(
"Unhandled exception in _interpret_oserror: {}".format(exc)
)
raise dbt_common.exceptions.DbtInternalError("Unhandled exception in _interpret_oserror: {}".format(exc))


def run_cmd(cwd: str, cmd: List[str], env: Optional[Dict[str, Any]] = None) -> Tuple[bytes, bytes]:
Expand All @@ -442,9 +434,7 @@ def run_cmd(cwd: str, cmd: List[str], env: Optional[Dict[str, Any]] = None) -> T
exe_pth = shutil.which(cmd[0])
if exe_pth:
cmd = [os.path.abspath(exe_pth)] + list(cmd[1:])
proc = subprocess.Popen(
cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=full_env
)
proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=full_env)

out, err = proc.communicate()
except OSError as exc:
Expand All @@ -460,9 +450,7 @@ def run_cmd(cwd: str, cmd: List[str], env: Optional[Dict[str, Any]] = None) -> T
return out, err


def download_with_retries(
url: str, path: str, timeout: Optional[Union[float, tuple]] = None
) -> None:
def download_with_retries(url: str, path: str, timeout: Optional[Union[float, tuple]] = None) -> None:
download_fn = functools.partial(download, url, path, timeout)
connection_exception_retry(download_fn, 5)

Expand Down Expand Up @@ -553,9 +541,7 @@ def move(src, dst):
if os.path.isdir(src):
if _absnorm(dst + "\\").startswith(_absnorm(src + "\\")):
# dst is inside src
raise EnvironmentError(
"Cannot move a directory '{}' into itself '{}'".format(src, dst)
)
raise EnvironmentError("Cannot move a directory '{}' into itself '{}'".format(src, dst))
shutil.copytree(src, dst, symlinks=True)
rmtree(src)
else:
Expand Down
4 changes: 1 addition & 3 deletions dbt_common/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@
from dbt_common.events.logger import LineFormat

# make sure event manager starts with a logger
get_event_manager().add_logger(
get_stdout_config(LineFormat.PlainText, True, EventLevel.INFO, False)
)
get_event_manager().add_logger(get_stdout_config(LineFormat.PlainText, True, EventLevel.INFO, False))
34 changes: 8 additions & 26 deletions dbt_common/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,14 @@ def to_version_string(self, skip_matcher=False):

if not skip_matcher:
matcher = self.matcher
return "{}{}.{}.{}{}{}".format(
matcher, self.major, self.minor, self.patch, prerelease, build
)
return "{}{}.{}.{}{}{}".format(matcher, self.major, self.minor, self.patch, prerelease, build)

@classmethod
def from_version_string(cls, version_string):
match = _VERSION_REGEX.match(version_string)

if not match:
raise dbt_common.exceptions.base.SemverError(
f'"{version_string}" is not a valid semantic version.'
)
raise dbt_common.exceptions.base.SemverError(f'"{version_string}" is not a valid semantic version.')

matched = {k: v for k, v in match.groupdict().items() if v is not None}

Expand Down Expand Up @@ -158,33 +154,23 @@ def compare(self, other):
return -1
# else is equal and will fall through

equal = (
self.matcher == Matchers.GREATER_THAN_OR_EQUAL
and other.matcher == Matchers.LESS_THAN_OR_EQUAL
) or (
self.matcher == Matchers.LESS_THAN_OR_EQUAL
and other.matcher == Matchers.GREATER_THAN_OR_EQUAL
equal = (self.matcher == Matchers.GREATER_THAN_OR_EQUAL and other.matcher == Matchers.LESS_THAN_OR_EQUAL) or (
self.matcher == Matchers.LESS_THAN_OR_EQUAL and other.matcher == Matchers.GREATER_THAN_OR_EQUAL
)
if equal:
return 0

lt = (
(self.matcher == Matchers.LESS_THAN and other.matcher == Matchers.LESS_THAN_OR_EQUAL)
or (
other.matcher == Matchers.GREATER_THAN
and self.matcher == Matchers.GREATER_THAN_OR_EQUAL
)
or (other.matcher == Matchers.GREATER_THAN and self.matcher == Matchers.GREATER_THAN_OR_EQUAL)
or (self.is_upper_bound and other.is_lower_bound)
)
if lt:
return -1

gt = (
(other.matcher == Matchers.LESS_THAN and self.matcher == Matchers.LESS_THAN_OR_EQUAL)
or (
self.matcher == Matchers.GREATER_THAN
and other.matcher == Matchers.GREATER_THAN_OR_EQUAL
)
or (self.matcher == Matchers.GREATER_THAN and other.matcher == Matchers.GREATER_THAN_OR_EQUAL)
or (self.is_lower_bound and other.is_upper_bound)
)
if gt:
Expand Down Expand Up @@ -354,9 +340,7 @@ def to_version_string_pair(self):

class UnboundedVersionSpecifier(VersionSpecifier):
def __init__(self, *args, **kwargs) -> None:
super().__init__(
matcher=Matchers.EXACT, major=None, minor=None, patch=None, prerelease=None, build=None
)
super().__init__(matcher=Matchers.EXACT, major=None, minor=None, patch=None, prerelease=None, build=None)

def __str__(self):
return "*"
Expand Down Expand Up @@ -467,7 +451,5 @@ def filter_installable(versions: List[str], install_prerelease: bool) -> List[st
installable.append(version)
installable_dict[str(version)] = version_string
sorted_installable = sorted(installable)
sorted_installable_original_versions = [
str(installable_dict.get(str(version))) for version in sorted_installable
]
sorted_installable_original_versions = [str(installable_dict.get(str(version))) for version in sorted_installable]
return sorted_installable_original_versions
16 changes: 4 additions & 12 deletions tests/unit/test_system_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def test__make_file_when_not_exists(self):

def test__make_file_with_overwrite(self):
self.set_up_profile()
written = dbt_common.clients.system.make_file(
self.profiles_path, contents="NEW_TEXT", overwrite=True
)
written = dbt_common.clients.system.make_file(self.profiles_path, contents="NEW_TEXT", overwrite=True)

self.assertTrue(written)
self.assertEqual(self.get_profile_text(), "NEW_TEXT")
Expand Down Expand Up @@ -201,9 +199,7 @@ def test_ignore_spec(self):
self.tempdir,
[""],
"*.sql",
pathspec.PathSpec.from_lines(
pathspec.patterns.GitWildMatchPattern, "sql-files*".splitlines()
),
pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, "sql-files*".splitlines()),
)
self.assertEqual(out, [])

Expand Down Expand Up @@ -246,9 +242,7 @@ def test_untar_package_success(self):

def test_untar_package_failure(self):
# create a text file then rename it as a tar (so it's invalid)
with NamedTemporaryFile(
prefix="a", suffix=".txt", dir=self.tempdir, delete=False
) as file_a:
with NamedTemporaryFile(prefix="a", suffix=".txt", dir=self.tempdir, delete=False) as file_a:
file_a.write(b"some text in the text file")
txt_file_name = file_a.name
file_path = os.path.dirname(txt_file_name)
Expand All @@ -261,9 +255,7 @@ def test_untar_package_failure(self):

def test_untar_package_empty(self):
# create a tarball with nothing in it
with NamedTemporaryFile(
prefix="my-empty-package.2", suffix=".tar.gz", dir=self.tempdir
) as named_file:
with NamedTemporaryFile(prefix="my-empty-package.2", suffix=".tar.gz", dir=self.tempdir) as named_file:

# make sure we throw an error for the empty file
with self.assertRaises(tarfile.ReadError) as exc:
Expand Down
6 changes: 1 addition & 5 deletions third-party-stubs/colorama/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
from typing import Optional, Any


class Fore:
RED: str = ...
GREEN: str = ...
YELLOW: str = ...


class Style:
RESET_ALL: str = ...


def init(
autoreset: bool = ...,
convert: Optional[Any] = ...,
strip: Optional[Any] = ...,
wrap: bool = ...,
) -> None:
...
) -> None: ...

0 comments on commit fb02009

Please sign in to comment.