Skip to content

Commit 597b2b6

Browse files
authored
[MAINTENANCE] add ruff use-pathlib PTH noqa comments (great-expectations#7290)
These changes will be added to `.git-blame-ignore-revs`
1 parent 466ac70 commit 597b2b6

File tree

60 files changed

+969
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+969
-621
lines changed

docs_rtd/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from sphinx.ext.autodoc import between
2424

25-
sys.path.insert(0, os.path.abspath("../"))
25+
sys.path.insert(0, os.path.abspath("../")) # noqa: PTH100
2626

2727

2828
# -- General configuration ------------------------------------------------

great_expectations/_version.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
117117
rootdirs = []
118118

119119
for i in range(3):
120-
dirname = os.path.basename(root)
120+
dirname = os.path.basename(root) # noqa: PTH119
121121
if dirname.startswith(parentdir_prefix):
122122
return {
123123
"version": dirname[len(parentdir_prefix) :],
@@ -128,7 +128,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
128128
}
129129
else:
130130
rootdirs.append(root)
131-
root = os.path.dirname(root) # up a level
131+
root = os.path.dirname(root) # up a level # noqa: PTH120
132132

133133
if verbose:
134134
print(
@@ -525,7 +525,7 @@ def get_versions():
525525
# tree (where the .git directory might live) to this file. Invert
526526
# this to find the root from __file__.
527527
for _ in cfg.versionfile_source.split("/"):
528-
root = os.path.dirname(root)
528+
root = os.path.dirname(root) # noqa: PTH120
529529
except NameError:
530530
return {
531531
"version": "0+unknown",

great_expectations/cli/checkpoint.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def _verify_checkpoint_does_not_exist(
165165

166166

167167
def _get_notebook_path(context: DataContext, notebook_name: str) -> str:
168-
return os.path.abspath(
169-
os.path.join(
168+
return os.path.abspath( # noqa: PTH100
169+
os.path.join( # noqa: PTH118
170170
context.root_directory, context.GX_EDIT_NOTEBOOK_DIR, notebook_name
171171
)
172172
)
@@ -327,11 +327,11 @@ def checkpoint_script(ctx: click.Context, checkpoint: str) -> None:
327327
)
328328

329329
script_name: str = f"run_{checkpoint}.py"
330-
script_path: str = os.path.join(
330+
script_path: str = os.path.join( # noqa: PTH118
331331
context.root_directory, context.GX_UNCOMMITTED_DIR, script_name
332332
)
333333

334-
if os.path.isfile(script_path):
334+
if os.path.isfile(script_path): # noqa: PTH113
335335
toolkit.exit_with_failure_message_and_stats(
336336
data_context=context,
337337
usage_event=usage_event_end,
@@ -359,7 +359,9 @@ def checkpoint_script(ctx: click.Context, checkpoint: str) -> None:
359359
def _write_checkpoint_script_to_disk(
360360
context_directory: str, checkpoint_name: str, script_path: str
361361
) -> None:
362-
script_full_path: str = os.path.abspath(os.path.join(script_path))
362+
script_full_path: str = os.path.abspath( # noqa: PTH100
363+
os.path.join(script_path) # noqa: PTH118
364+
)
363365
template: str = _load_script_template().format(checkpoint_name, context_directory)
364366
linted_code: str = lint_code(code=template)
365367
with open(script_full_path, "w") as f:

great_expectations/cli/datasource.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def verify_libraries_installed(self) -> bool:
270270
def create_notebook(self, context: FileDataContext) -> str:
271271
"""Create a datasource_new notebook and save it to disk."""
272272
renderer = self.get_notebook_renderer(context)
273-
notebook_path = os.path.join(
273+
notebook_path = os.path.join( # noqa: PTH118
274274
context.root_directory,
275275
context.GX_UNCOMMITTED_DIR,
276276
"datasource_new.ipynb",

great_expectations/cli/init.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def init(ctx: click.Context, usage_stats: bool) -> None:
5757
config_file_location=ctx.obj.config_file_location
5858
).get("directory")
5959
if directory is None:
60-
directory = os.getcwd()
61-
target_directory = os.path.abspath(directory)
60+
directory = os.getcwd() # noqa: PTH109
61+
target_directory = os.path.abspath(directory) # noqa: PTH100
6262
ge_dir = _get_full_path_to_ge_dir(target_directory)
6363
cli_message(GREETING)
6464

@@ -121,4 +121,6 @@ def init(ctx: click.Context, usage_stats: bool) -> None:
121121

122122

123123
def _get_full_path_to_ge_dir(target_directory: str) -> str:
124-
return os.path.abspath(os.path.join(target_directory, FileDataContext.GX_DIR))
124+
return os.path.abspath( # noqa: PTH100
125+
os.path.join(target_directory, FileDataContext.GX_DIR) # noqa: PTH118
126+
)

great_expectations/cli/python_subprocess.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def execute_shell_command(command: str) -> int:
2020
:param command: bash command -- as if typed in a shell/Terminal window
2121
:return: status code -- 0 if successful; all other values (1 is the most common) indicate an error
2222
"""
23-
cwd: str = os.getcwd()
23+
cwd: str = os.getcwd() # noqa: PTH109
2424

2525
path_env_var: str = os.pathsep.join([os.environ.get("PATH", os.defpath), cwd])
2626
env: dict = dict(os.environ, PATH=path_env_var)
@@ -66,7 +66,7 @@ def execute_shell_command_with_progress_polling(command: str) -> int:
6666
:param command: bash command -- as if typed in a shell/Terminal window
6767
:return: status code -- 0 if successful; all other values (1 is the most common) indicate an error
6868
"""
69-
cwd: str = os.getcwd()
69+
cwd: str = os.getcwd() # noqa: PTH109
7070

7171
path_env_var: str = os.pathsep.join([os.environ.get("PATH", os.defpath), cwd])
7272
env: dict = dict(os.environ, PATH=path_env_var)

great_expectations/cli/suite.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,8 @@ def suite_list(ctx: click.Context) -> None:
978978

979979

980980
def _get_notebook_path(context: DataContext, notebook_name: str) -> str:
981-
return os.path.abspath(
982-
os.path.join(
981+
return os.path.abspath( # noqa: PTH100
982+
os.path.join( # noqa: PTH118
983983
context.root_directory, context.GX_EDIT_NOTEBOOK_DIR, notebook_name
984984
)
985985
)

great_expectations/cli/upgrade_helpers/upgrade_helper_v11.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def _get_tuple_filesystem_store_backend_run_time(
362362
"%Y%m%dT%H%M%S.%fZ"
363363
)
364364
except (ValueError, TypeError):
365-
source_path = os.path.join(
365+
source_path = os.path.join( # noqa: PTH118
366366
store_backend.full_base_directory,
367367
store_backend._convert_key_to_filepath(source_key),
368368
)
@@ -387,7 +387,9 @@ def _get_tuple_s3_store_backend_run_time(
387387
except (ValueError, TypeError):
388388
source_path = store_backend._convert_key_to_filepath(source_key)
389389
if not source_path.startswith(store_backend.prefix):
390-
source_path = os.path.join(store_backend.prefix, source_path)
390+
source_path = os.path.join( # noqa: PTH118
391+
store_backend.prefix, source_path
392+
)
391393
source_object = s3.Object(store_backend.bucket, source_path)
392394
source_object_last_mod = source_object.last_modified.strftime(
393395
"%Y%m%dT%H%M%S.%fZ"
@@ -411,7 +413,9 @@ def _get_tuple_gcs_store_backend_run_time(
411413
except (ValueError, TypeError):
412414
source_path = store_backend._convert_key_to_filepath(source_key)
413415
if not source_path.startswith(store_backend.prefix):
414-
source_path = os.path.join(store_backend.prefix, source_path)
416+
source_path = os.path.join( # noqa: PTH118
417+
store_backend.prefix, source_path
418+
)
415419
source_blob_created_time = bucket.get_blob(
416420
source_path
417421
).time_created.strftime("%Y%m%dT%H%M%S.%fZ")
@@ -612,15 +616,15 @@ def _save_upgrade_log(self) -> str:
612616
current_time = datetime.datetime.now(datetime.timezone.utc).strftime(
613617
"%Y%m%dT%H%M%S.%fZ"
614618
)
615-
dest_path = os.path.join(
619+
dest_path = os.path.join( # noqa: PTH118
616620
self.data_context._context_root_directory,
617621
"uncommitted",
618622
"logs",
619623
"project_upgrades",
620624
f"UpgradeHelperV11_{current_time}.json",
621625
)
622626
dest_dir, dest_filename = os.path.split(dest_path)
623-
os.makedirs(dest_dir, exist_ok=True)
627+
os.makedirs(dest_dir, exist_ok=True) # noqa: PTH103
624628

625629
with open(dest_path, "w") as outfile:
626630
json.dump(self.upgrade_log, outfile, indent=2)

great_expectations/cli/upgrade_helpers/upgrade_helper_v13.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,15 @@ def _save_upgrade_log(self):
440440
current_time = datetime.datetime.now(datetime.timezone.utc).strftime(
441441
"%Y%m%dT%H%M%S.%fZ"
442442
)
443-
dest_path = os.path.join(
443+
dest_path = os.path.join( # noqa: PTH118
444444
self.data_context.root_directory,
445445
"uncommitted",
446446
"logs",
447447
"project_upgrades",
448448
f"UpgradeHelperV13_{current_time}.json",
449449
)
450450
dest_dir, dest_filename = os.path.split(dest_path)
451-
os.makedirs(dest_dir, exist_ok=True)
451+
os.makedirs(dest_dir, exist_ok=True) # noqa: PTH103
452452

453453
with open(dest_path, "w") as outfile:
454454
json.dump(self.upgrade_log, outfile, indent=2)

great_expectations/cli/v012/checkpoint.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,14 @@ def _write_checkpoint_to_disk(
151151
context: DataContext, checkpoint: Dict, checkpoint_name: str
152152
) -> str:
153153
# TODO this should be the responsibility of the DataContext
154-
checkpoint_dir = os.path.join(
154+
checkpoint_dir = os.path.join( # noqa: PTH118
155155
context.root_directory,
156156
DataContextConfigDefaults.CHECKPOINTS_BASE_DIRECTORY.value,
157157
)
158-
checkpoint_file = os.path.join(checkpoint_dir, f"{checkpoint_name}.yml")
159-
os.makedirs(checkpoint_dir, exist_ok=True)
158+
checkpoint_file = os.path.join( # noqa: PTH118
159+
checkpoint_dir, f"{checkpoint_name}.yml"
160+
)
161+
os.makedirs(checkpoint_dir, exist_ok=True) # noqa: PTH103
160162
with open(checkpoint_file, "w") as f:
161163
yaml.dump(checkpoint, f)
162164
return checkpoint_file
@@ -165,7 +167,8 @@ def _write_checkpoint_to_disk(
165167
def _load_checkpoint_yml_template() -> dict:
166168
# TODO this should be the responsibility of the DataContext
167169
template_file = file_relative_path(
168-
__file__, os.path.join("..", "data_context", "checkpoint_template.yml")
170+
__file__,
171+
os.path.join("..", "data_context", "checkpoint_template.yml"), # noqa: PTH118
169172
)
170173
with open(template_file) as f:
171174
template = yaml.load(f)
@@ -315,11 +318,11 @@ def checkpoint_script(checkpoint, directory) -> None:
315318
_ = toolkit.load_checkpoint(context, checkpoint, usage_event)
316319

317320
script_name = f"run_{checkpoint}.py"
318-
script_path = os.path.join(
321+
script_path = os.path.join( # noqa: PTH118
319322
context.root_directory, context.GX_UNCOMMITTED_DIR, script_name
320323
)
321324

322-
if os.path.isfile(script_path):
325+
if os.path.isfile(script_path): # noqa: PTH113
323326
toolkit.exit_with_failure_message_and_stats(
324327
context,
325328
usage_event,
@@ -350,7 +353,9 @@ def _load_script_template() -> str:
350353
def _write_checkpoint_script_to_disk(
351354
context_directory: str, checkpoint_name: str, script_path: str
352355
) -> None:
353-
script_full_path = os.path.abspath(os.path.join(script_path))
356+
script_full_path = os.path.abspath( # noqa: PTH100
357+
os.path.join(script_path) # noqa: PTH118
358+
)
354359
template = _load_script_template().format(checkpoint_name, context_directory)
355360
linted_code = lint_code(template)
356361
with open(script_full_path, "w") as f:

great_expectations/cli/v012/datasource.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def _add_pandas_datasource(
413413
else:
414414
basenamepath = path
415415

416-
datasource_name = f"{os.path.basename(basenamepath)}__dir"
416+
datasource_name = f"{os.path.basename(basenamepath)}__dir" # noqa: PTH119
417417
if prompt_for_datasource_name:
418418
datasource_name = click.prompt(
419419
msg_prompt_datasource_name, default=datasource_name
@@ -423,7 +423,7 @@ def _add_pandas_datasource(
423423
batch_kwargs_generators={
424424
"subdir_reader": {
425425
"class_name": "SubdirReaderBatchKwargsGenerator",
426-
"base_directory": os.path.join("..", path),
426+
"base_directory": os.path.join("..", path), # noqa: PTH118
427427
}
428428
}
429429
)
@@ -911,7 +911,7 @@ def _add_spark_datasource(
911911
else:
912912
basenamepath = path
913913

914-
datasource_name = f"{os.path.basename(basenamepath)}__dir"
914+
datasource_name = f"{os.path.basename(basenamepath)}__dir" # noqa: PTH119
915915
if prompt_for_datasource_name:
916916
datasource_name = click.prompt(
917917
msg_prompt_datasource_name, default=datasource_name
@@ -921,7 +921,7 @@ def _add_spark_datasource(
921921
batch_kwargs_generators={
922922
"subdir_reader": {
923923
"class_name": "SubdirReaderBatchKwargsGenerator",
924-
"base_directory": os.path.join("..", path),
924+
"base_directory": os.path.join("..", path), # noqa: PTH118
925925
}
926926
}
927927
)
@@ -1195,7 +1195,7 @@ def _get_batch_kwargs_from_generator_or_from_file_path( # noqa: C901 - 26
11951195
)
11961196

11971197
if not path.startswith("gs:") and not path.startswith("s3"):
1198-
path = os.path.abspath(path)
1198+
path = os.path.abspath(path) # noqa: PTH100
11991199

12001200
batch_kwargs = {"path": path, "datasource": datasource_name}
12011201

great_expectations/cli/v012/init.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def init(target_directory, view, usage_stats) -> None: # noqa: C901 - 21
7070
It scaffolds directories, sets up notebooks, creates a project file, and
7171
appends to a `.gitignore` file.
7272
"""
73-
target_directory = os.path.abspath(target_directory)
73+
target_directory = os.path.abspath(target_directory) # noqa: PTH100
7474
ge_dir = _get_full_path_to_ge_dir(target_directory)
7575
cli_message(GREETING)
7676

@@ -222,4 +222,6 @@ def _slack_setup(context):
222222

223223

224224
def _get_full_path_to_ge_dir(target_directory):
225-
return os.path.abspath(os.path.join(target_directory, FileDataContext.GX_DIR))
225+
return os.path.abspath( # noqa: PTH100
226+
os.path.join(target_directory, FileDataContext.GX_DIR) # noqa: PTH118
227+
)

great_expectations/cli/v012/python_subprocess.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def execute_shell_command(command: str) -> int:
2020
:param command: bash command -- as if typed in a shell/Terminal window
2121
:return: status code -- 0 if successful; all other values (1 is the most common) indicate an error
2222
"""
23-
cwd: str = os.getcwd()
23+
cwd: str = os.getcwd() # noqa: PTH109
2424

2525
path_env_var: str = os.pathsep.join([os.environ.get("PATH", os.defpath), cwd])
2626
env: dict = dict(os.environ, PATH=path_env_var)
@@ -66,7 +66,7 @@ def execute_shell_command_with_progress_polling(command: str) -> int:
6666
:param command: bash command -- as if typed in a shell/Terminal window
6767
:return: status code -- 0 if successful; all other values (1 is the most common) indicate an error
6868
"""
69-
cwd: str = os.getcwd()
69+
cwd: str = os.getcwd() # noqa: PTH109
7070

7171
path_env_var: str = os.pathsep.join([os.environ.get("PATH", os.defpath), cwd])
7272
env: dict = dict(os.environ, PATH=path_env_var)

great_expectations/cli/v012/suite.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def _suite_scaffold(suite: str, directory: str, jupyter: bool) -> None:
461461

462462
if suite_name in context.list_expectation_suite_names():
463463
toolkit.tell_user_suite_exists(suite_name)
464-
if os.path.isfile(notebook_path):
464+
if os.path.isfile(notebook_path): # noqa: PTH113
465465
cli_message(
466466
f" - If you wish to adjust your scaffolding, you can open this notebook with jupyter: `{notebook_path}` <red>(Please note that if you run that notebook, you will overwrite your existing suite.)</red>"
467467
)
@@ -551,8 +551,8 @@ def suite_list(directory):
551551

552552

553553
def _get_notebook_path(context, notebook_name):
554-
return os.path.abspath(
555-
os.path.join(
554+
return os.path.abspath( # noqa: PTH100
555+
os.path.join( # noqa: PTH118
556556
context.root_directory, context.GX_EDIT_NOTEBOOK_DIR, notebook_name
557557
)
558558
)

great_expectations/core/config_provider.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ def get_values(self) -> Dict[str, str]:
148148
defined_path: str = self._substitutor.substitute_config_variable( # type: ignore[assignment]
149149
self._config_variables_file_path, env_vars
150150
)
151-
if not os.path.isabs(defined_path):
151+
if not os.path.isabs(defined_path): # noqa: PTH117
152152
root_directory: str = self._root_directory or os.curdir
153153
else:
154154
root_directory = ""
155155

156-
var_path = os.path.join(root_directory, defined_path)
156+
var_path = os.path.join(root_directory, defined_path) # noqa: PTH118
157157
with open(var_path) as config_variables_file:
158158
contents = config_variables_file.read()
159159

great_expectations/data_asset/file_data_asset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ def expect_file_to_exist(
554554
:ref:`include_config`, :ref:`catch_exceptions`, and :ref:`meta`.
555555
"""
556556

557-
if filepath is not None and os.path.isfile(filepath):
557+
if filepath is not None and os.path.isfile(filepath): # noqa: PTH113
558558
success = True
559-
elif self._path is not None and os.path.isfile(self._path):
559+
elif self._path is not None and os.path.isfile(self._path): # noqa: PTH113
560560
success = True
561561
else:
562562
success = False

0 commit comments

Comments
 (0)