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 style #1040

Merged
merged 5 commits into from
Nov 13, 2023
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 backend/scripts/update_licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def download_data(url):
try:
response = httpx.get(url)
response.raise_for_status()
except Exception:
except Exception: # noqa: BLE001
time.sleep(1)
continue
else:
Expand Down
33 changes: 22 additions & 11 deletions backend/src/hatchling/bridge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,40 @@ def __init__(self) -> None:
def verbosity(self) -> int:
return self.__verbosity

def display(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display(*args: Any, **kwargs: Any) -> None:
send_app_command('display', *args, **kwargs)

def display_info(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_info(*args: Any, **kwargs: Any) -> None:
send_app_command('display_info', *args, **kwargs)

def display_waiting(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_waiting(*args: Any, **kwargs: Any) -> None:
send_app_command('display_waiting', *args, **kwargs)

def display_success(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_success(*args: Any, **kwargs: Any) -> None:
send_app_command('display_success', *args, **kwargs)

def display_warning(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_warning(*args: Any, **kwargs: Any) -> None:
send_app_command('display_warning', *args, **kwargs)

def display_error(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_error(*args: Any, **kwargs: Any) -> None:
send_app_command('display_error', *args, **kwargs)

def display_debug(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_debug(*args: Any, **kwargs: Any) -> None:
send_app_command('display_debug', *args, **kwargs)

def display_mini_header(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def display_mini_header(*args: Any, **kwargs: Any) -> None:
send_app_command('display_mini_header', *args, **kwargs)

def abort(self, *args: Any, **kwargs: Any) -> None:
@staticmethod
def abort(*args: Any, **kwargs: Any) -> None:
send_app_command('abort', *args, **kwargs)
sys.exit(kwargs.get('code', 1))

Expand All @@ -65,7 +74,8 @@ def verbosity(self) -> int:
"""
return self.__verbosity

def display(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
@staticmethod
def display(message: str = '', **kwargs: Any) -> None: # noqa: ARG004
# Do not document
print(message)

Expand Down Expand Up @@ -112,7 +122,8 @@ def display_debug(self, message: str = '', level: int = 1, **kwargs: Any) -> Non
if not 1 <= level <= 3: # noqa: PLR2004
error_message = 'Debug output can only have verbosity levels between 1 and 3 (inclusive)'
raise ValueError(error_message)
elif self.__verbosity >= level:

if self.__verbosity >= level:
print(message)

def display_mini_header(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
Expand Down
5 changes: 2 additions & 3 deletions backend/src/hatchling/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'get_requires_for_build_sdist',
'get_requires_for_build_wheel',
]
__all__.append('__all__')
__all__ += ['__all__']


def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]: # noqa: ARG001
Expand Down Expand Up @@ -95,8 +95,7 @@ def build_editable(
# See: https://github.com/pypa/pip/blob/22.2.2/src/pip/_internal/operations/build/build_tracker.py#L41-L51
# Example use case: https://github.com/pypa/hatch/issues/532
if 'PIP_BUILD_TRACKER' not in os.environ:
__all__.append('prepare_metadata_for_build_editable')
__all__.append('prepare_metadata_for_build_wheel')
__all__ += ['prepare_metadata_for_build_editable', 'prepare_metadata_for_build_wheel']

def prepare_metadata_for_build_wheel(
metadata_directory: str,
Expand Down
9 changes: 5 additions & 4 deletions backend/src/hatchling/builders/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def scripts(self) -> list[str]:
f'Script #{i} of field `tool.hatch.build.targets.{self.plugin_name}.scripts` must be a string'
)
raise TypeError(message)
elif script not in known_scripts:

if script not in known_scripts:
message = f'Unknown script in field `tool.hatch.build.targets.{self.plugin_name}.scripts`: {script}'
raise ValueError(message)

Expand Down Expand Up @@ -88,11 +89,11 @@ class AppBuilder(BuilderInterface):
def get_version_api(self) -> dict[str, Callable]:
return {'bootstrap': self.build_bootstrap}

def get_default_versions(self) -> list[str]:
def get_default_versions(self) -> list[str]: # noqa: PLR6301
return ['bootstrap']

def clean(
self,
self, # noqa: PLR6301
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
Expand Down Expand Up @@ -188,7 +189,7 @@ def cargo_build(self, *args: Any, **kwargs: Any) -> None:
kwargs['stdout'] = subprocess.PIPE
kwargs['stderr'] = subprocess.STDOUT

process = subprocess.run(*args, **kwargs)
process = subprocess.run(*args, **kwargs) # noqa: PLW1510
if process.returncode:
message = f'Compilation of failed (code {process.returncode})'
if not self.app.verbosity:
Expand Down
81 changes: 48 additions & 33 deletions backend/src/hatchling/builders/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ def include_spec(self) -> pathspec.GitIgnoreSpec | None:
if not isinstance(include_pattern, str):
message = f'Pattern #{i} in field `{include_location}` must be a string'
raise TypeError(message)
elif not include_pattern:

if not include_pattern:
message = f'Pattern #{i} in field `{include_location}` cannot be an empty string'
raise ValueError(message)

all_include_patterns.append(include_pattern)

for relative_path in self.packages:
# Matching only at the root requires a forward slash, back slashes do not work. As such,
# normalize to forward slashes for consistency.
all_include_patterns.append(f"/{relative_path.replace(os.sep, '/')}/")
# Matching only at the root requires a forward slash, back slashes do not work. As such,
# normalize to forward slashes for consistency.
all_include_patterns.extend(f"/{relative_path.replace(os.sep, '/')}/" for relative_path in self.packages)

if all_include_patterns:
self.__include_spec = pathspec.GitIgnoreSpec.from_lines(all_include_patterns)
Expand Down Expand Up @@ -194,7 +194,8 @@ def exclude_spec(self) -> pathspec.GitIgnoreSpec | None:
if not isinstance(exclude_pattern, str):
message = f'Pattern #{i} in field `{exclude_location}` must be a string'
raise TypeError(message)
elif not exclude_pattern:

if not exclude_pattern:
message = f'Pattern #{i} in field `{exclude_location}` cannot be an empty string'
raise ValueError(message)

Expand Down Expand Up @@ -231,7 +232,8 @@ def artifact_spec(self) -> pathspec.GitIgnoreSpec | None:
if not isinstance(artifact_pattern, str):
message = f'Pattern #{i} in field `{artifact_location}` must be a string'
raise TypeError(message)
elif not artifact_pattern:

if not artifact_pattern:
message = f'Pattern #{i} in field `{artifact_location}` cannot be an empty string'
raise ValueError(message)

Expand Down Expand Up @@ -381,15 +383,16 @@ def require_runtime_features(self) -> list[str]:
raise TypeError(message)

all_features: dict[str, None] = {}
for i, feature in enumerate(require_runtime_features, 1):
if not isinstance(feature, str):
for i, raw_feature in enumerate(require_runtime_features, 1):
if not isinstance(raw_feature, str):
message = f'Feature #{i} of field `{features_location}` must be a string'
raise TypeError(message)
elif not feature:

if not raw_feature:
message = f'Feature #{i} of field `{features_location}` cannot be an empty string'
raise ValueError(message)

feature = normalize_project_name(feature)
feature = normalize_project_name(raw_feature)
if feature not in self.builder.metadata.core.optional_dependencies:
message = (
f'Feature `{feature}` of field `{features_location}` is not defined in '
Expand Down Expand Up @@ -470,7 +473,8 @@ def dev_mode_dirs(self) -> list[str]:
if not isinstance(dev_mode_dir, str):
message = f'Directory #{i} in field `{dev_mode_dirs_location}` must be a string'
raise TypeError(message)
elif not dev_mode_dir:

if not dev_mode_dir:
message = f'Directory #{i} in field `{dev_mode_dirs_location}` cannot be an empty string'
raise ValueError(message)

Expand Down Expand Up @@ -515,7 +519,8 @@ def versions(self) -> list[str]:
f'Version #{i} in field `tool.hatch.build.targets.{self.plugin_name}.versions` must be a string'
)
raise TypeError(message)
elif not version:

if not version:
message = (
f'Version #{i} in field `tool.hatch.build.targets.{self.plugin_name}.versions` '
f'cannot be an empty string'
Expand Down Expand Up @@ -581,29 +586,31 @@ def dependencies(self) -> list[str]:
if not isinstance(hook_require_runtime_dependencies, bool):
message = f'Option `require-runtime-dependencies` of build hook `{hook_name}` must be a boolean'
raise TypeError(message)
elif hook_require_runtime_dependencies:

if hook_require_runtime_dependencies:
require_runtime_dependencies = True

hook_require_runtime_features = config.get('require-runtime-features', [])
if not isinstance(hook_require_runtime_features, list):
message = f'Option `require-runtime-features` of build hook `{hook_name}` must be an array'
raise TypeError(message)

for i, feature in enumerate(hook_require_runtime_features, 1):
if not isinstance(feature, str):
for i, raw_feature in enumerate(hook_require_runtime_features, 1):
if not isinstance(raw_feature, str):
message = (
f'Feature #{i} of option `require-runtime-features` of build hook `{hook_name}` '
f'must be a string'
)
raise TypeError(message)
elif not feature:

if not raw_feature:
message = (
f'Feature #{i} of option `require-runtime-features` of build hook `{hook_name}` '
f'cannot be an empty string'
)
raise ValueError(message)

feature = normalize_project_name(feature)
feature = normalize_project_name(raw_feature)
if feature not in self.builder.metadata.core.optional_dependencies:
message = (
f'Feature `{feature}` of option `require-runtime-features` of build hook `{hook_name}` '
Expand Down Expand Up @@ -658,7 +665,8 @@ def sources(self) -> dict[str, str]:
if not isinstance(source, str):
message = f'Source #{i} in field `{sources_location}` must be a string'
raise TypeError(message)
elif not source:

if not source:
message = f'Source #{i} in field `{sources_location}` cannot be an empty string'
raise ValueError(message)

Expand All @@ -668,7 +676,8 @@ def sources(self) -> dict[str, str]:
if not source:
message = f'Source #{i} in field `{sources_location}` cannot be an empty string'
raise ValueError(message)
elif not isinstance(path, str):

if not isinstance(path, str):
message = f'Path for source `{source}` in field `{sources_location}` must be a string'
raise TypeError(message)

Expand Down Expand Up @@ -711,7 +720,8 @@ def packages(self) -> list[str]:
if not isinstance(package, str):
message = f'Package #{i} in field `{package_location}` must be a string'
raise TypeError(message)
elif not package:

if not package:
message = f'Package #{i} in field `{package_location}` cannot be an empty string'
raise ValueError(message)

Expand All @@ -738,10 +748,12 @@ def force_include(self) -> dict[str, str]:
if not source:
message = f'Source #{i} in field `{force_include_location}` cannot be an empty string'
raise ValueError(message)
elif not isinstance(relative_path, str):

if not isinstance(relative_path, str):
message = f'Path for source `{source}` in field `{force_include_location}` must be a string'
raise TypeError(message)
elif not relative_path:

if not relative_path:
message = (
f'Path for source `{source}` in field `{force_include_location}` cannot be an empty string'
)
Expand Down Expand Up @@ -777,7 +789,8 @@ def only_include(self) -> dict[str, str]:
if not normalized_path or normalized_path.startswith(('~', '..')):
message = f'Path #{i} in field `{only_include_location}` must be relative: {relative_path}'
raise ValueError(message)
elif normalized_path in inclusion_map:

if normalized_path in inclusion_map:
message = f'Duplicate path in field `{only_include_location}`: {normalized_path}'
raise ValueError(message)

Expand Down Expand Up @@ -829,10 +842,12 @@ def load_vcs_exclusion_patterns(self) -> list[str]:
if exact_line == 'syntax: glob':
glob_mode = True
continue
elif exact_line.startswith('syntax: '):

if exact_line.startswith('syntax: '):
glob_mode = False
continue
elif glob_mode:

if glob_mode:
patterns.append(line)

return patterns
Expand All @@ -843,19 +858,19 @@ def normalize_build_directory(self, build_directory: str) -> str:

return os.path.normpath(build_directory)

def default_include(self) -> list:
def default_include(self) -> list: # noqa: PLR6301
return []

def default_exclude(self) -> list:
def default_exclude(self) -> list: # noqa: PLR6301
return []

def default_packages(self) -> list:
def default_packages(self) -> list: # noqa: PLR6301
return []

def default_only_include(self) -> list:
def default_only_include(self) -> list: # noqa: PLR6301
return []

def default_global_exclude(self) -> list[str]:
def default_global_exclude(self) -> list[str]: # noqa: PLR6301
patterns = ['*.py[cdo]', f'/{DEFAULT_BUILD_DIRECTORY}']
patterns.sort()
return patterns
Expand Down Expand Up @@ -897,8 +912,8 @@ def set_build_data(self, build_data: dict[str, Any]) -> Generator:
def env_var_enabled(env_var: str, *, default: bool = False) -> bool:
if env_var in os.environ:
return os.environ[env_var] in ('1', 'true')
else:
return default

return default


BuilderConfigBound = TypeVar('BuilderConfigBound', bound=BuilderConfig)
3 changes: 2 additions & 1 deletion backend/src/hatchling/builders/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def __new__( # type: ignore
if not isinstance(build_script, str):
message = f'Option `path` for builder `{cls.PLUGIN_NAME}` must be a string'
raise TypeError(message)
elif not build_script:

if not build_script:
message = f'Option `path` for builder `{cls.PLUGIN_NAME}` must not be empty if defined'
raise ValueError(message)

Expand Down
3 changes: 2 additions & 1 deletion backend/src/hatchling/builders/hooks/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def __new__( # type: ignore
if not isinstance(build_script, str):
message = f'Option `path` for build hook `{cls.PLUGIN_NAME}` must be a string'
raise TypeError(message)
elif not build_script:

if not build_script:
message = f'Option `path` for build hook `{cls.PLUGIN_NAME}` must not be empty if defined'
raise ValueError(message)

Expand Down
3 changes: 2 additions & 1 deletion backend/src/hatchling/builders/hooks/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def config_path(self) -> str:
if not isinstance(path, str):
message = f'Option `path` for build hook `{self.PLUGIN_NAME}` must be a string'
raise TypeError(message)
elif not path:

if not path:
message = f'Option `path` for build hook `{self.PLUGIN_NAME}` is required'
raise ValueError(message)

Expand Down
Loading