`compact_aaz.py` fails if path is too long
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 3.5k
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 60
Description
### Describe the bug
This script fails if the `azure-cli` repo's path is long.
```
DEBUG:__main__:Writing python file C:\Users\kkxxxxx\Developer\azure-cli\build_scripts\windows\artifacts\cli\Lib\site-packages\azure\cli\command_modules\network\aaz_compact\latest\network\application_gateway\waf_policy\custom_rule\match_condition\__init__.py
Traceback (most recent call last):
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 464, in
compactor.compact()
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 157, in compact
self.compact_sub_resource_groups(ctx, profile_mod_name)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 187, in compact_sub_resource_groups
self.compact_resource_group(ctx, sub_dir)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 200, in compact_resource_group
self.compact_sub_resource_groups(ctx, dirs)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 187, in compact_sub_resource_groups
self.compact_resource_group(ctx, sub_dir)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 200, in compact_resource_group
self.compact_sub_resource_groups(ctx, dirs)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 187, in compact_sub_resource_groups
self.compact_resource_group(ctx, sub_dir)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 200, in compact_resource_group
self.compact_sub_resource_groups(ctx, dirs)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 187, in compact_sub_resource_groups
self.compact_resource_group(ctx, sub_dir)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 200, in compact_resource_group
self.compact_sub_resource_groups(ctx, dirs)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 187, in compact_sub_resource_groups
self.compact_resource_group(ctx, sub_dir)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 199, in compact_resource_group
self.compact_resource_group_commands(ctx, dirs)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 261, in compact_resource_group_commands
self._write_py_file(os.path.join(compact_folder, '__init__.py'), content=init_content)
File "C:\Users\kkxxxxx\Developer\azure-cli\scripts\compact_aaz.py", line 173, in _write_py_file
py_compile.compile(path)
File "py_compile.py", line 172, in compile
File "", line 191, in _write_atomic
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\kkxxxxx\\Developer\\azure-cli\\build_scripts\\windows\\artifacts\\cli\\Lib\\site-packages\\azure\\cli\\command_modules\\network\\aaz_compact\\latest\\network\\application_gateway\\waf_policy\\custom_rule\\match_condition\\__pycache__\\__init__.cpython-311.pyc.2276667489168'
```
This is similar to this bug https://bugs.python.org/issue14599, which is triggered by the long import path.
`C:\Users\kkxxxxx\Developer\azure-cli\build_scripts\windows\artifacts\cli\Lib\site-packages\azure\cli\command_modules\network\aaz_compact\latest\network\application_gateway\waf_policy\custom_rule\match_condition\__pycache__\__init__.cpython-311.pyc.2276667489168` is **261** chars, which greater than the [Maximum Path Length Limitation](https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#maximum-path-length-limitation) **260** on Windows.
(If you want to write that file in Python, the same error is raised)
If `aaz\latest\network\application_gateway\waf_policy\custom_rule\match_condition` folder is renamed to `aaz\latest\network\application_gateway\waf_policy\custom_rule\match`, the error disappears.
Contributor guide
Assessment
This issue has not been assessed yet.