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

Commit

Permalink
Merge branch 'davidcaron-feature/support-pathlib'
Browse files Browse the repository at this point in the history
  • Loading branch information
tmontaigu committed Sep 11, 2020
2 parents a5ae92a + 966953e commit 6c16ead
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
7 changes: 4 additions & 3 deletions pylas/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io
import logging
import os
from pathlib import Path
from typing import Union

import numpy as np
Expand Down Expand Up @@ -97,7 +98,7 @@ def open_las(
"do_compress argument is not used when opening in read mode, "
"did you meant to open in write mode ?"
)
if isinstance(source, str):
if isinstance(source, (str, Path)):
stream = open(source, mode="rb", closefd=closefd)
elif isinstance(source, bytes):
stream = io.BytesIO(source)
Expand All @@ -108,7 +109,7 @@ def open_las(
if header is None:
raise ValueError("A header is needed when opening a file for writing")

if isinstance(source, str):
if isinstance(source, (str, Path)):
if do_compress is None:
do_compress = os.path.splitext(source)[1].lower() == ".laz"
stream = open(source, mode="wb+", closefd=closefd)
Expand All @@ -127,7 +128,7 @@ def open_las(
closefd=closefd,
)
elif mode == "a":
if isinstance(source, str):
if isinstance(source, (str, Path)):
stream = open(source, mode="rb+", closefd=closefd)
elif isinstance(source, bytes):
stream = io.BytesIO(source)
Expand Down
15 changes: 8 additions & 7 deletions pylastests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import os
from pathlib import Path

import numpy as np
import pytest

import pylas
from pylas.lib import write_then_read_again

simple_las = os.path.dirname(__file__) + "/" + "simple.las"
simple_laz = os.path.dirname(__file__) + "/" + "simple.laz"
vegetation1_3_las = os.path.dirname(__file__) + "/vegetation_1_3.las"
test1_4_las = os.path.dirname(__file__) + "/" + "test1_4.las"
extra_bytes_las = os.path.dirname(__file__) + "/extrabytes.las"
extra_bytes_laz = os.path.dirname(__file__) + "/extra.laz"
plane_laz = os.path.dirname(__file__) + "/plane.laz"
simple_las = Path(__file__).parent / "simple.las"
simple_laz = Path(__file__).parent / "simple.laz"
vegetation1_3_las = Path(__file__).parent / "vegetation_1_3.las"
test1_4_las = Path(__file__).parent / "test1_4.las"
extra_bytes_las = Path(__file__).parent / "extrabytes.las"
extra_bytes_laz = Path(__file__).parent / "extra.laz"
plane_laz = Path(__file__).parent / "plane.laz"

if not pylas.LazBackend.detect_available():
do_compression = [False]
Expand Down

0 comments on commit 6c16ead

Please sign in to comment.