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

Upgrade Ruff #1085

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
42 changes: 20 additions & 22 deletions backend/src/hatchling/builders/constants.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
DEFAULT_BUILD_DIRECTORY = 'dist'

EXCLUDED_DIRECTORIES = frozenset(
(
# Python bytecode
'__pycache__',
# Git
'.git',
# Mercurial
'.hg',
# Hatch
'.hatch',
# tox
'.tox',
# nox
'.nox',
# Ruff
'.ruff_cache',
# pytest
'.pytest_cache',
# Mypy
'.mypy_cache',
)
)
EXCLUDED_DIRECTORIES = frozenset((
# Python bytecode
'__pycache__',
# Git
'.git',
# Mercurial
'.hg',
# Hatch
'.hatch',
# tox
'.tox',
# nox
'.nox',
# Ruff
'.ruff_cache',
# pytest
'.pytest_cache',
# Mypy
'.mypy_cache',
))


class BuildEnvVars:
Expand Down
68 changes: 31 additions & 37 deletions backend/tests/downstream/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,18 @@ def main():

print('<<<<< Building backend >>>>>')
subprocess.check_call([sys.executable, '-m', 'build', '--wheel', '-o', links_dir, backend_path])
subprocess.check_call(
[
sys.executable,
'-m',
'pip',
'download',
'-q',
'--disable-pip-version-check',
'--no-python-version-warning',
'-d',
links_dir,
os.path.join(links_dir, os.listdir(links_dir)[0]),
]
)
subprocess.check_call([
sys.executable,
'-m',
'pip',
'download',
'-q',
'--disable-pip-version-check',
'--no-python-version-warning',
'-d',
links_dir,
os.path.join(links_dir, os.listdir(links_dir)[0]),
])

constraints = []
constraints_file = os.path.join(build_dir, 'constraints.txt')
Expand Down Expand Up @@ -227,31 +225,27 @@ def main():
env_vars['PIP_CONSTRAINT'] = constraints_file
with EnvVars(env_vars, ignore=('__PYVENV_LAUNCHER__', 'PYTHONHOME')):
print('--> Installing project')
subprocess.check_call(
[
shutil.which('pip'),
'install',
'-q',
'--disable-pip-version-check',
'--no-python-version-warning',
'--find-links',
links_dir,
'--no-deps',
repo_dir,
]
)
subprocess.check_call([
shutil.which('pip'),
'install',
'-q',
'--disable-pip-version-check',
'--no-python-version-warning',
'--find-links',
links_dir,
'--no-deps',
repo_dir,
])

print('--> Installing dependencies')
subprocess.check_call(
[
shutil.which('pip'),
'install',
'-q',
'--disable-pip-version-check',
'--no-python-version-warning',
repo_dir,
]
)
subprocess.check_call([
shutil.which('pip'),
'install',
'-q',
'--disable-pip-version-check',
'--no-python-version-warning',
repo_dir,
])

print('--> Testing package')
for statement in test_data['statements']:
Expand Down
48 changes: 22 additions & 26 deletions release/macos/build_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,34 @@ def main():
components_dir = temp_dir / 'components'
components_dir.mkdir()

run_command(
[
'pkgbuild',
'--root',
str(root_dir),
'--identifier',
IDENTIFIER,
'--version',
version,
'--install-location',
'/',
str(components_dir / COMPONENT_PACKAGE_NAME),
]
)
run_command([
'pkgbuild',
'--root',
str(root_dir),
'--identifier',
IDENTIFIER,
'--version',
version,
'--install-location',
'/',
str(components_dir / COMPONENT_PACKAGE_NAME),
])

# This is where we build the final artifact
build_dir = temp_dir / 'build'
build_dir.mkdir()
product_archive = build_dir / f'{binary_name}-{version}.pkg'

run_command(
[
'productbuild',
'--distribution',
str(ASSETS_DIR / 'distribution.xml'),
'--resources',
str(resources_dir),
'--package-path',
str(components_dir),
str(product_archive),
]
)
run_command([
'productbuild',
'--distribution',
str(ASSETS_DIR / 'distribution.xml'),
'--resources',
str(resources_dir),
'--package-path',
str(components_dir),
str(product_archive),
])

