Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code with black #68

Merged
merged 2 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
set -e

/github/home/.local/bin/poetry install
- name: Black
shell: bash
run: |
set -e
/github/home/.local/bin/poetry run black . --check --diff
- name: Lint
run: |
set -e
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Hadoop FileSystem Java Class Wrapper
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Typed Python wrappers for [Hadoop FileSystem](https://hadoop.apache.org/docs/stable/api/org/apache/hadoop/fs/FileSystem.html) class family.

## Installation
Expand Down Expand Up @@ -42,4 +44,4 @@ def is_valid_source_path(file_system: FileSystem, path: str) -> bool:
Currently basic filesystem operations (listing, deleting, search, iterative listing etc.) are supported. If an operation you require is not yet wrapped,
please open an issue or create a PR.

All changes are tested against Spark 3.2/3.3 running in local mode.
All changes are tested against Spark 3.2/3.3 running in local mode.
2 changes: 1 addition & 1 deletion hadoop_fs_wrapper/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
Version file.
"""

__version__ = '0.0.0' # replaced by git tag on deploy
__version__ = "0.0.0" # replaced by git tag on deploy
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/buffered_input_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

class BufferedInputStream:
"""
Wrapper for java.io.BufferedInputStream
Wrapper for java.io.BufferedInputStream
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

Expand Down
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/buffered_output_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

class BufferedOutputStream:
"""
Wrapper for java.io.BufferedOutputStream
Wrapper for java.io.BufferedOutputStream
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

Expand Down
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/buffered_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

class BufferedReader:
"""
Wrapper for java.io.BufferedReader
Wrapper for java.io.BufferedReader
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

Expand Down
21 changes: 11 additions & 10 deletions hadoop_fs_wrapper/models/file_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,67 @@

class FileStatus:
"""
Wrapper for org.apache.hadoop.fs.FileStatus
Wrapper for org.apache.hadoop.fs.FileStatus
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

def get_path(self) -> str:
"""
Wraps getPath() method.
Wraps getPath() method.

"""
return self.underlying.getPath().toString()

def get_owner(self) -> str:
"""
Wraps getOwner() method.
Wraps getOwner() method.

"""
return self.underlying.getOwner()

def get_group(self) -> str:
"""
Wraps getGroup() method.
Wraps getGroup() method.

"""
return self.underlying.getGroup()

def get_permission(self) -> str:
"""
Wraps getPermission() method.
Wraps getPermission() method.

"""
return self.underlying.getPermission().toString()

def get_modification_time(self) -> int:
"""
Wraps getModificationTime() method.
Wraps getModificationTime() method.

"""
return self.underlying.getModificationTime()

def is_file(self) -> bool:
"""
Wraps isFile() method.
Wraps isFile() method.

"""
return self.underlying.isFile()

def get_block_size(self) -> int:
"""
Wraps getBlockSize() method.
Wraps getBlockSize() method.

"""
return self.underlying.getBlockSize()

def get_file_length(self) -> int:
"""
Wraps getLen() method.
Wraps getLen() method.

"""
return self.underlying.getLen()
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/fs_data_input_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@

class FSDataInputStream:
"""
Wrapper for org.apache.hadoop.fs.FSDataInputStream
Wrapper for org.apache.hadoop.fs.FSDataInputStream
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/fs_data_output_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@

class FSDataOutputStream:
"""
Wrapper for org.apache.hadoop.fs.FSDataOutputStream
Wrapper for org.apache.hadoop.fs.FSDataOutputStream
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/glob_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

class GlobFilter:
"""
Wrapper for org.apache.hadoop.fs.GlobFilter
Wrapper for org.apache.hadoop.fs.GlobFilter
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

Expand Down
9 changes: 4 additions & 5 deletions hadoop_fs_wrapper/models/hadoop_file_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
@dataclass
class HadoopFileStatus:
"""
Interface that represents the client side information for a file.
Interface that represents the client side information for a file.
"""

path: str
owner: str
group: str
Expand All @@ -57,12 +58,10 @@ def from_file_status(cls, hadoop_file_status: FileStatus):
owner=hadoop_file_status.get_owner(),
group=hadoop_file_status.get_group(),
permission=hadoop_file_status.get_permission(),
modified_on=datetime.utcfromtimestamp(
hadoop_file_status.get_modification_time() // 1000
).replace(
modified_on=datetime.utcfromtimestamp(hadoop_file_status.get_modification_time() // 1000).replace(
microsecond=hadoop_file_status.get_modification_time() % 1000 * 1000
),
type="File" if hadoop_file_status.is_file() else "Folder",
block_size=hadoop_file_status.get_block_size(),
length=hadoop_file_status.get_file_length()
length=hadoop_file_status.get_file_length(),
)
9 changes: 5 additions & 4 deletions hadoop_fs_wrapper/models/hadoop_fs_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@

class HadoopFsPath:
"""
Wrapper for org.apache.hadoop.fs.Path
Wrapper for org.apache.hadoop.fs.Path
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

def uri(self):
"""
Returns java.net.Uri corresponding to the supplied path
Returns java.net.Uri corresponding to the supplied path
"""
return self.underlying.toUri()

@classmethod
def from_string(cls, jvm, path_string: str):
"""
Creates a new class instance directly from a path string
Creates a new class instance directly from a path string
"""
return cls(jvm.org.apache.hadoop.fs.Path(path_string))
7 changes: 4 additions & 3 deletions hadoop_fs_wrapper/models/input_stream_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

class InputStreamReader:
"""
Wrapper for java.io.InputStreamReader
Wrapper for java.io.InputStreamReader
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

Expand All @@ -44,7 +45,7 @@ def from_input_stream_and_charset(cls, jvm, input_stream, charset_name):
:param charset_name: The name of a supported charset
:return: InputStreamReader
"""
return cls(jvm.java.io.InputStreamReader(input_stream,charset_name))
return cls(jvm.java.io.InputStreamReader(input_stream, charset_name))

@classmethod
def from_input_stream(cls, jvm, input_stream):
Expand Down
18 changes: 9 additions & 9 deletions hadoop_fs_wrapper/models/remote_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@
"""
from typing import Generic, TypeVar, Iterable, Iterator

T = TypeVar('T') # pylint: disable=C0103
T = TypeVar("T") # pylint: disable=C0103


class RemoteIterator(Generic[T], Iterable[T]):
"""
Wrapper for org.apache.hadoop.fs.RemoteIterator<T>
Wrapper for org.apache.hadoop.fs.RemoteIterator<T>
"""

def __iter__(self) -> Iterator[T]:
return self

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

def _next(self) -> T:
"""
Wraps E next()
throws IOException
Returns the next element in the iteration.
Wraps E next()
throws IOException
Returns the next element in the iteration.
"""

return self.underlying.next()

def _has_next(self) -> bool:
"""
Wraps boolean hasNext()
throws IOException
Returns true if the iteration has more elements.
Wraps boolean hasNext()
throws IOException
Returns true if the iteration has more elements.
"""

return self.underlying.hasNext()
Expand Down
5 changes: 3 additions & 2 deletions hadoop_fs_wrapper/models/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@

class URI:
"""
Wrapper for java.net.URI
Wrapper for java.net.URI
"""

def __init__(self, underlying):
"""
Class init
Class init
"""
self.underlying = underlying

Expand Down
Loading