Skip to content

Commit b43861c

Browse files
authored
Fix tagging via patch of generated source distribution file name (#36383)
* building sdist now results in old style formatting of the file names even with new setuptools
1 parent 2d7012f commit b43861c

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
"contosodataset",
199199
"centralus",
200200
"centraluseuap",
201+
"corehttp",
201202
"creds",
202203
"ctoring",
203204
"ctxt",

eng/pipelines/templates/steps/build-package-artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ steps:
5757

5858
- pwsh: |
5959
which python
60-
python -m pip install --force -r eng\ci_tools.txt
60+
python -m pip install --force -r eng/ci_tools.txt
6161
python -m pip freeze --all
6262
displayName: 'Prep Environment'
6363

eng/tox/tox_helper_tasks.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@ def unzip_sdist_to_directory(containing_folder: str) -> str:
2828
tars = glob.glob(os.path.join(containing_folder, "*.tar.gz"))
2929
return unzip_file_to_directory(tars[0], containing_folder)
3030

31-
3231
def unzip_file_to_directory(path_to_zip_file: str, extract_location: str) -> str:
3332
if path_to_zip_file.endswith(".zip"):
3433
with zipfile.ZipFile(path_to_zip_file, "r") as zip_ref:
3534
zip_ref.extractall(extract_location)
3635
extracted_dir = os.path.basename(os.path.splitext(path_to_zip_file)[0])
3736
return os.path.join(extract_location, extracted_dir)
38-
else:
39-
with tarfile.open(path_to_zip_file) as tar_ref:
37+
elif path_to_zip_file.endswith(".tar.gz") or path_to_zip_file.endswith(".tgz"):
38+
with tarfile.open(path_to_zip_file, "r:gz") as tar_ref:
4039
tar_ref.extractall(extract_location)
41-
extracted_dir = os.path.basename(path_to_zip_file).replace(".tar.gz", "")
42-
return os.path.join(extract_location, extracted_dir)
43-
40+
top_level_dir = None
41+
for member in tar_ref.getmembers():
42+
if member.isdir():
43+
top_level_dir = member.name.split('/')[0]
44+
break
45+
if top_level_dir:
46+
return os.path.join(extract_location, top_level_dir)
47+
else:
48+
raise ValueError("Failed to determine the top-level directory in the tar.gz archive")
49+
else:
50+
raise ValueError("Unsupported file format")
4451

4552
def move_and_rename(source_location):
4653
new_location = os.path.join(os.path.dirname(source_location), "unzipped")

tools/azure-sdk-tools/ci_tools/build.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,21 @@ def create_package(
189189

190190
if enable_sdist:
191191
run([sys.executable, "setup.py", "sdist", "-d", dist], cwd=setup_parsed.folder, check=True)
192+
193+
# The file normalization changes in setuptools 67.3.0 intends source distribution file names to have the
194+
# formatting a whl distributions. This patch avoids that for now.
195+
normalized_package_name = setup_parsed.name.replace("-", "_")
196+
generated_sdist_name = os.path.join(dist, f"{normalized_package_name}-{setup_parsed.version}.tar.gz")
197+
destination = generated_sdist_name.replace(normalized_package_name, setup_parsed.name)
198+
199+
# in cases where there is no reformatting necessary (sdk/core/corehttp is a good example)
200+
# skip this effort
201+
if generated_sdist_name != destination:
202+
if os.path.exists(generated_sdist_name):
203+
if os.path.exists(destination):
204+
os.remove(destination)
205+
206+
os.rename(generated_sdist_name, destination)
207+
else:
208+
logger.log(level=logging.ERROR, msg=f"Unable to find a source distribution for {setup_parsed.name} that could be renamed without normalization.")
209+

0 commit comments

Comments
 (0)