Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Fix upgrade depenecies workflow #1083

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions .github/workflows/upgrade-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,7 @@ jobs:
ssh-key: ${{ secrets.DEPLOY_KEY }}

# START PYTHON DEPENDENCIES
- uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: pip
cache-dependency-path: 'pyproject.toml'
- uses: actions/setup-python@v5
with:
python-version: "3.9"
cache: pip
cache-dependency-path: 'pyproject.toml'
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
cache-dependency-path: 'pyproject.toml'

- uses: actions/setup-python@v5
with:
python-version: "3.11"
Expand All @@ -46,14 +32,13 @@ jobs:
# ADD YOUR CUSTOM DEPENDENCY UPGRADE COMMANDS BELOW
run: |
set -x
flags="--extra pyqt5 --extra pyqt6 --extra pyside2 --extra pyside6"
flags+=" --extra test --extra pyinstaller --allow-unsafe --strip-extras --resolver=backtracking"
pip install -U uv
flags=(--extra pyqt5 --extra pyqt6 --extra pyside2 --extra pyside6 --extra test --extra pyinstaller)

for pyv in 3.8 3.9 3.10 3.11; do
python${pyv} -m pip install -U pip pip-tools
python${pyv} -m piptools compile --upgrade -o requirements/constraints_py${pyv}.txt pyproject.toml requirements/version_denylist.txt ${flags}
uv pip compile --python-version ${pyv} --upgrade --output-file requirements/constraints_py${pyv}.txt pyproject.toml requirements/version_denylist.txt "${flags[@]}"
done
python3.11 -m piptools compile --upgrade -o requirements/constraints_py3.11_docs.txt pyproject.toml requirements/version_denylist.txt --allow-unsafe --strip-extras --extra docs --extra pyqt6
uv pip compile --python-version 3.11 --upgrade --output-file requirements/constraints_py3.11_docs.txt pyproject.toml requirements/version_denylist.txt --extra docs --extra pyqt6
# END PYTHON DEPENDENCIES

- name: Check updated packages
Expand Down
15 changes: 9 additions & 6 deletions build_utils/check_updated_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import re
import subprocess # nosec
import sys
from configparser import ConfigParser
from pathlib import Path

from tomllib import loads

name_re = re.compile(r"[\w-]+")
changed_name_re = re.compile(r"\+([\w-]+)")

Expand All @@ -31,12 +32,14 @@
sys.exit(0)


config = ConfigParser()
config.read(src_dir / "setup.cfg")
config = loads((src_dir / "pyproject.toml").read_text())

metadata = config["project"]

packages = (
config["options"]["install_requires"].split("\n")
+ config["options.extras_require"]["pyinstaller"].split("\n")
+ config["options.extras_require"]["all"].split("\n")
metadata["dependencies"]
+ metadata["optional-dependencies"]["pyinstaller"]
+ metadata["optional-dependencies"]["all"]
Comment on lines +35 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

The transition to reading and parsing pyproject.toml using tomli is correctly implemented. However, there are a few considerations for improvement:

  1. Error handling for file reading and TOML parsing should be added to catch and handle potential IO or parsing errors gracefully.
  2. The extraction of dependencies assumes the presence of certain keys (dependencies, optional-dependencies) in the TOML file. It's advisable to check for the existence of these keys before accessing them to avoid KeyError.
+ try:
config = loads((src_dir / "pyproject.toml").read_text())
+ except (FileNotFoundError, IOError) as e:
+     print(f"Error reading pyproject.toml: {e}", file=sys.stderr)
+     sys.exit(1)
+ except tomli.TOMLDecodeError as e:
+     print(f"Error parsing pyproject.toml: {e}", file=sys.stderr)
+     sys.exit(1)

+ if "project" not in config:
+     print("Missing 'project' section in pyproject.toml", file=sys.stderr)
+     sys.exit(1)
metadata = config["project"]

+ if "dependencies" not in metadata or "optional-dependencies" not in metadata:
+     print("Missing dependencies information in pyproject.toml", file=sys.stderr)
+     sys.exit(1)
packages = (
    metadata["dependencies"]
    + metadata.get("optional-dependencies", {}).get("pyinstaller", [])
    + metadata.get("optional-dependencies", {}).get("all", [])
)
+ ```

<!-- This is an auto-generated comment by CodeRabbit -->

---

<!-- suggestion_start -->
<details>
<summary>Committable suggestion</summary>

> :bangbang: **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

```suggestion
try:
    config = loads((src_dir / "pyproject.toml").read_text())
except (FileNotFoundError, IOError) as e:
    print(f"Error reading pyproject.toml: {e}", file=sys.stderr)
    sys.exit(1)
except tomli.TOMLDecodeError as e:
    print(f"Error parsing pyproject.toml: {e}", file=sys.stderr)
    sys.exit(1)

if "project" not in config:
    print("Missing 'project' section in pyproject.toml", file=sys.stderr)
    sys.exit(1)
metadata = config["project"]

if "dependencies" not in metadata or "optional-dependencies" not in metadata:
    print("Missing dependencies information in pyproject.toml", file=sys.stderr)
    sys.exit(1)
packages = (
    metadata["dependencies"]
    + metadata.get("optional-dependencies", {}).get("pyinstaller", [])
    + metadata.get("optional-dependencies", {}).get("all", [])
)

)
packages = [name_re.match(package).group().lower() for package in packages if name_re.match(package)]

Expand Down