Skip to content

Commit

Permalink
Update style (#1031)
Browse files Browse the repository at this point in the history
* Update style

* .

* .

* .
  • Loading branch information
ofek authored Nov 6, 2023
1 parent dc3b0bd commit 9c2f74b
Show file tree
Hide file tree
Showing 43 changed files with 212 additions and 107 deletions.
18 changes: 9 additions & 9 deletions backend/src/hatchling/bridge/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,46 @@ def verbosity(self) -> int:
"""
return self.__verbosity

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

def display_info(self, message: str = '', **kwargs: Any) -> None:
def display_info(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
"""
Meant to be used for messages conveying basic information.
"""
if self.__verbosity >= 0:
print(message)

def display_waiting(self, message: str = '', **kwargs: Any) -> None:
def display_waiting(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
"""
Meant to be used for messages shown before potentially time consuming operations.
"""
if self.__verbosity >= 0:
print(message)

def display_success(self, message: str = '', **kwargs: Any) -> None:
def display_success(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
"""
Meant to be used for messages indicating some positive outcome.
"""
if self.__verbosity >= 0:
print(message)

def display_warning(self, message: str = '', **kwargs: Any) -> None:
def display_warning(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
"""
Meant to be used for messages conveying important information.
"""
if self.__verbosity >= -1:
print(message)

def display_error(self, message: str = '', **kwargs: Any) -> None:
def display_error(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
"""
Meant to be used for messages indicating some unrecoverable error.
"""
if self.__verbosity >= -2: # noqa: PLR2004
print(message)

def display_debug(self, message: str = '', level: int = 1, **kwargs: Any) -> None:
def display_debug(self, message: str = '', level: int = 1, **kwargs: Any) -> None: # noqa: ARG002
"""
Meant to be used for messages that are not useful for most user experiences.
The `level` option must be between 1 and 3 (inclusive).
Expand All @@ -115,11 +115,11 @@ def display_debug(self, message: str = '', level: int = 1, **kwargs: Any) -> Non
elif self.__verbosity >= level:
print(message)

def display_mini_header(self, message: str = '', **kwargs: Any) -> None:
def display_mini_header(self, message: str = '', **kwargs: Any) -> None: # noqa: ARG002
if self.__verbosity >= 0:
print(f'[{message}]')

def abort(self, message: str = '', code: int = 1, **kwargs: Any) -> None:
def abort(self, message: str = '', code: int = 1, **kwargs: Any) -> None: # noqa: ARG002
"""
Terminate the program with the given return code.
"""
Expand Down
24 changes: 16 additions & 8 deletions backend/src/hatchling/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
__all__.append('__all__')


def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]:
def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]: # noqa: ARG001
"""
https://peps.python.org/pep-0517/#get-requires-for-build-sdist
"""
Expand All @@ -24,7 +24,7 @@ def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None)
return builder.config.dependencies


def build_sdist(sdist_directory: str, config_settings: dict[str, Any] | None = None) -> str:
def build_sdist(sdist_directory: str, config_settings: dict[str, Any] | None = None) -> str: # noqa: ARG001
"""
https://peps.python.org/pep-0517/#build-sdist
"""
Expand All @@ -34,7 +34,7 @@ def build_sdist(sdist_directory: str, config_settings: dict[str, Any] | None = N
return os.path.basename(next(builder.build(sdist_directory, ['standard'])))


def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]:
def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]: # noqa: ARG001
"""
https://peps.python.org/pep-0517/#get-requires-for-build-wheel
"""
Expand All @@ -45,7 +45,9 @@ def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None)


