public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/pkgcore/snakeoil:master commit in: tests/, src/snakeoil/
@ 2022-12-31 21:07 Arthur Zamarin
  0 siblings, 0 replies; only message in thread
From: Arthur Zamarin @ 2022-12-31 21:07 UTC (permalink / raw
  To: gentoo-commits

commit:     0a9a567ec6672e2ad541dfbf5ad6f6484bcbcf77
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 31 21:06:57 2022 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Sat Dec 31 21:06:57 2022 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=0a9a567e

fileutils: small cleanup and modernization

Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/snakeoil/_fileutils.py | 15 ---------------
 src/snakeoil/fileutils.py  | 14 +++++---------
 tests/test_fileutils.py    |  7 -------
 tests/test_osutils.py      |  4 +---
 4 files changed, 6 insertions(+), 34 deletions(-)

diff --git a/src/snakeoil/_fileutils.py b/src/snakeoil/_fileutils.py
index 4a226486..cd0bb645 100644
--- a/src/snakeoil/_fileutils.py
+++ b/src/snakeoil/_fileutils.py
@@ -64,10 +64,6 @@ class readlines_iter:
         return self.iterable
 
 
-def _native_readlines_shim(*args, **kwds):
-    return native_readlines("r", *args, **kwds)
-
-
 def native_readlines(
     mode,
     mypath,
@@ -107,17 +103,6 @@ def _strip_whitespace_filter(iterable):
         yield line.strip()
 
 
-def _py2k_ascii_strict_filter(source):
-    for line in source:
-        if any((0x80 & ord(char)) for char in line):
-            raise ValueError("character ordinal over 127")
-        yield line
-
-
-def _native_readfile_shim(*args, **kwds):
-    return native_readfile("r", *args, **kwds)
-
-
 def native_readfile(mode, mypath, none_on_missing=False, encoding=None):
     """Read a file, returning the contents.
 

diff --git a/src/snakeoil/fileutils.py b/src/snakeoil/fileutils.py
index b0aa7247..743ef2d1 100644
--- a/src/snakeoil/fileutils.py
+++ b/src/snakeoil/fileutils.py
@@ -12,21 +12,17 @@ from .currying import pretty_docs
 from .klass import GetAttrProxy
 
 
-def touch(fname, mode=0o644, **kwargs):
+def touch(fname: str, mode: int = 0o644, dir_fd=None, **kwargs):
     """touch(1) equivalent
 
     :param fname: file path
-    :type fname: str
     :param mode: file mode
-    :type mode: octal
 
     See os.utime for other supported arguments.
     """
     flags = os.O_CREAT | os.O_APPEND
-    dir_fd = kwargs.get("dir_fd", None)
-    os_open = partial(os.open, dir_fd=dir_fd)
 
-    with os.fdopen(os_open(fname, flags, mode)) as f:
+    with os.fdopen(os.open(fname, flags, mode, dir_fd=dir_fd)) as f:
         os.utime(
             f.fileno() if os.utime in os.supports_fd else fname,
             dir_fd=None if os.supports_fd else dir_fd,
@@ -34,7 +30,7 @@ def touch(fname, mode=0o644, **kwargs):
         )
 
 
-def mmap_or_open_for_read(path):
+def mmap_or_open_for_read(path: str):
     size = os.stat(path).st_size
     if size == 0:
         return (None, data_source.bytes_ro_StringIO(b""))
@@ -153,10 +149,10 @@ class AtomicWriteFile(AtomicWriteFile_mixin):
     __getattr__ = GetAttrProxy("raw")
 
 
-def _mk_pretty_derived_func(func, name_base, name, *args, **kwds):
+def _mk_pretty_derived_func(func, name_base: str, name: str, *args, **kwds):
     if name:
         name = "_" + name
-    return pretty_docs(partial(func, *args, **kwds), name="%s%s" % (name_base, name))
+    return pretty_docs(partial(func, *args, **kwds), name=name_base + name)
 
 
 _mk_readfile = partial(_mk_pretty_derived_func, _fileutils.native_readfile, "readfile")

diff --git a/tests/test_fileutils.py b/tests/test_fileutils.py
index 356eb74d..de8a1f7d 100644
--- a/tests/test_fileutils.py
+++ b/tests/test_fileutils.py
@@ -122,13 +122,6 @@ class TestAtomicWriteFile:
         af.close()
 
 
-def cpy_setup_class(scope, func_name):
-    if getattr(fileutils, "native_%s" % func_name) is getattr(fileutils, func_name):
-        scope["skip"] = "extensions disabled"
-    else:
-        scope["func"] = staticmethod(getattr(fileutils, func_name))
-
-
 class Test_readfile:
     func = staticmethod(fileutils.readfile)
 

diff --git a/tests/test_osutils.py b/tests/test_osutils.py
index fac98532..a60bb15f 100644
--- a/tests/test_osutils.py
+++ b/tests/test_osutils.py
@@ -10,7 +10,6 @@ from unittest import mock
 import pytest
 from snakeoil import osutils
 from snakeoil.contexts import Namespace
-from snakeoil.fileutils import touch
 from snakeoil.osutils import native_readdir, supported_systems, sizeof_fmt
 from snakeoil.osutils.mount import MNT_DETACH, MS_BIND, mount, umount
 
@@ -114,8 +113,7 @@ class TestEnsureDirs:
 
     def test_path_is_a_file(self, tmp_path):
         # fail if passed a path to an existing file
-        path = tmp_path / "file"
-        touch(path)
+        (path := tmp_path / "file").touch()
         assert path.is_file()
         assert not osutils.ensure_dirs(path, mode=0o700)
 


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-31 21:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-31 21:07 [gentoo-commits] proj/pkgcore/snakeoil:master commit in: tests/, src/snakeoil/ Arthur Zamarin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox