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

Fix Ruff file exclusion #1088

Merged
merged 1 commit into from
Dec 5, 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/src/hatchling/cli/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def build_impl(
app.display_info(artifact)


def build_command(subparsers: argparse._SubParsersAction, defaults: Any) -> None:
def build_command(subparsers: argparse._SubParsersAction, defaults: Any) -> None: # noqa: SLF001
parser = subparsers.add_parser('build')
parser.add_argument(
'-d', '--directory', dest='directory', help='The directory in which to build artifacts', **defaults
Expand Down
3 changes: 3 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extend = "ruff_defaults.toml"

# https://github.com/astral-sh/ruff/issues/8627
exclude = [".git", ".mypy_cache", ".ruff_cache", ".venv", "dist"]

[lint]
preview = true
ignore = [
Expand Down
14 changes: 5 additions & 9 deletions src/hatch/cli/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ def build(app: Application, location, targets, hooks_only, no_hooks, ext, clean,
"""Build a project."""
app.ensure_environment_plugin_dependencies()

from hatchling.builders.constants import BuildEnvVars
from hatchling.builders.plugin.interface import BuilderInterface

from hatch.config.constants import AppEnvVars
from hatch.utils.fs import Path
from hatch.utils.structures import EnvVars
from hatchling.builders.constants import BuildEnvVars
from hatchling.builders.plugin.interface import BuilderInterface

if location:
path = str(Path(location).resolve())
else:
path = None
path = str(Path(location).resolve()) if location else None

if ext:
hooks_only = True
Expand Down Expand Up @@ -93,14 +89,14 @@ def build(app: Application, location, targets, hooks_only, no_hooks, ext, clean,
env_vars[AppEnvVars.QUIET] = str(abs(app.verbosity))

class Builder(BuilderInterface):
def get_version_api(self):
def get_version_api(self): # noqa: PLR6301
return {}

with app.project.location.as_cwd(env_vars):
environment = app.get_environment()
try:
environment.check_compatibility()
except Exception as e:
except Exception as e: # noqa: BLE001
app.abort(f'Environment `{environment.name}` is incompatible: {e}')

for target in targets:
Expand Down
11 changes: 7 additions & 4 deletions src/hatch/venv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def deactivate(self):

self._env_vars_to_restore.clear()

def create(self, python, allow_system_packages=False):
def create(self, python, *, allow_system_packages=False):
# WARNING: extremely slow import
from virtualenv import cli_run

Expand Down Expand Up @@ -76,16 +76,19 @@ def executables_directory(self):
if exe_dir.is_dir():
self._executables_directory = exe_dir
else:
raise OSError(f'Unable to locate executables directory within: {self.directory}')
msg = f'Unable to locate executables directory within: {self.directory}'
raise OSError(msg)
# Debian
elif (self.directory / 'local').is_dir(): # no cov
exe_dir = self.directory / 'local' / 'bin'
if exe_dir.is_dir():
self._executables_directory = exe_dir
else:
raise OSError(f'Unable to locate executables directory within: {self.directory}')
msg = f'Unable to locate executables directory within: {self.directory}'
raise OSError(msg)
else:
raise OSError(f'Unable to locate executables directory within: {self.directory}')
msg = f'Unable to locate executables directory within: {self.directory}'
raise OSError(msg)

return self._executables_directory

Expand Down
46 changes: 23 additions & 23 deletions tests/cli/build/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@ def test_legacy(self, hatch, temp_dir, helpers):
data_path.mkdir()

(path / 'pyproject.toml').write_text(
"""\
"""\
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
"""
)
(path / 'setup.py').write_text(
"""\
"""\
import setuptools
setuptools.setup(name="tmp", version="0.0.1")
"""
)
(path / 'tmp.py').write_text(
"""\
"""\
print("Hello World!")
"""
)
Expand Down Expand Up @@ -208,8 +208,8 @@ def test_default(hatch, temp_dir, helpers):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 2

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -243,7 +243,7 @@ def test_explicit_targets(hatch, temp_dir, helpers):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 1

wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -273,8 +273,8 @@ def test_explicit_directory(hatch, temp_dir, helpers):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 2

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -307,8 +307,8 @@ def test_explicit_directory_env_var(hatch, temp_dir, helpers):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 2

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -389,10 +389,10 @@ def initialize(self, version, build_data):
assert len(artifacts) == 3
assert test_file in artifacts

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
assert '9000' in str(sdist_path)

wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))
assert '9000' in str(wheel_path)

assert result.output == helpers.dedent(
Expand Down Expand Up @@ -446,10 +446,10 @@ def test_clean_env_var(hatch, temp_dir, helpers):
assert len(artifacts) == 3
assert test_file in artifacts

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
assert '9000' in str(sdist_path)

wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))
assert '9000' in str(wheel_path)

assert result.output == helpers.dedent(
Expand Down Expand Up @@ -646,8 +646,8 @@ def initialize(self, version, build_data):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 2

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -709,8 +709,8 @@ def initialize(self, version, build_data):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 2

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -998,7 +998,7 @@ def initialize(self, version, build_data):
assert len(artifacts) == 1
assert not (path / 'my_app' / 'lib.so').exists()

wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def initialize(self, version, build_data):
assert len(artifacts) == 1
assert not (path / 'my_app' / 'lib.so').exists()

wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def test_debug_verbosity(hatch, temp_dir, helpers):
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 1

wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down Expand Up @@ -1253,8 +1253,8 @@ def test_plugin_dependencies_unmet(hatch, temp_dir, helpers, mock_plugin_install
artifacts = list(build_directory.iterdir())
assert len(artifacts) == 2

sdist_path = [artifact for artifact in artifacts if artifact.name.endswith('.tar.gz')][0]
wheel_path = [artifact for artifact in artifacts if artifact.name.endswith('.whl')][0]
sdist_path = next(artifact for artifact in artifacts if artifact.name.endswith('.tar.gz'))
wheel_path = next(artifact for artifact in artifacts if artifact.name.endswith('.whl'))

assert result.output == helpers.dedent(
f"""
Expand Down
3 changes: 2 additions & 1 deletion tests/venv/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def test_executables_directory(temp_dir, platform):
if entry.name.startswith('py'):
break
else: # no cov
raise AssertionError('Unable to locate Python executable')
msg = 'Unable to locate Python executable'
raise AssertionError(msg)


def test_activation(temp_dir, platform):
Expand Down