def build_wheel(
wheel_directory: str, config_settings: dict[str, Any] | None = None, metadata_directory: str | None = None
wheel_directory: str,
config_settings: dict[str, Any] | None = None, # noqa: ARG001
metadata_directory: str | None = None, # noqa: ARG001
) -> str:
"""
https://peps.python.org/pep-0517/#build-wheel
Expand All @@ -56,7 +58,7 @@ def build_wheel(
return os.path.basename(next(builder.build(wheel_directory, ['standard'])))


def get_requires_for_build_editable(config_settings: dict[str, Any] | None = None) -> list[str]:
def get_requires_for_build_editable(config_settings: dict[str, Any] | None = None) -> list[str]: # noqa: ARG001
"""
https://peps.python.org/pep-0660/#get-requires-for-build-editable
"""
Expand All @@ -67,7 +69,9 @@ def get_requires_for_build_editable(config_settings: dict[str, Any] | None = Non


def build_editable(
wheel_directory: str, config_settings: dict[str, Any] | None = None, metadata_directory: str | None = None
wheel_directory: str,
config_settings: dict[str, Any] | None = None, # noqa: ARG001
metadata_directory: str | None = None, # noqa: ARG001
) -> str:
"""
https://peps.python.org/pep-0660/#build-editable
Expand All @@ -94,7 +98,10 @@ def build_editable(
__all__.append('prepare_metadata_for_build_editable')
__all__.append('prepare_metadata_for_build_wheel')

def prepare_metadata_for_build_wheel(metadata_directory: str, config_settings: dict[str, Any] | None = None) -> str:
def prepare_metadata_for_build_wheel(
metadata_directory: str,
config_settings: dict[str, Any] | None = None, # noqa: ARG001
) -> str:
"""
https://peps.python.org/pep-0517/#prepare-metadata-for-build-wheel
"""
Expand All @@ -112,7 +119,8 @@ def prepare_metadata_for_build_wheel(metadata_directory: str, config_settings: d
return os.path.basename(directory)

def prepare_metadata_for_build_editable(
metadata_directory: str, config_settings: dict[str, Any] | None = None
metadata_directory: str,
config_settings: dict[str, Any] | None = None, # noqa: ARG001
) -> str:
"""
https://peps.python.org/pep-0660/#prepare-metadata-for-build-editable
Expand Down
12 changes: 10 additions & 2 deletions backend/src/hatchling/builders/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,22 @@ def get_version_api(self) -> dict[str, Callable]:
def get_default_versions(self) -> list[str]:
return ['bootstrap']

def clean(self, directory: str, versions: list[str]) -> None:
def clean(
self,
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
import shutil

app_dir = os.path.join(directory, 'app')
if os.path.isdir(app_dir):
shutil.rmtree(app_dir)

def build_bootstrap(self, directory: str, **build_data: Any) -> str:
def build_bootstrap(
self,
directory: str,
**build_data: Any, # noqa: ARG002
) -> str:
import shutil
import tempfile

Expand Down
6 changes: 5 additions & 1 deletion backend/src/hatchling/builders/hooks/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def config_pattern(self) -> str | bool:

return self.__config_pattern

def initialize(self, version: str, build_data: dict[str, Any]) -> None:
def initialize(
self,
version: str, # noqa: ARG002
build_data: dict[str, Any],
) -> None:
version_file = VersionFile(self.root, self.config_path)
if self.config_pattern:
version_file.read(self.config_pattern)
Expand Down
6 changes: 5 additions & 1 deletion backend/src/hatchling/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def get_version_api(self) -> dict[str, Callable]:
def get_default_versions(self) -> list[str]:
return ['standard']

def clean(self, directory: str, versions: list[str]) -> None:
def clean(
self,
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
for filename in os.listdir(directory):
if filename.endswith('.tar.gz'):
os.remove(os.path.join(directory, filename))
Expand Down
6 changes: 5 additions & 1 deletion backend/src/hatchling/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ def get_version_api(self) -> dict[str, Callable]:
def get_default_versions(self) -> list[str]:
return ['standard']

def clean(self, directory: str, versions: list[str]) -> None:
def clean(
self,
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
for filename in os.listdir(directory):
if filename.endswith('.whl'):
os.remove(os.path.join(directory, filename))
Expand Down
5 changes: 4 additions & 1 deletion backend/src/hatchling/cli/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def metadata_impl(*, called_by_app: bool, field: str, compact: bool) -> None:
app.display(json.dumps(metadata, indent=4))


def metadata_command(subparsers: argparse._SubParsersAction, defaults: Any) -> None:
def metadata_command(
subparsers: argparse._SubParsersAction,
defaults: Any, # noqa: ARG001
) -> None:
parser = subparsers.add_parser('metadata')
parser.add_argument('field', nargs='?')
parser.add_argument('-c', '--compact', action='store_true')
Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/licenses/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def normalize_license_expression(raw_license_expression: str) -> str:
for token in tokens:
if token not in ('or', 'and', 'with', '(', ')'):
python_tokens.append('False')
elif token == 'with':
elif token == 'with': # noqa: S105
python_tokens.append('or')
elif token == '(' and python_tokens and python_tokens[-1] not in ('or', 'and'):
elif token == '(' and python_tokens and python_tokens[-1] not in ('or', 'and'): # noqa: S105
message = f'invalid license expression: {raw_license_expression}'
raise ValueError(message)
else:
Expand Down
10 changes: 7 additions & 3 deletions backend/src/hatchling/ouroboros.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ def read_dependencies() -> list[str]:
return literal_eval(match.group(1))


def get_requires_for_build_sdist(config_settings: dict[str, Any] | None = None) -> list[str]: # type: ignore[no-redef]
def get_requires_for_build_sdist( # type: ignore[no-redef]
config_settings: dict[str, Any] | None = None # noqa: ARG001
) -> list[str]:
"""
https://peps.python.org/pep-0517/#get-requires-for-build-sdist
"""
return read_dependencies()


def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]: # type: ignore[no-redef]
def get_requires_for_build_wheel( # type: ignore[no-redef]
config_settings: dict[str, Any] | None = None # noqa: ARG001
) -> list[str]:
"""
https://peps.python.org/pep-0517/#get-requires-for-build-wheel
"""
return read_dependencies()


def get_requires_for_build_editable( # type: ignore[no-redef]
config_settings: dict[str, Any] | None = None
config_settings: dict[str, Any] | None = None # noqa: ARG001
) -> list[str]:
"""
https://peps.python.org/pep-0660/#get-requires-for-build-editable
Expand Down
10 changes: 5 additions & 5 deletions backend/src/hatchling/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def get_formatters(self) -> MutableMapping:
'root': self.__format_root,
}

def __format_directory_separator(self, value: str, data: str) -> str:
def __format_directory_separator(self, value: str, data: str) -> str: # noqa: ARG002
return os.sep

def __format_path_separator(self, value: str, data: str) -> str:
def __format_path_separator(self, value: str, data: str) -> str: # noqa: ARG002
return os.pathsep

def __format_root(self, value: str, data: str) -> str:
def __format_root(self, value: str, data: str) -> str: # noqa: ARG002
return self.format_path(self.__root, data)

def __format_home(self, value: str, data: str) -> str:
def __format_home(self, value: str, data: str) -> str: # noqa: ARG002
return self.format_path(os.path.expanduser('~'), data)

def __format_env(self, value: str, data: str) -> str:
def __format_env(self, value: str, data: str) -> str: # noqa: ARG002
if not data:
message = 'The `env` context formatting field requires a modifier'
raise ValueError(message)
Expand Down
7 changes: 6 additions & 1 deletion backend/src/hatchling/version/scheme/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class StandardScheme(VersionSchemeInterface):

PLUGIN_NAME = 'standard'

def update(self, desired_version: str, original_version: str, version_data: dict) -> str:
def update(
self,
desired_version: str,
original_version: str,
version_data: dict, # noqa: ARG002
) -> str:
from packaging.version import Version

original = Version(original_version)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/version/source/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ def get_version_data(self) -> dict:

return {'version': version}

def set_version(self, version: str, version_data: dict) -> None:
def set_version(self, version: str, version_data: dict) -> None: # noqa: ARG002
message = 'Cannot rewrite loaded code'
raise NotImplementedError(message)
2 changes: 1 addition & 1 deletion backend/src/hatchling/version/source/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def get_version_data(self) -> dict:

return {'version': os.environ[variable]}

def set_version(self, version: str, version_data: dict) -> None:
def set_version(self, version: str, version_data: dict) -> None: # noqa: ARG002
message = 'Cannot set environment variables'
raise NotImplementedError(message)
5 changes: 4 additions & 1 deletion docs/.hooks/expand_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def _config_example_replace(m):
"""


def on_config(config, **kwargs):
def on_config(
config,
**kwargs, # noqa: ARG001
):
config.markdown_extensions.append(MyExtension())


Expand Down
5 changes: 4 additions & 1 deletion docs/.hooks/inject_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def get_latest_version():
return f'{major}.{minor}.{patch}'


def on_page_read_source(page, config):
def on_page_read_source(
page,
config, # noqa: ARG001
):
with open(page.file.abs_src_path, encoding='utf-8') as f:
return f.read().replace(MARKER, get_latest_version())
2 changes: 1 addition & 1 deletion docs/history/hatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
***Added:***

- Support Python 3.12
- Add standalone binaries
- Add installers and standalone binaries
- Add the ability to manage Python installations
- The `virtual` environment type can now automatically download requested versions of Python that are not installed
- Add `dependency_hash` method to the `environment` interface
Expand Down
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ skip-string-normalization = true
line-length = 120
select = [
"A",
"ARG",
"B",
"C",
"DTZ",
Expand Down Expand Up @@ -123,13 +124,9 @@ ignore = [
"B027",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
# Ignore complexity
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
"PLC1901", # empty string comparisons
"PLW2901", # `for` loop variable overwritten
"SIM114", # Combine `if` branches using logical `or` operator
]
unfixable = [
# Don't touch unused imports
Expand All @@ -150,8 +147,8 @@ ban-relative-imports = "all"
"backend/src/hatchling/bridge/app.py" = ["T201"]
"backend/tests/downstream/integrate.py" = ["T201"]
"scripts/*" = ["T201"]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]
# Tests can use empty string comparisons, magic values, assertions, and relative imports
"tests/**/*" = ["PLC1901", "PLR2004", "S101", "TID252"]

[tool.mypy]
disallow_untyped_defs = false
Expand Down
Loading

0 comments on commit 9c2f74b

Please sign in to comment.