Skip to content

Commit

Permalink
Fix Python logging.warn() deprecation warnings (microsoft#537)
Browse files Browse the repository at this point in the history
Updates `logging.warn()` to `logging.warning()` to prevent
deprecation warnings like this:

  .pytool\Plugin\UncrustifyCheck\UncrustifyCheck.py:386:
    DeprecationWarning: The 'warn' function is deprecated, use
    'warning' instead

- [ ] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

- Review Python code for `log.warn()` usage
- Check logs that reported issue earlier after changee

N/A

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
  • Loading branch information
makubacki authored and kenlautner committed Sep 21, 2024
1 parent f9c5a1d commit 447cd69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .pytool/Plugin/LineEndingCheck/LineEndingCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def GetTestName(self, packagename: str, environment: VarDict) -> Tuple:

# Note: This function access git via the command line
#
# function to check and warn if git config reports that
# function to check and warn if git config reports that
# autocrlf is configured to TRUE
def _check_autocrlf(self):
r = Repo(self._abs_workspace_path)
Expand Down Expand Up @@ -121,7 +121,7 @@ def _get_git_ignored_paths(self) -> List[Path]:
If git is not found, an empty list will be returned.
"""
if not shutil.which("git"):
logging.warn(
logging.warning(
"Git is not found on this system. Git submodule paths will "
"not be considered.")
return []
Expand Down Expand Up @@ -162,7 +162,7 @@ def _get_git_submodule_paths(self) -> List[Path]:
If git is not found, an empty list will be returned.
"""
if not shutil.which("git"):
logging.warn(
logging.warning(
"Git is not found on this system. Git submodule paths will "
"not be considered.")
return []
Expand Down Expand Up @@ -270,7 +270,7 @@ def RunBuildPlugin(self, package_rel_path: str, edk2_path: Edk2Path,
for file in Path(self._abs_pkg_path).rglob('*'):
if file.is_dir():
continue

if any(file.is_relative_to(ignore_dir) for ignore_dir in ignore_dirs):
continue

Expand All @@ -279,7 +279,7 @@ def RunBuildPlugin(self, package_rel_path: str, edk2_path: Edk2Path,

if file in ignore_files:
continue

with open(file.resolve(), 'rb') as fb:
if not fb.readable() or _is_binary_string(fb.read(1024)):
continue
Expand Down
4 changes: 1 addition & 3 deletions .pytool/Plugin/UncrustifyCheck/UncrustifyCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os
import pathlib
import shutil
import stat
import timeit
from edk2toolext.environment import version_aggregator
from edk2toolext.environment.plugin_manager import PluginManager
Expand Down Expand Up @@ -495,7 +494,6 @@ def _initialize_file_to_format_info(self) -> None:
for path in rel_file_paths_to_format:
self._abs_file_paths_to_format.extend(
[str(path.resolve()) for path in pathlib.Path(self._abs_package_path).rglob(path)])

# Remove files ignore in the plugin configuration file
plugin_ignored_files = list(filter(self._get_files_ignored_in_config(), self._abs_file_paths_to_format))

Expand Down Expand Up @@ -639,7 +637,7 @@ def _remove_readonly(func, path, _):
"""
Private function to attempt to change permissions on file/folder being deleted.
"""
os.chmod(path, stat.S_IWRITE)
os.chmod(path, os.stat.S_IWRITE)
func(path)

for _ in range(3): # retry up to 3 times
Expand Down

0 comments on commit 447cd69

Please sign in to comment.