Skip to content
This repository has been archived by the owner on Aug 18, 2022. It is now read-only.

Commit

Permalink
Add black to the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Dec 29, 2020
1 parent 30405e9 commit 1819e98
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 59 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
on: [push, pull_request]

jobs:
Formatting:
runs-on: ubuntu-latest

steps:
- name: Clone
uses: actions/checkout@v2

- name: Install black
run: |
python3 -m pip install setuptools
python3 -m pip install black
- name: Run black check
run: python3 -m black --check pylas


Tests:
runs-on: ubuntu-latest
strategy:
Expand Down
6 changes: 2 additions & 4 deletions pylas/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ def __init__(

@property
def point_format(self) -> PointFormat:
""" The point format
"""
"""The point format"""
return self._point_format

@point_format.setter
Expand All @@ -203,8 +202,7 @@ def point_format(self, new_point_format: PointFormat) -> None:

@property
def version(self) -> Version:
""" The version
"""
"""The version"""
return self._version

@version.setter
Expand Down
36 changes: 18 additions & 18 deletions pylas/lasappender.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@


class LasAppender:
""" Allows to append points to and existing LAS/LAZ file.
"""Allows to append points to and existing LAS/LAZ file.
Appending to LAZ is only supported by the lazrs backend
"""

def __init__(
self,
dest: BinaryIO,
laz_backend: Union[LazBackend, Iterable[LazBackend]] = (
LazBackend.LazrsParallel,
LazBackend.Lazrs,
),
closefd: bool = True,
self,
dest: BinaryIO,
laz_backend: Union[LazBackend, Iterable[LazBackend]] = (
LazBackend.LazrsParallel,
LazBackend.Lazrs,
),
closefd: bool = True,
) -> None:
if not dest.seekable():
raise TypeError("Expected the 'dest' to be a seekable file object")
Expand All @@ -51,7 +51,7 @@ def __init__(

if header.version.minor >= 4 and header.number_of_evlrs > 0:
assert (
self.dest.tell() <= self.header.start_of_first_evlr
self.dest.tell() <= self.header.start_of_first_evlr
), "The position is past the start of evlrs"
pos = self.dest.tell()
self.dest.seek(self.header.start_of_first_evlr, io.SEEK_SET)
Expand All @@ -66,7 +66,7 @@ def __init__(
self.closefd = closefd

def append_points(self, points: PackedPointRecord) -> None:
""" Append the points to the file, the points
"""Append the points to the file, the points
must have the same point format as the points
already contained within the file.
Expand All @@ -88,9 +88,9 @@ def close(self) -> None:

def _write_evlrs(self) -> None:
if (
self.header.version.minor >= 4
and self.evlrs is not None
and len(self.evlrs) > 0
self.header.version.minor >= 4
and self.evlrs is not None
and len(self.evlrs) > 0
):
self.header.number_of_evlr = len(self.evlrs)
self.header.start_of_first_evlr = self.dest.tell()
Expand All @@ -103,11 +103,11 @@ def _write_updated_header(self) -> None:
self.dest.seek(pos, io.SEEK_SET)

def _create_laz_backend(
self,
laz_backend: Union[LazBackend, Iterable[LazBackend]] = (
LazBackend.LazrsParallel,
LazBackend.Lazrs,
),
self,
laz_backend: Union[LazBackend, Iterable[LazBackend]] = (
LazBackend.LazrsParallel,
LazBackend.Lazrs,
),
) -> "LazrsAppender":
try:
laz_backend = iter(laz_backend)
Expand Down
4 changes: 3 additions & 1 deletion pylas/lasreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
self.points_read = 0

def read_points(self, n: int) -> Optional[record.ScaleAwarePointRecord]:
""" Read n points from the file
"""Read n points from the file
If there are no points left to read, returns None.
Expand Down Expand Up @@ -89,6 +89,8 @@ def read(self) -> LasData:
points = self.read_points(-1)
if points is None:
points = record.PackedPointRecord.empty(self.header.point_format)
else:
points = record.PackedPointRecord(points.array, points.point_format)

las_data = LasData(header=self.header, points=points)
if self.header.version.minor >= 4:
Expand Down
4 changes: 2 additions & 2 deletions pylas/laswriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@


class LasWriter:
""" Allows to write a complete LAS/LAZ file to the destination.
"""
"""Allows to write a complete LAS/LAZ file to the destination."""

def __init__(
self,
dest: BinaryIO,
Expand Down
9 changes: 3 additions & 6 deletions pylas/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def open_las(
header=None,
do_compress=None,
) -> Union[LasReader, LasWriter, LasAppender]:
""" The pylas.open opens a LAS/LAZ file in one of the 3 supported
"""The pylas.open opens a LAS/LAZ file in one of the 3 supported
mode:
- "r" => Reading => a :class:`pylas.LasReader` will be returned
Expand Down Expand Up @@ -175,8 +175,7 @@ def read_las(source, closefd=True, laz_backend=LazBackend.detect_available()):


def mmap_las(filename):
"""MMap a file, much like laspy did
"""
"""MMap a file, much like laspy did"""
return LasMMAP(filename)


Expand Down Expand Up @@ -227,9 +226,7 @@ def create_las(
if isinstance(point_format, int):
point_format = PointFormat(point_format)

header = LasHeader(
point_format=point_format, version=file_version
)
header = LasHeader(point_format=point_format, version=file_version)
return LasData(header=header)


Expand Down
39 changes: 22 additions & 17 deletions pylas/point/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@


class ExtraBytesParams:
""" All parameters needed to create extra bytes
"""
"""All parameters needed to create extra bytes"""

def __init__(self,
name: str,
type: str,
description: str = "",
offsets: Optional[np.ndarray] = None,
scales: Optional[np.ndarray] = None) -> None:
if offsets is not None and scales is None or offsets is None and scales is not None:
def __init__(
self,
name: str,
type: str,
description: str = "",
offsets: Optional[np.ndarray] = None,
scales: Optional[np.ndarray] = None,
) -> None:
if (
offsets is not None
and scales is None
or offsets is None
and scales is not None
):
raise ValueError("Both scales and offsets needs to be provided")

self.name = name
Expand Down Expand Up @@ -53,8 +59,8 @@ class PointFormat:
"""

def __init__(
self,
point_format_id: int,
self,
point_format_id: int,
):
"""
Parameters
Expand Down Expand Up @@ -82,7 +88,7 @@ def __init__(

@property
def standard_dimensions(self) -> Iterable[dims.DimensionInfo]:
""" Returns an iterable of the standard dimensions
"""Returns an iterable of the standard dimensions
>>> fmt = PointFormat(0)
>>> standard_dims = list(fmt.standard_dimensions)
Expand Down Expand Up @@ -157,7 +163,7 @@ def has_waveform_packet(self):
return all(name in dimensions for name in dims.WAVEFORM_FIELDS_NAMES)

def dimension_by_name(self, name: str) -> dims.DimensionInfo:
""" Returns the dimension info for the dimension by name
"""Returns the dimension info for the dimension by name
ValueError is raised if the dimension does not exist un the point format
Expand All @@ -179,8 +185,7 @@ def dimension_by_name(self, name: str) -> dims.DimensionInfo:
raise ValueError(f"Dimension '{name}' does not exist")

def add_extra_dimension(self, param: ExtraBytesParams) -> None:
""" Add an extra, user-defined dimension
"""
"""Add an extra, user-defined dimension"""
dim_info = dims.DimensionInfo.from_type_str(
param.name,
param.type,
Expand All @@ -190,8 +195,8 @@ def add_extra_dimension(self, param: ExtraBytesParams) -> None:
scales=param.scales,
)
if (
dim_info.num_elements > 3
and dim_info.kind != dims.DimensionKind.UnsignedInteger
dim_info.num_elements > 3
and dim_info.kind != dims.DimensionKind.UnsignedInteger
):
raise PylasError("Extra Dimensions do not support more than 3 elements")
self.dimensions.append(dim_info)
Expand Down
6 changes: 3 additions & 3 deletions pylas/point/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import numpy as np

from . import dims, packing
from .dims import SubFieldView, ScaledArrayView
from . import dims
from .dims import ScaledArrayView
from .. import errors
from ..point import PointFormat

Expand Down Expand Up @@ -225,7 +225,7 @@ def __repr__(self):
)


def apply_new_scaling(record, scales, offsets) -> None:
def apply_new_scaling(record, scales: np.ndarray, offsets: np.ndarray) -> None:
record["X"] = unscale_dimension(np.asarray(record.x), scales[0], offsets[0])
record["Y"] = unscale_dimension(np.asarray(record.y), scales[1], offsets[1])
record["Z"] = unscale_dimension(np.asarray(record.x), scales[2], offsets[2])
Expand Down
2 changes: 1 addition & 1 deletion pylas/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def encode_to_len(string: str, wanted_len: int, codec='ascii') -> bytes:
def encode_to_len(string: str, wanted_len: int, codec="ascii") -> bytes:
encoded_str = string.encode(codec)

missing_bytes = wanted_len - len(encoded_str)
Expand Down
8 changes: 4 additions & 4 deletions pylas/vlrs/vlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def read_from(cls, stream: BinaryIO):

def __eq__(self, other):
return (
self.record_id == other.record_id
and self.user_id == other.user_id
and self.description == other.description
and self.record_data == other.record_data
self.record_id == other.record_id
and self.user_id == other.user_id
and self.description == other.description
and self.record_data == other.record_data
)

def __repr__(self):
Expand Down
4 changes: 2 additions & 2 deletions pylas/vlrs/vlrlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def index(self, value, start: int = 0, stop: int = None) -> int:
if stop is None:
stop = len(self)
if isinstance(value, str):
for i, vlr in enumerate(self[start: stop]):
for i, vlr in enumerate(self[start:stop]):
if vlr.__class__.__name__ == value:
return i + start
else:
Expand Down Expand Up @@ -137,7 +137,7 @@ def __repr__(self):

@classmethod
def read_from(
cls, data_stream: BinaryIO, num_to_read: int, extended: bool = False
cls, data_stream: BinaryIO, num_to_read: int, extended: bool = False
) -> "VLRList":
"""Reads vlrs and parse them if possible from the stream
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"pytest",
"sphinx",
"sphinx-rtd-theme",
"nox"
"nox",
"black"
],
"lazrs": [
"lazrs>=0.2.3, < 0.3.0"
Expand Down

0 comments on commit 1819e98

Please sign in to comment.