Skip to content

Commit

Permalink
Changes to account for #1832 and #1868
Browse files Browse the repository at this point in the history
  • Loading branch information
costrouc committed Aug 3, 2023
1 parent 0b4a192 commit aa6a93b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 26 deletions.
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ select = [
ignore = [
"E501", # Line too long
"F821", # Undefined name
"PTH101", # `os.chmod()` should be replaced by `Path.chmod()`
"PTH103", # `os.makedirs()` should be replaced by `Path.mkdir(parents=True)`
"PTH113", # os.path.isfile() -> Path.is_file()
"PTH118", # os.path.join() should be replaced by Path()
"PTH120", # `os.path.dirname()` should be replaced by `Path.parent`
"PTH123", # open() should be replaced by Path.open()
]
extend-exclude = [
Expand Down
2 changes: 1 addition & 1 deletion src/_nebari/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def deploy_configuration(
stage_outputs = {}
with contextlib.ExitStack() as stack:
for stage in stages:
s = stage(output_directory=pathlib.Path("."), config=config)
s = stage(output_directory=pathlib.Path.cwd(), config=config)
stack.enter_context(s.deploy(stage_outputs))

if not disable_checks:
Expand Down
2 changes: 1 addition & 1 deletion src/_nebari/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def destroy_configuration(config: schema.Main, stages: List[hookspecs.NebariStag
with contextlib.ExitStack() as stack:
for stage in stages:
try:
s = stage(output_directory=pathlib.Path("."), config=config)
s = stage(output_directory=pathlib.Path.cwd(), config=config)
stack.enter_context(s.destroy(stage_outputs, status))
except Exception as e:
status[s.name] = False
Expand Down
8 changes: 3 additions & 5 deletions src/_nebari/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,13 @@ def render_config(
config["terraform_state"] = {"type": terraform_state.value}

# Save default password to file
default_password_filename = os.path.join(
tempfile.gettempdir(), "NEBARI_DEFAULT_PASSWORD"
)
default_password_filename = pathlib.Path(tempfile.gettempdir()) / "NEBARI_DEFAULT_PASSWORD"
config["security"] = {
"keycloak": {"initial_root_password": random_secure_string(length=32)}
}
with open(default_password_filename, "w") as f:
with default_password_filename.open("w") as f:
f.write(config["security"]["keycloak"]["initial_root_password"])
os.chmod(default_password_filename, 0o700)
default_password_filename.chmod(0o700)

config["theme"] = {"jupyterhub": {"hub_title": f"Nebari - { project_name }"}}
config["theme"]["jupyterhub"][
Expand Down
12 changes: 7 additions & 5 deletions src/_nebari/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from _nebari.deprecate import DEPRECATED_FILE_PATHS
from nebari import hookspecs, schema
from _nebari.utils import is_relative_to


def render_template(
Expand Down Expand Up @@ -76,8 +77,8 @@ def render_template(
print("dry-run enabled no files will be created, updated, or deleted")
else:
for filename in new | updated:
output_filename = os.path.join(str(output_directory), filename)
os.makedirs(os.path.dirname(output_filename), exist_ok=True)
output_filename = output_directory / filename
output_filename.parent.mkdir(parents=True, exist_ok=True)

if isinstance(contents[filename], str):
with open(output_filename, "w") as f:
Expand Down Expand Up @@ -131,6 +132,7 @@ def list_files(
for path in directory.rglob("*"):
if not path.is_file():
continue
yield path

for filename in contents:
if isinstance(contents[filename], str):
Expand All @@ -140,8 +142,8 @@ def list_files(
else:
source_files[filename] = hashlib.sha256(contents[filename]).hexdigest()

output_filename = os.path.join(output_base_dir, filename)
if os.path.isfile(output_filename):
output_filename = pathlib.Path(output_base_dir) / filename
if output_filename.is_file():
output_files[filename] = hash_file(filename)

deleted_files = set()
Expand All @@ -152,7 +154,7 @@ def list_files(

for filename in list_files(output_base_dir, ignore_filenames, ignore_directories):
relative_path = os.path.relpath(filename, output_base_dir)
if os.path.isfile(filename):
if filename.is_file():
output_files[relative_path] = hash_file(filename)

new_files = source_files.keys() - output_files.keys()
Expand Down
17 changes: 8 additions & 9 deletions src/_nebari/stages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ def render(self) -> Dict[str, str]:
}
for root, dirs, filenames in os.walk(self.template_directory):
for filename in filenames:
with open(os.path.join(root, filename), "rb") as f:
contents[
os.path.join(
self.stage_prefix,
os.path.relpath(
os.path.join(root, filename), self.template_directory
),
)
] = f.read()
root_filename = pathlib.Path(root) / filename
with root_filename.open("rb") as f:
contents[pathlib.Path(
self.stage_prefix,
os.path.relpath(
root_filename, self.template_directory
),
)] = f.read()
return contents

def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
Expand Down
6 changes: 6 additions & 0 deletions src/_nebari/stages/kubernetes_services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ def input_vars(self, stage_outputs: Dict[str, Dict[str, Any]]):
"*/*": ["viewer"],
},
},
"argo-workflows-jupyter-scheduler": {
"primary_namespace": "",
"role_bindings": {
"*/*": ["viewer"],
},
},
}

# Compound any logout URLs from extensions so they are are logged out in succession
Expand Down
12 changes: 12 additions & 0 deletions src/_nebari/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,15 @@ def random_secure_string(
length: int = 16, chars: str = string.ascii_lowercase + string.digits
):
return "".join(secrets.choice(chars) for i in range(length))


def is_relative_to(self: pathlib.Path, other: pathlib.Path, /) -> bool:
"""Compatibility function to bring ``Path.is_relative_to`` to Python 3.8"""
if sys.version_info[:2] >= (3, 9):
return self.is_relative_to(other)

try:
self.relative_to(other)
return True
except ValueError:
return False

0 comments on commit aa6a93b

Please sign in to comment.