# Copy the final artifact to the target directory
directory.mkdir(parents=True, exist_ok=True)
Expand Down
8 changes: 8 additions & 0 deletions ruff_defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ select = [
"FURB145",
"FURB148",
"FURB152",
"FURB163",
"FURB168",
"FURB169",
"FURB171",
Expand Down Expand Up @@ -269,6 +270,7 @@ select = [
"PLE0604",
"PLE0605",
"PLE0704",
"PLE1132",
"PLE1142",
"PLE1205",
"PLE1206",
Expand All @@ -285,6 +287,8 @@ select = [
"PLE2515",
"PLR0124",
"PLR0133",
"PLR0202",
"PLR0203",
"PLR0206",
"PLR0402",
"PLR1701",
Expand All @@ -293,6 +297,8 @@ select = [
"PLR1711",
"PLR1714",
"PLR1722",
"PLR1733",
"PLR1736",
"PLR2004",
"PLR5501",
"PLR6201",
Expand Down Expand Up @@ -427,6 +433,7 @@ select = [
"S112",
"S113",
"S201",
"S202",
"S301",
"S302",
"S303",
Expand Down Expand Up @@ -463,6 +470,7 @@ select = [
"S607",
"S608",
"S609",
"S611",
"S612",
"S701",
"S702",
Expand Down
12 changes: 5 additions & 7 deletions scripts/release_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ def main():

version, notes = get_latest_release(args.project)

params = urlencode(
{
'title': f'{args.project.capitalize()} v{version}',
'tag': f'{args.project}-v{version}',
'body': notes,
}
)
params = urlencode({
'title': f'{args.project.capitalize()} v{version}',
'tag': f'{args.project}-v{version}',
'body': notes,
})

url = f'https://github.com/pypa/hatch/releases/new?{params}'
webbrowser.open_new_tab(url)
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Allow boolean positional values in function calls, like `dict.get(... True)`
'FBT003',
# Ignore complexity
'C901', 'PLR0904', 'PLR0911', 'PLR0912', 'PLR0913', 'PLR0915', 'PLR0916',
'C901', 'PLR0904', 'PLR0911', 'PLR0912', 'PLR0913', 'PLR0915', 'PLR0916', 'PLR0917',
# These are dependent on projects themselves
'AIR\\d+', 'CPY\\d+', 'D\\d+', 'DJ\\d+', 'NPY\\d+', 'PD\\d+',
# Many projects either don't have type annotations or it would take much effort to satisfy this
Expand Down
36 changes: 21 additions & 15 deletions src/hatch/env/internal/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,18 @@ def construct_config_file(self, *, preview: bool | None) -> str:
lines.append(']')

# Default config
lines.extend(
(
'',
'[lint.flake8-tidy-imports]',
'ban-relative-imports = "all"',
'',
'[lint.isort]',
f'known-first-party = ["{self.metadata.name.replace("-", "_")}"]',
'',
'[lint.flake8-pytest-style]',
'fixture-parentheses = false',
'mark-parentheses = false',
)
)
lines.extend((
'',
'[lint.flake8-tidy-imports]',
'ban-relative-imports = "all"',
'',
'[lint.isort]',
f'known-first-party = ["{self.metadata.name.replace("-", "_")}"]',
'',
'[lint.flake8-pytest-style]',
'fixture-parentheses = false',
'mark-parentheses = false',
))

# Ensure the file ends with a newline to satisfy other linters
lines.append('')
Expand Down Expand Up @@ -188,7 +186,7 @@ def get_config(self, section: str) -> dict[str, Any]:
return self.user_config.get(section, {})


RUFF_MINIMUM_VERSION: str = '0.1.6'
RUFF_MINIMUM_VERSION: str = '0.1.7'
STABLE_RULES: tuple[str, ...] = (
'A001',
'A002',
Expand Down Expand Up @@ -732,6 +730,7 @@ def get_config(self, section: str) -> dict[str, Any]:
'FURB145',
'FURB148',
'FURB152',
'FURB163',
'FURB168',
'FURB169',
'FURB171',
Expand All @@ -746,8 +745,13 @@ def get_config(self, section: str) -> dict[str, Any]:
'PLC2401',
'PLC2403',
'PLE0704',
'PLE1132',
'PLR0202',
'PLR0203',
'PLR1704',
'PLR1706',
'PLR1733',
'PLR1736',
'PLR6201',
'PLR6301',
'PLW0108',
Expand All @@ -761,8 +765,10 @@ def get_config(self, section: str) -> dict[str, Any]:
'RUF018',
'RUF019',
'S201',
'S202',
'S505',
'S507',
'S611',
'S702',
'TRIO100',
'TRIO105',
Expand Down
6 changes: 3 additions & 3 deletions src/hatch/python/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def unpack(self, archive: Path, directory: Path) -> None:
import tarfile

with tarfile.open(archive, 'r:gz') as tf:
tf.extractall(directory)
tf.extractall(directory) # noqa: S202
elif self.source.endswith('.tar.bz2'):
import tarfile

with tarfile.open(archive, 'r:bz2') as tf:
tf.extractall(directory)
tf.extractall(directory) # noqa: S202
elif self.source.endswith('.tar.zst'):
import tarfile

Expand All @@ -57,7 +57,7 @@ def unpack(self, archive: Path, directory: Path) -> None:
with open(archive, 'rb') as ifh:
dctx = zstandard.ZstdDecompressor()
with dctx.stream_reader(ifh) as reader, tarfile.open(mode='r|', fileobj=reader) as tf:
tf.extractall(directory)
tf.extractall(directory) # noqa: S202
else:
message = f'Unknown archive type: {archive}'
raise ValueError(message)
Expand Down
10 changes: 7 additions & 3 deletions src/hatch/utils/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ def populate_default_popen_kwargs(self, kwargs: dict[str, Any], *, shell: bool)
unprotected_paths = []
for path in default_paths:
normalized_path = os.path.normpath(path)
if not normalized_path.startswith(
('/System', '/usr', '/bin', '/sbin', '/var')
) or normalized_path.startswith('/usr/local'):
if not normalized_path.startswith((
'/System',
'/usr',
'/bin',
'/sbin',
'/var',
)) or normalized_path.startswith('/usr/local'):
unprotected_paths.append(path)

search_path = os.pathsep.join(unprotected_paths)
Expand Down
Loading