Skip to content
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
4 changes: 2 additions & 2 deletions autoconf/directory_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def keys(self):
[
path != "priors",
len(path.split(".")[0]) != 0,
os.path.isdir(f"{self.path}/{path}")
(self.path / path).is_dir()
or path.endswith(".ini")
or path.endswith(".yaml")
or path.endswith(".yml"),
Expand Down Expand Up @@ -204,7 +204,7 @@ def _getitem(self, item):
yaml_name = f"{item}.yaml"
if yaml_name in listing:
return YAMLConfig(self.path / yaml_name)
if item in listing and os.path.isdir(self.path / item):
if item in listing and (self.path / item).is_dir():
return RecursiveConfig(self.path / item)
raise KeyError(f"No configuration found for {item} at path {self.path}")

Expand Down
7 changes: 3 additions & 4 deletions autoconf/json_prior/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import json
import logging
import os
from os import path
from importlib import util
from pathlib import Path

Expand Down Expand Up @@ -51,9 +50,9 @@ def generate(directory: str):
directory
The directory for which prior are generated
"""
cwd = Path(os.getcwd())
cwd = Path.cwd()
try:
os.mkdir(path.join(cwd, "priors"))
(cwd / "priors").mkdir()
except FileExistsError:
pass
for directory, _, files in os.walk(directory):
Expand All @@ -64,7 +63,7 @@ def generate(directory: str):
spec = for_file(full_path)
config_path = cwd / "priors" / file.replace(".py", ".json")
if len(spec) > 0:
if os.path.exists(config_path):
if config_path.exists():
logger.info(f"{config_path} already exists")
continue
with open(config_path, "w+") as f:
Expand Down
5 changes: 3 additions & 2 deletions autoconf/setup_colab.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from pathlib import Path
os.environ['XLA_FLAGS'] = "--xla_disable_hlo_passes=constant_folding"

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -103,8 +104,8 @@ def _colab_setup(
os.chdir(workspace_dir)

conf.instance.push(
new_path=os.path.join(workspace_dir, "config"),
output_path=os.path.join(workspace_dir, "output"),
new_path=Path(workspace_dir) / "config",
output_path=Path(workspace_dir) / "output",
)

print(
Expand Down
4 changes: 2 additions & 2 deletions test_autoconf/test_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import shutil
from os import path
from pathlib import Path

import pytest

Expand All @@ -9,7 +9,7 @@
from autoconf.mock.mock_real import EllProfile, Gaussian
from autoconf.exc import ConfigException

directory = path.dirname(path.realpath(__file__))
directory = Path(__file__).resolve().parent


class MockClass:
Expand Down
25 changes: 12 additions & 13 deletions test_autoconf/test_fitsable.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
from astropy.io import fits
import numpy as np
import os
from os import path
from pathlib import Path

from autoconf import conf
from autoconf import fitsable

test_path = "{}".format(path.dirname(path.realpath(__file__)))
test_path = Path(__file__).resolve().parent

test_data_path = os.path.join(
"{}".format(os.path.dirname(os.path.realpath(__file__))), "files"
)
test_data_path = Path(__file__).resolve().parent / "files"


def create_fits(fits_path, array):
if path.exists(fits_path):
fits_path = Path(fits_path)
if fits_path.exists():
os.remove(fits_path)

hdu_list = fits.HDUList()
Expand All @@ -29,22 +28,22 @@ def create_fits(fits_path, array):

def test__ndarray_via_fits_from():
arr = fitsable.ndarray_via_fits_from(
file_path=os.path.join(test_data_path, "3x3_ones.fits"), hdu=0
file_path=test_data_path / "3x3_ones.fits", hdu=0
)

assert (arr == np.ones((3, 3))).all()

arr = fitsable.ndarray_via_fits_from(
file_path=os.path.join(test_data_path, "4x3_ones.fits"), hdu=0
file_path=test_data_path / "4x3_ones.fits", hdu=0
)

assert (arr == np.ones((4, 3))).all()


def test__output_to_fits():
file_path = os.path.join(test_data_path, "array_out.fits")
file_path = test_data_path / "array_out.fits"

if os.path.exists(file_path):
if file_path.exists():
os.remove(file_path)

arr = np.array([[10.0, 30.0, 40.0], [92.0, 19.0, 20.0]])
Expand All @@ -57,9 +56,9 @@ def test__output_to_fits():


def test__output_to_fits__header_dict():
file_path = os.path.join(test_data_path, "array_out.fits")
file_path = test_data_path / "array_out.fits"

if os.path.exists(file_path):
if file_path.exists():
os.remove(file_path)

arr = np.array([[10.0, 30.0, 40.0], [92.0, 19.0, 20.0]])
Expand All @@ -73,7 +72,7 @@ def test__output_to_fits__header_dict():

def test__header_obj_from():
header_obj = fitsable.header_obj_from(
file_path=os.path.join(test_data_path, "3x3_ones.fits"), hdu=0
file_path=test_data_path / "3x3_ones.fits", hdu=0
)

assert isinstance(header_obj, fits.header.Header)
Expand Down
Loading