Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathlib everywhere #1773

Merged
merged 18 commits into from
Jul 20, 2023
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 .github/actions/publish-from-template/render_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pathlib
import sys
from pathlib import Path

import jinja2

Expand All @@ -13,5 +13,5 @@ def main(template_path):


if __name__ == "__main__":
template_path = pathlib.Path(sys.argv[1])
template_path = Path(sys.argv[1])
main(template_path)
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,15 @@ Source = "https://github.com/nebari-dev/nebari"
nebari = "_nebari.cli.main:app"

[tool.ruff]
select = [
"E",
"F",
"PTH",
]
ignore = [
"E501", # Line too long
"F821", # Undefined name
"PTH123", # open() should be replaced by Path.open()
]
extend-exclude = [
"src/_nebari/template",
Expand Down
4 changes: 2 additions & 2 deletions scripts/aws-force-destroy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import logging
import pathlib
import time
from pathlib import Path

from _nebari.utils import check_cloud_credentials, load_yaml, timer

Expand All @@ -17,7 +17,7 @@ def main():


def handle_force_destroy(args):
config_filename = pathlib.Path(args.config)
config_filename = Path(args.config)
if not config_filename.is_file():
raise ValueError(
f"passed in configuration filename={config_filename} must exist"
Expand Down
19 changes: 10 additions & 9 deletions scripts/helm-validate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import json
import logging
import os
import pathlib
import re
from pathlib import Path

import hcl2
from tqdm import tqdm

from nebari.utils import deep_merge
from _nebari.utils import deep_merge

# Configure logging
logging.basicConfig(level=logging.INFO)
Expand All @@ -28,7 +28,7 @@ def get_filepaths_that_contain_helm_release(self):
"""Get list of helm charts from nebari code-base"""
# using pathlib to get list of files in the project root dir, look for all .tf files that
# contain helm_release
path = pathlib.Path(__file__).parent.parent.absolute()
path = Path(__file__).parent.parent.absolute()
path_tree = path.glob(f"{self.stages_dir}/**/main.tf")
paths = []
for file in path_tree:
Expand Down Expand Up @@ -72,7 +72,7 @@ def _load_variable_value(self, argument, parent_contents):
raise ValueError(f"Could not find variable {var_name}")

def retrieve_helm_information(self, filepath):
parent_path = pathlib.Path(filepath).parent
parent_path = Path(filepath).parent

if parent_path.name in self.skip_charts:
self.logger.debug(f"Skipping {parent_path.name}")
Expand Down Expand Up @@ -166,8 +166,9 @@ def pull_helm_chart(chart_index: dict, skip_charts: list) -> None:
Raises:
ValueError: If a chart could not be found in the `helm_charts` directory after pulling.
"""
chart_dir = "helm_charts"
os.makedirs(chart_dir, exist_ok=True)
chart_dir = Path("helm_charts")
chart_dir.mkdir(parents=True, exist_ok=True)

os.chdir(chart_dir)

for chart_name, chart_metadata in tqdm(
Expand All @@ -184,14 +185,14 @@ def pull_helm_chart(chart_index: dict, skip_charts: list) -> None:
f"helm pull {chart_name} --version {chart_version} --repo {chart_repository} --untar"
)

chart_filename = f"{chart_name}-{chart_version}.tgz"
if not os.path.exists(chart_filename):
chart_filename = Path(f"{chart_name}-{chart_version}.tgz")
if not chart_filename.exists():
raise ValueError(
f"Could not find {chart_name}:{chart_version} directory in {chart_dir}."
)

print("All charts downloaded successfully!")
# shutil.rmtree(pathlib.Path(os.getcwd()).parent / chart_dir)
# shutil.rmtree(Path(os.getcwd()).parent / chart_dir)


def add_workflow_job_summary(chart_index: dict):
Expand Down
4 changes: 2 additions & 2 deletions scripts/keycloak-export.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import argparse
import json
import logging
import pathlib
import sys
from pathlib import Path

from _nebari.keycloak import get_keycloak_admin_from_config

Expand All @@ -18,7 +18,7 @@ def main():


def handle_keycloak_export(args):
config_filename = pathlib.Path(args.config)
config_filename = Path(args.config)
if not config_filename.is_file():
raise ValueError(
f"passed in configuration filename={config_filename} must exist"
Expand Down
Loading