Skip to content

Commit daf5752

Browse files
committed
fixed a crash with pypy2
1 parent 5f56304 commit daf5752

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

build_rules.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
"""
1919

2020
# pylint: disable=unused-argument
21+
# pylint: disable=consider-using-f-string
2122

2223
from __future__ import absolute_import, print_function, unicode_literals
2324

2425
import os
2526
import sys
2627
from burger import clean_directories, clean_files, run_command, \
27-
lock_files, unlock_files, delete_directory
28+
lock_files, unlock_files, delete_directory, create_setup_py, \
29+
delete_file
30+
2831
from wslwinreg import __version__
2932

3033
# If set to True, ``buildme -r``` will not parse directories in this folder.
@@ -86,6 +89,10 @@ def build(working_directory, configuration):
8689
None if not implemented, otherwise an integer error code.
8790
"""
8891

92+
input_file = os.path.join(working_directory, "pyproject.toml")
93+
output_file = os.path.join(working_directory, "setup.py")
94+
create_setup_py(input_file, output_file)
95+
8996
# Unlock the files to handle Perforce locking
9097
lock_list = unlock_files(working_directory) + \
9198
unlock_files(os.path.join(working_directory, "wslwinreg"))
@@ -129,6 +136,7 @@ def clean(working_directory):
129136

130137
# Get rid of extra binaries
131138
delete_directory(os.path.join(working_directory, "wslwinreg", "bin"))
139+
delete_file(os.path.join(working_directory, "setup.py"))
132140

133141
clean_directories(
134142
working_directory,

pyproject.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors = [
1212
description = "Drop in replacement for winreg for Cygwin, MSYS2 and WSL"
1313
license = "MIT"
1414
license-files = ["LICENSE.txt"]
15-
dependencies = ["setuptools >= 77.0.0", "enum34>=1.0.0"]
15+
dependencies = ["setuptools >=44.0.0", "enum34>=1.0.0"]
1616
classifiers = [
1717
"Development Status :: 5 - Production/Stable",
1818
"Environment :: Console",
@@ -51,6 +51,10 @@ keywords = [
5151
"burger",
5252
]
5353

54+
[tool.setuptools]
55+
platforms = ["Any"]
56+
zip-safe = false
57+
5458
[tool.setuptools.dynamic]
5559
version = { attr = "wslwinreg.__version__" }
5660

@@ -60,9 +64,9 @@ Documentation = "http://wslwinreg.readthedocs.io"
6064
Source = "https://github.com/burgerbecky/wslwinreg"
6165

6266
[tool.setuptools.packages.find]
63-
include = ["wslwinreg"]
67+
include = ["wslwinreg", "wslwinreg.bin"]
6468
exclude = ["unittests", "src"]
65-
namespaces = false
69+
namespaces = true
6670

6771
[tool.setuptools.package-data]
6872
wslwinreg = ["bin/*.exe"]

unittests/test_winreg.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# pylint: disable=invalid-name
2525
# pylint: disable=consider-using-f-string
2626

27+
# Some tests are unstable on pypy
2728
USING_PYPY = python_implementation().lower() == "pypy"
2829

2930
try:
@@ -66,16 +67,16 @@ def win32_edition():
6667
WIN_VER = (10, 0)
6768

6869
# Some tests should only run on 64-bit architectures where WOW64 will be.
69-
WIN64_MACHINE = True if machine() == "AMD64" or machine() == "x86_64" else False
70+
WIN64_MACHINE = bool(machine() == "AMD64" or machine() == "x86_64")
7071

7172
# Starting with Windows 7 and Windows Server 2008 R2, WOW64 no longer uses
7273
# registry reflection and formerly reflected keys are shared instead.
7374
# Windows 7 and Windows Server 2008 R2 are version 6.1. Due to this, some
7475
# tests are only valid up until 6.1
75-
HAS_REFLECTION = True if WIN_VER < (6, 1) else False
76+
HAS_REFLECTION = bool(WIN_VER < (6, 1))
7677

77-
STRING_WITH_NULL_WORKS = True if sys.version_info >= (3, 6, 0) or \
78-
sys.version_info[0] == 2 else False
78+
STRING_WITH_NULL_WORKS = bool(sys.version_info >= (3, 6, 0) or \
79+
sys.version_info[0] == 2)
7980

8081
# Use a per-process key to prevent concurrent test runs (buildbot!) from
8182
# stomping on each other.
@@ -264,24 +265,22 @@ class LocalWinregTests(BaseWinregTests):
264265
Run tests only on local machine
265266
"""
266267

268+
@unittest.skipIf(USING_PYPY, "Test doesn't work on PYPY")
267269
def test_registry_works(self):
268270
"""
269271
Try unicode
270272
"""
271-
if not USING_PYPY:
272-
self._test_all(HKEY_CURRENT_USER)
273-
self._test_all(HKEY_CURRENT_USER, "日本-subkey")
273+
self._test_all(HKEY_CURRENT_USER)
274+
self._test_all(HKEY_CURRENT_USER, "日本-subkey")
274275

276+
@unittest.skipIf(USING_PYPY, "Test doesn't work on PYPY")
275277
def test_registry_works_extended_functions(self):
276278
"""
277279
Substitute the regular CreateKey and OpenKey calls with their
278280
extended counterparts.
279281
Note: DeleteKeyEx is not used here because it is platform dependent
280282
"""
281283

282-
if USING_PYPY:
283-
return
284-
285284
def cke(key, sub_key):
286285
return CreateKeyEx(
287286
key,
@@ -349,6 +348,7 @@ def test_context_manager(self):
349348
except OSError:
350349
self.assertEqual(h.handle, 0)
351350

351+
@unittest.skipIf(USING_PYPY, "Test doesn't work on PYPY")
352352
def test_changing_value(self):
353353
"""
354354
Issue2810: A race condition in 2.6 and 3.1 may cause
@@ -403,6 +403,7 @@ def test_long_key(self):
403403
DeleteKey(HKEY_CURRENT_USER, "\\".join((test_key_name, name)))
404404
DeleteKey(HKEY_CURRENT_USER, test_key_name)
405405

406+
@unittest.skipIf(USING_PYPY, "Test doesn't work on PYPY")
406407
def test_dynamic_key(self):
407408
"""
408409
Issue2810, when the value is dynamically generated, these

wslwinreg/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
PFILETIME, SUBLANG_DEFAULT
6464

6565
## Numeric version
66-
__numversion__ = (1, 1, 1)
66+
__numversion__ = (1, 1, 2)
6767

6868
## Current version of the library
6969
__version__ = ".".join([str(num) for num in __numversion__])

wslwinreg/wslapi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@
4545
# Fake it for Python 3
4646
basestring = str
4747

48+
try:
49+
FileNotFoundError # type: ignore
50+
except NameError:
51+
class FileNotFoundError(OSError):
52+
"""
53+
pypy2 does not define this exception
54+
"""
55+
# pylint: disable=unnecessary-pass
56+
pass
57+
4858
## Loopback address
4959
_LOCALHOST = "127.0.0.1"
5060

0 commit comments

Comments
 (0)