sysutils/py-scandir: Fix unicode issues, level up ports compliance

This change fixes tests and likely runtime in certain locale environments
by replace the existing test_scandir.py patch with a backported upstream
patch from PR #109 [1][2], coupled with setting an appropriate locale.

While I'm here:

  - Strip shared library and add LICENSE_FILE

Tests now all pass on all Python versions (2.7-3.8)

[1] https://github.com/benhoyt/scandir/pull/109
[2] https://github.com/benhoyt/scandir/issues/122

Approved by:	portmgr (blanket: ports compliance, bugfix)
MFH:		2019Q4 (blanket: bugfix)
This commit is contained in:
Kubilay Kocak 2019-12-18 05:07:44 +00:00
parent 5dad846cad
commit 44bf576b45
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=520359
3 changed files with 36 additions and 70 deletions

View File

@ -4,6 +4,7 @@
PORTNAME= scandir
PORTVERSION= 1.10.0
DISTVERSIONPREFIX= v
PORTREVISION= 1
CATEGORIES= sysutils python
PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
@ -11,6 +12,7 @@ MAINTAINER= rene@FreeBSD.org
COMMENT= Fast and featureful directory iterator
LICENSE= BSD3CLAUSE
LICENSE_FILE= ${WRKSRC}/LICENSE.txt
USES= python
USE_PYTHON= autoplist distutils
@ -18,7 +20,12 @@ USE_PYTHON= autoplist distutils
USE_GITHUB= yes
GH_ACCOUNT= benhoyt
USE_LOCALE= en_US.UTF-8
post-install:
${STRIP_CMD} ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR}/_scandir.so
do-test:
${PYTHON_CMD} ${WRKSRC}/test/run_tests.py
${SETENV} ${TEST_ENV} ${PYTHON_CMD} ${WRKSRC}/test/run_tests.py
.include <bsd.port.mk>

View File

@ -0,0 +1,28 @@
# Based on https://github.com/benhoyt/scandir/pull/109
# TODO: Upstream
# See: https://github.com/benhoyt/scandir/issues/122
From cfda49a07865097d3fdadc4e321881635ab2f795 Mon Sep 17 00:00:00 2001
From: "Elias M. Mariani" <marianielias@gmail.com>
Date: Mon, 6 Aug 2018 12:06:44 -0300
Subject: [PATCH] Fix dirent.h struct alignment on OpenBSD
--- scandir.py.orig 2019-03-09 17:51:39 UTC
+++ scandir.py
@@ -432,6 +432,16 @@ elif sys.platform.startswith(('linux', 'darwin', 'suno
('__d_padding', ctypes.c_uint8 * 4),
('d_name', ctypes.c_char * 256),
)
+ elif 'freebsd' in sys.platform:
+ _fields_ = (
+ ('d_ino', ctypes.c_uint64),
+ ('d_off', ctypes.c_uint64),
+ ('d_reclen', ctypes.c_uint16),
+ ('d_type', ctypes.c_uint8),
+ ('d_namlen', ctypes.c_uint8),
+ ('__d_padding', ctypes.c_uint8 * 4),
+ ('d_name', ctypes.c_char * 256),
+ )
else:
_fields_ = (
('d_ino', ctypes.c_uint32), # must be uint32, not ulong

View File

@ -1,69 +0,0 @@
--- test/test_scandir.py.orig 2017-09-29 12:38:51 UTC
+++ test/test_scandir.py
@@ -14,6 +14,9 @@ try:
except ImportError:
has_scandir = False
+reload(sys)
+sys.setdefaultencoding('utf8')
+
FILE_ATTRIBUTE_DIRECTORY = 16
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), 'testdir'))
@@ -48,24 +51,24 @@ def create_file(path, contents='1234'):
def setup_main():
join = os.path.join
- os.mkdir(TEST_PATH)
- os.mkdir(join(TEST_PATH, 'subdir'))
+ os.makedirs(TEST_PATH)
+ os.makedirs(join(TEST_PATH, 'subdir'))
create_file(join(TEST_PATH, 'file1.txt'))
create_file(join(TEST_PATH, 'file2.txt'), contents='12345678')
- os.mkdir(join(TEST_PATH, 'subdir', 'unidir\u018F'))
+ os.makedirs(join(TEST_PATH, 'subdir', u'unidir\u018F'))
create_file(join(TEST_PATH, 'subdir', 'file1.txt'))
- create_file(join(TEST_PATH, 'subdir', 'unicod\u018F.txt'))
+ create_file(join(TEST_PATH, 'subdir', u'unicod\u018F.txt'))
- create_file(join(TEST_PATH, 'subdir', 'unidir\u018F', 'file1.txt'))
+ create_file(join(TEST_PATH, 'subdir', u'unidir\u018F', 'file1.txt'))
- os.mkdir(join(TEST_PATH, 'linkdir'))
+ os.makedirs(join(TEST_PATH, 'linkdir'))
def setup_symlinks():
join = os.path.join
- os.mkdir(join(TEST_PATH, 'linkdir', 'linksubdir'))
+ os.makedirs(join(TEST_PATH, 'linkdir', 'linksubdir'))
create_file(join(TEST_PATH, 'linkdir', 'file1.txt'))
os.symlink(os.path.abspath(join(TEST_PATH, 'linkdir', 'file1.txt')),
@@ -217,7 +220,7 @@ class TestMixin(object):
self.assertTrue(isinstance(entry.path, bytes))
# b'unicod?.txt' on Windows, b'unicod\xc6\x8f.txt' (UTF-8) or similar on POSIX
- entry_name = 'unicod\u018f.txt'.encode(sys.getfilesystemencoding(), 'replace')
+ entry_name = u'unicod\u018f.txt'.encode(sys.getfilesystemencoding(), 'replace')
self.assertEqual(entry.name, entry_name)
self.assertEqual(entry.path, os.path.join(path, entry_name))
@@ -234,12 +237,12 @@ class TestMixin(object):
self.assertTrue(isinstance(entry.name, str))
self.assertTrue(isinstance(entry.path, str))
- entry_name = 'unicod\u018f.txt'
+ entry_name = u'unicod\u018f.txt'
self.assertEqual(entry.name, entry_name)
- self.assertEqual(entry.path, os.path.join(path, 'unicod\u018f.txt'))
+ self.assertEqual(entry.path, os.path.join(path, u'unicod\u018f.txt'))
# Check that it handles unicode input properly
- path = os.path.join(TEST_PATH, 'subdir', 'unidir\u018f')
+ path = os.path.join(TEST_PATH, 'subdir', u'unidir\u018f')
self.assertTrue(isinstance(path, str))
entries = list(self.scandir_func(path))
self.assertEqual(len(entries), 1)