Skip to content

Support python 3.13 with updated dependencies - #4430

Merged
AyanSinhaMahapatra merged 84 commits into
developfrom
test-pyahocorasick
Jun 26, 2025
Merged

Support python 3.13 with updated dependencies#4430
AyanSinhaMahapatra merged 84 commits into
developfrom
test-pyahocorasick

Conversation

@AyanSinhaMahapatra

@AyanSinhaMahapatra AyanSinhaMahapatra commented Jun 17, 2025

Copy link
Copy Markdown
Member

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁
  • Updated documentation pages (if applicable)
  • Updated CHANGELOG.rst (if applicable)

JonoYang and others added 30 commits July 17, 2023 13:28
Signed-off-by: Jono Yang <jyang@nexb.com>
    * Use ruff config and Make commands from scancode.io

Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Add support for new OS versions
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* remove CI scripts and use Makefile targets instead
* ensure doc8 runs quiet
* add new docs-check make target to run documentation and links checks
* update oudated doc for docs contribution

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
    * Use ruff config and Make commands from scancode.io

Signed-off-by: Jono Yang <jyang@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
Reference: #4447
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
"--all", "--path", site_packages_dir]
return subprocess.check_output(args, encoding="utf-8")
args = ["pip", "freeze", "--exclude-editable", "--all", "--path", site_packages_dir]
return subprocess.check_output(args, encoding="utf-8") # noqa: S603

Check failure

Code scanning / CodeQL

Uncontrolled command line

This command line depends on a [user-provided value](1). This command line depends on a [user-provided value](2).

Copilot Autofix

AI about 1 year ago

To fix the issue, we need to validate and sanitize the site_packages_dir input before using it in the subprocess.check_output() call. The best approach is to ensure that the input is a valid directory path and restrict it to a predefined allowlist or sanitize it to prevent command injection.

Steps to fix:

  1. Add a validation function to check that site_packages_dir is a valid directory path and does not contain any malicious characters or patterns.
  2. Use shlex.quote() to safely escape the site_packages_dir value before including it in the args list for the subprocess call.
  3. Update the get_installed_reqs function in utils_requirements.py to incorporate these changes.

Suggested changeset 1
etc/scripts/utils_requirements.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/etc/scripts/utils_requirements.py b/etc/scripts/utils_requirements.py
--- a/etc/scripts/utils_requirements.py
+++ b/etc/scripts/utils_requirements.py
@@ -115,9 +115,14 @@
     Return the installed pip requirements as text found in `site_packages_dir`
-    as a text.
+    as a text. Validates and sanitizes the input to prevent command injection.
     """
-    if not os.path.exists(site_packages_dir):
-        raise Exception(f"site_packages directory: {site_packages_dir!r} does not exists")
+    if not os.path.exists(site_packages_dir) or not os.path.isdir(site_packages_dir):
+        raise Exception(f"site_packages directory: {site_packages_dir!r} does not exist or is not a directory")
+    
+    # Sanitize the input to prevent command injection
+    import shlex
+    sanitized_dir = shlex.quote(str(site_packages_dir))
+    
     # Also include these packages in the output with --all: wheel, distribute,
     # setuptools, pip
-    args = ["pip", "freeze", "--exclude-editable", "--all", "--path", site_packages_dir]
+    args = ["pip", "freeze", "--exclude-editable", "--all", "--path", sanitized_dir]
     return subprocess.check_output(args, encoding="utf-8")  # noqa: S603
EOF
@@ -115,9 +115,14 @@
Return the installed pip requirements as text found in `site_packages_dir`
as a text.
as a text. Validates and sanitizes the input to prevent command injection.
"""
if not os.path.exists(site_packages_dir):
raise Exception(f"site_packages directory: {site_packages_dir!r} does not exists")
if not os.path.exists(site_packages_dir) or not os.path.isdir(site_packages_dir):
raise Exception(f"site_packages directory: {site_packages_dir!r} does not exist or is not a directory")

# Sanitize the input to prevent command injection
import shlex
sanitized_dir = shlex.quote(str(site_packages_dir))

# Also include these packages in the output with --all: wheel, distribute,
# setuptools, pip
args = ["pip", "freeze", "--exclude-editable", "--all", "--path", site_packages_dir]
args = ["pip", "freeze", "--exclude-editable", "--all", "--path", sanitized_dir]
return subprocess.check_output(args, encoding="utf-8") # noqa: S603
Copilot is powered by AI and may make mistakes. Always verify output.
@AyanSinhaMahapatra
AyanSinhaMahapatra force-pushed the test-pyahocorasick branch 8 times, most recently from 9789e0c to 32421cb Compare June 25, 2025 13:20
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
@AyanSinhaMahapatra

Copy link
Copy Markdown
Member Author

All green, release tests also passing at https://github.com/AyanSinhaMahapatra/scancode-toolkit/actions/runs/15879003647

Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>

@JonoYang JonoYang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I am able to run scancode and the tests using Python 3.13 on my machine, there's just a merge issue with the contrib doc.

Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
@AyanSinhaMahapatra

Copy link
Copy Markdown
Member Author

Merging, test failures seem to be heisenbugs, release tests passing https://github.com/AyanSinhaMahapatra/scancode-toolkit/actions/runs/15902292932

@AyanSinhaMahapatra
AyanSinhaMahapatra merged commit c0ce98b into develop Jun 26, 2025
@AyanSinhaMahapatra
AyanSinhaMahapatra deleted the test-pyahocorasick branch December 3, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants