Skip to content

Commit 95b5255

Browse files
committed
linting and improved nox
1 parent 026b5d2 commit 95b5255

File tree

6 files changed

+46
-53
lines changed

6 files changed

+46
-53
lines changed

.flake8

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[flake8]
2+
max-line-length = 80
3+
per-file-ignores =
4+
upath/__init__.py: F401
5+
exclude =
6+
.noxfile,
7+
.nox,
8+
__pycache__,
9+
.git,
10+
.github,
11+
.gitignore,
12+
.pytest_cache,
13+
14+

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ dependencies:
1818
- pip
1919
- pip:
2020
- hadoop-test-cluster
21+
- nox
2122

noxfile.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import nox
2+
from pathlib import Path
23

34

45
@nox.session(python=False)
@@ -10,13 +11,13 @@ def develop(session):
1011
@nox.session(python=False)
1112
def black(session):
1213
session.install("black")
13-
session.run(*"black upath".split())
14+
session.run(*"black upath noxfile.py setup.py".split())
1415

1516

1617
@nox.session(python=False)
1718
def lint(session):
1819
session.install("flake8")
19-
session.run(*"flake8 upath".split())
20+
session.run(*"flake8".split())
2021

2122

2223
@nox.session(python=False)
@@ -34,3 +35,12 @@ def smoke(session):
3435
def build(session):
3536
session.install("flit")
3637
session.run(*"flit build".split())
38+
39+
40+
@nox.session(python=False)
41+
def rm_dirs(session):
42+
paths = ["build", "dist"]
43+
for path in paths:
44+
p = Path(path)
45+
if p.exists():
46+
session.run(*f"rm -rf {str(p)}".split())

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
with open("README.md") as f:
66
long_description = f.read()
7-
7+
88
setuptools.setup(
99
name="universal_pathlib",
1010
version=__version__,
@@ -15,5 +15,5 @@
1515
python_requires=">=3.7",
1616
description="pathlib api extended to use fsspec backends",
1717
long_description=long_description,
18-
long_description_content_type='text/markdown'
18+
long_description_content_type="text/markdown",
1919
)

upath/core.py

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import os
22
import pathlib
3-
from pathlib import *
43
import urllib
54
import re
6-
import asyncio
7-
import inspect
85

9-
import fsspec
10-
from fsspec.asyn import AsyncFileSystem
11-
from fsspec.core import url_to_fs
12-
from fsspec.registry import filesystem, get_filesystem_class
6+
from fsspec.registry import get_filesystem_class
137

148
from upath.errors import NotDirectoryError
159

@@ -81,21 +75,18 @@ def __getattribute__(self, item):
8175
if fs is not None:
8276
method = getattr(fs, item, None)
8377
if method:
84-
awaitable = inspect.isawaitable(
85-
lambda args, kwargs: method(*args, **kwargs)
86-
)
87-
return lambda *args, **kwargs: self.argument_upath_self_to_filepath(
88-
method
89-
)(
90-
*args, **kwargs
91-
)
78+
return lambda *args, **kwargs: (
79+
self.argument_upath_self_to_filepath(method)(
80+
*args, **kwargs
81+
)
82+
) # noqa: E501
9283
else:
9384
raise NotImplementedError(
9485
f"{fs.protocol} filesystem has not attribute {item}"
9586
)
9687

9788

98-
class PureUniversalPath(PurePath):
89+
class PureUniversalPath(pathlib.PurePath):
9990
_flavour = pathlib._posix_flavour
10091
__slots__ = ()
10192

@@ -111,7 +102,11 @@ def __new__(cls, *args, **kwargs):
111102
if val:
112103
parsed_url._replace(**{key: val})
113104
if not parsed_url.scheme:
114-
cls = WindowsPath if os.name == "nt" else PosixPath
105+
cls = (
106+
pathlib.WindowsPath
107+
if os.name == "nt"
108+
else pathlib.PosixPath
109+
)
115110
else:
116111
cls = UniversalPath
117112
# cls._url = parsed_url
@@ -134,28 +129,6 @@ def __new__(cls, *args, **kwargs):
134129
return self
135130

136131

137-
def run_as_async(self, func, *args, **kwargs):
138-
def wrapper(*args, **kwargs):
139-
if isinstance(self.fs, AsyncFileSystem):
140-
result = None
141-
142-
async def async_runner():
143-
async def async_func():
144-
return await func(*args, **kwargs)
145-
146-
coro = async_func()
147-
done, pending = await asyncio.wait({coro})
148-
if coro is done:
149-
result = coro
150-
151-
asyncio.run(async_runner())
152-
return result
153-
else:
154-
return func(*args, **kwargs)
155-
156-
return wrapper
157-
158-
159132
class UniversalPath(UPath, PureUniversalPath):
160133

161134
__slots__ = ("_url", "_kwargs", "_closed", "fs")
@@ -298,20 +271,15 @@ def unlink(self, missing_ok=False):
298271
raise FileNotFoundError
299272
else:
300273
return
301-
try:
302-
self._accessor.rm(self, recursive=False)
303-
except:
304-
self._accessor.rm_file(self)
305-
306-
# asyncio.run(async_unlink())
274+
self._accessor.rm(self, recursive=False)
307275

308276
def rmdir(self, recursive=True):
309277
"""Add warning if directory not empty
310278
assert is_dir?
311279
"""
312280
try:
313281
assert self.is_dir()
314-
except:
282+
except AssertionError:
315283
raise NotDirectoryError
316284
self._accessor.rm(self, recursive=recursive)
317285

upath/tests/test_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ def test_mkdir(self):
226226
# new_dir.mkdir()
227227
# mkdir doesnt really do anything. A directory only exists in s3
228228
# if some file or something is written to it
229-
f = new_dir.joinpath("test.txt").touch()
229+
new_dir.joinpath("test.txt").touch()
230230
assert new_dir.exists()
231231

232232
def test_rmdir(self, local_testdir):
233233
dirname = "rmdir_test"
234234
mock_dir = self.path.joinpath(dirname)
235-
f = mock_dir.joinpath("test.txt").touch()
235+
mock_dir.joinpath("test.txt").touch()
236236
mock_dir.rmdir()
237237
assert not mock_dir.exists()
238238
with pytest.raises(NotDirectoryError):
@@ -261,5 +261,5 @@ def test_multiple_backend_paths(local_testdir, s3, hdfs):
261261
assert s3_path.joinpath("text.txt")._url.scheme == "s3"
262262
host, user, port = hdfs
263263
path = f"hdfs:{local_testdir}"
264-
hdfs_path = UPath(path, host=host, user=user, port=port)
264+
UPath(path, host=host, user=user, port=port)
265265
assert s3_path.joinpath("text1.txt")._url.scheme == "s3"

0 commit comments

Comments
 (0)