Skip to content

Commit

Permalink
refactor(anci.py, __init__.py): clean up and bring write to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
Taoning Wang committed Aug 16, 2023
1 parent b503976 commit e0865c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
14 changes: 5 additions & 9 deletions pyradiance/__init__.py
Expand Up @@ -8,7 +8,7 @@
import logging
import os

from .anci import BINPATH
from .anci import BINPATH, write

from .cal import (
cnt,
Expand Down Expand Up @@ -37,21 +37,15 @@
mkillum,
)

from .lib import (
ABASELIST,
BSDF,
read_rad,
get_view_resolu,
spec_xyz,
xyz_rgb
)
from .lib import ABASELIST, BSDF, read_rad, get_view_resolu, spec_xyz, xyz_rgb

from .model import (
Sensor,
Scene,
View,
Primitive,
load_views,
parse_view,
parse_primitive,
)

Expand Down Expand Up @@ -130,6 +124,7 @@
"oconv",
"pabopto2bsdf",
"parse_primitive",
"parse_view",
"pkgbsdf",
"pvalue",
"pvaluer",
Expand Down Expand Up @@ -161,6 +156,7 @@
"vwrays",
"WrapBSDFInput",
"wrapbsdf",
"write",
"xform",
"xyz_rgb",
]
20 changes: 11 additions & 9 deletions pyradiance/anci.py
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from functools import wraps
from subprocess import CalledProcessError
from typing import Union
import os

BINPATH = Path(__file__).parent / "bin"
Expand All @@ -29,13 +30,12 @@ def wrapper(*args, **kwargs):

return wrapper


def write(
file_path,
data,
overwrite=True,
mode='wb') -> str:
"""
Write data to a file.
file_path: Union[str, Path], data: Union[str, bytes], overwrite=True, mode="wb"
) -> str:
"""Write data to a file.
Args:
file_path: path to file
data: data to write
Expand All @@ -46,9 +46,11 @@ def write(
str: path to file
"""
if not overwrite and os.path.exists(file_path):
raise Exception(f'The path {file_path} already exists and '
f'"overwrite" has been set to False.')
raise Exception(
f"The path {file_path} already exists and "
f'"overwrite" has been set to False.'
)
else:
with open(file_path, mode=mode) as write_data:
write_data.write(data)
return file_path
return str(file_path)

0 comments on commit e0865c4

Please sign in to comment.