Skip to content

Commit 67ab121

Browse files
Allow the directory used for storing intermediate files to be changed via argument.
1 parent 692519d commit 67ab121

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

scripts/changesummary.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ class ChangeSummary:
4949
artifacts.
5050
"""
5151

52-
def __init__(self, new_artifacts_dir, current_artifacts_dir, file_list):
52+
def __init__(self, new_artifacts_dir, current_artifacts_dir, temp_dir, file_list):
5353
"""Initializes an instance of a ChangeSummary.
5454
5555
Args:
5656
new_artifacts_dir (str): The relative path to the directory with the
5757
new discovery artifacts.
5858
current_artifacts_dir (str): The relative path to the directory with
5959
the current discovery artifacts.
60+
temp_dir (str): The relative path to the directory used for
61+
temporary storage where intermediate files will be stored.
6062
file_list (list): A list of strings containing files to analyze.
6163
"""
6264
if file_list is None:
@@ -65,6 +67,7 @@ def __init__(self, new_artifacts_dir, current_artifacts_dir, file_list):
6567
self._file_list = file_list
6668
self._new_artifacts_dir = new_artifacts_dir
6769
self._current_artifacts_dir = current_artifacts_dir
70+
self._temp_dir = temp_dir
6871

6972
# Sanity checks to ensure artifact directories exist
7073
self._raise_if_artifacts_dir_not_found(self._new_artifacts_dir)
@@ -497,16 +500,15 @@ def detect_discovery_changes(self):
497500
sort_columns = ["Name", "Version", "ChangeType", "Key"]
498501
result.sort_values(by=sort_columns, ascending=True, inplace=True)
499502

500-
# Create a temp/ folder which be used by the `createcommits.sh` and
501-
# `buildprbody.py` scripts
502-
temp_folder = "temp/"
503-
os.makedirs(os.path.dirname(temp_folder), exist_ok=True)
503+
# Create a folder which be used by the `createcommits.sh` and
504+
# `buildprbody.py` scripts.
505+
os.makedirs(os.path.dirname(self._temp_dir), exist_ok=True)
504506

505507
# Create a summary which contains a conventional commit message
506508
# for each API and write it to disk.
507-
summary_df = self._get_summary_and_write_to_disk(result, temp_folder)
509+
summary_df = self._get_summary_and_write_to_disk(result, self._temp_dir)
508510

509511
# Create verbose change information for each API which contains
510512
# a list of changes by key and write it to disk.
511-
self._write_verbose_changes_to_disk(result, temp_folder, summary_df)
513+
self._write_verbose_changes_to_disk(result, self._temp_dir, summary_df)
512514

scripts/updatediscoveryartifacts.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020
import describe
2121
import changesummary
2222

23-
DISCOVERY_DOC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
24-
'../googleapiclient/discovery_cache/documents')
25-
REFERENCE_DOC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
26-
'../docs/dyn')
23+
SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__))
24+
DISCOVERY_DOC_DIR = os.path.join(SCRIPTS_DIR, '../googleapiclient/discovery_cache/documents')
25+
REFERENCE_DOC_DIR = os.path.join(SCRIPTS_DIR, '../docs/dyn')
26+
TEMP_DIR = os.path.join(SCRIPTS_DIR, 'temp')
2727

2828
# Clear discovery documents and reference documents directory
2929
shutil.rmtree(DISCOVERY_DOC_DIR, ignore_errors=True)
3030
shutil.rmtree(REFERENCE_DOC_DIR, ignore_errors=True)
3131

3232
# Clear temporary directory
33-
shutil.rmtree('temp', ignore_errors=True)
33+
shutil.rmtree(TEMP_DIR, ignore_errors=True)
3434

3535
# Check out a fresh copy
3636
subprocess.call(['git', 'checkout', DISCOVERY_DOC_DIR])
3737
subprocess.call(['git', 'checkout', REFERENCE_DOC_DIR])
3838

3939
# Snapshot current discovery artifacts to a temporary directory
40-
with tempfile.TemporaryDirectory() as tmpdirname:
41-
shutil.copytree(DISCOVERY_DOC_DIR, tmpdirname, dirs_exist_ok=True)
40+
with tempfile.TemporaryDirectory() as current_discovery_doc_dir:
41+
shutil.copytree(DISCOVERY_DOC_DIR, current_discovery_doc_dir, dirs_exist_ok=True)
4242

4343
# Download discovery artifacts and generate documentation
4444
describe.generate_all_api_documents()
@@ -59,9 +59,12 @@
5959
all_changed_files = [os.path.basename(file_name) for file_name in git_diff_output.split('\n')]
6060
json_changed_files = [file for file in all_changed_files if file.endswith(".json")]
6161

62+
# Create temporary directory
63+
os.mkdir(TEMP_DIR)
64+
6265
# Analyze the changes in discovery artifacts using the changesummary module
63-
changesummary.ChangeSummary(DISCOVERY_DOC_DIR, tmpdirname, json_changed_files).detect_discovery_changes()
66+
changesummary.ChangeSummary(DISCOVERY_DOC_DIR, current_discovery_doc_dir, TEMP_DIR, json_changed_files).detect_discovery_changes()
6467

6568
# Write a list of the files changed to a file called `changed files` which will be used in the `createcommits.sh` script.
66-
with open(os.path.join("temp", "changed_files"), "w") as f:
69+
with open(os.path.join(TEMP_DIR, "changed_files"), "w") as f:
6770
f.writelines('\n'.join(all_changed_files))

0 commit comments

Comments
 (0)