Skip to content

Commit 34f4df6

Browse files
authored
fix: Python lint import-outside-top-level ruff rule PLC0415 (#298)
* fix: Python lint import-outside-top-level ruff rule PLC0415 * Use project.requires-python not tool.ruff.target-version
1 parent 81af3bf commit 34f4df6

File tree

8 files changed

+11
-12
lines changed

8 files changed

+11
-12
lines changed

pylib/gyp/MSVSVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _RegistryGetValueUsingWinReg(key, value):
219219
contents of the registry key's value, or None on failure. Throws
220220
ImportError if winreg is unavailable.
221221
"""
222-
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx
222+
from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx # noqa: PLC0415
223223
try:
224224
root, subkey = key.split("\\", 1)
225225
assert root == "HKLM" # Only need HKLM for now.

pylib/gyp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def gyp_main(args):
489489

490490
options, build_files_arg = parser.parse_args(args)
491491
if options.version:
492-
import pkg_resources
492+
import pkg_resources # noqa: PLC0415
493493
print(f"v{pkg_resources.get_distribution('gyp-next').version}")
494494
return 0
495495
build_files = build_files_arg

pylib/gyp/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ def uniquer(seq, idfun=lambda x: x):
583583

584584

585585
# Based on http://code.activestate.com/recipes/576694/.
586-
class OrderedSet(MutableSet):
586+
class OrderedSet(MutableSet): # noqa: PLW1641
587+
# TODO (cclauss): Fix eq-without-hash ruff rule PLW1641
587588
def __init__(self, iterable=None):
588589
self.end = end = []
589590
end += [None, end, end] # sentinel node for doubly linked list

pylib/gyp/generator/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def CalculateVariables(default_variables, params):
7878

7979
# Copy additional generator configuration data from Xcode, which is shared
8080
# by the Mac Make generator.
81-
import gyp.generator.xcode as xcode_generator
81+
import gyp.generator.xcode as xcode_generator # noqa: PLC0415
8282

8383
global generator_additional_non_configuration_keys
8484
generator_additional_non_configuration_keys = getattr(

pylib/gyp/generator/ninja.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import collections
77
import copy
8+
import ctypes
89
import hashlib
910
import json
1011
import multiprocessing
@@ -1993,7 +1994,7 @@ def CalculateVariables(default_variables, params):
19931994

19941995
# Copy additional generator configuration data from Xcode, which is shared
19951996
# by the Mac Ninja generator.
1996-
import gyp.generator.xcode as xcode_generator
1997+
import gyp.generator.xcode as xcode_generator # noqa: PLC0415
19971998

19981999
generator_additional_non_configuration_keys = getattr(
19992000
xcode_generator, "generator_additional_non_configuration_keys", []
@@ -2016,7 +2017,7 @@ def CalculateVariables(default_variables, params):
20162017

20172018
# Copy additional generator configuration data from VS, which is shared
20182019
# by the Windows Ninja generator.
2019-
import gyp.generator.msvs as msvs_generator
2020+
import gyp.generator.msvs as msvs_generator # noqa: PLC0415
20202021

20212022
generator_additional_non_configuration_keys = getattr(
20222023
msvs_generator, "generator_additional_non_configuration_keys", []
@@ -2084,8 +2085,6 @@ def GetDefaultConcurrentLinks():
20842085
return pool_size
20852086

20862087
if sys.platform in ("win32", "cygwin"):
2087-
import ctypes
2088-
20892088
class MEMORYSTATUSEX(ctypes.Structure):
20902089
_fields_ = [
20912090
("dwLength", ctypes.c_ulong),

pylib/gyp/mac_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _CopyStringsFile(self, source, dest):
141141
# CFPropertyListCreateFromXMLData(): Old-style plist parser: missing
142142
# semicolon in dictionary.
143143
# on invalid files. Do the same kind of validation.
144-
import CoreFoundation
144+
import CoreFoundation # noqa: PLC0415
145145

146146
with open(source, "rb") as in_file:
147147
s = in_file.read()

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ gyp = "gyp:script_main"
3939
[tool.ruff]
4040
extend-exclude = ["pylib/packaging"]
4141
line-length = 88
42-
target-version = "py37"
4342

4443
[tool.ruff.lint]
4544
select = [

test_gyp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ def print_configuration_info():
148148
print("Test configuration:")
149149
if sys.platform == "darwin":
150150
sys.path.append(os.path.abspath("test/lib"))
151-
import TestMac
151+
import TestMac # noqa: PLC0415
152152

153153
print(f" Mac {platform.mac_ver()[0]} {platform.mac_ver()[2]}")
154154
print(f" Xcode {TestMac.Xcode.Version()}")
155155
elif sys.platform == "win32":
156156
sys.path.append(os.path.abspath("pylib"))
157-
import gyp.MSVSVersion
157+
import gyp.MSVSVersion # noqa: PLC0415
158158

159159
print(" Win %s %s\n" % platform.win32_ver()[0:2])
160160
print(" MSVS %s" % gyp.MSVSVersion.SelectVisualStudioVersion().Description())

0 commit comments

Comments
 (0)