Skip to content

Commit

Permalink
Fix TOML parsing in Python ecosystem (fixes #10523)
Browse files Browse the repository at this point in the history
Use `tomli` instead of outdated `toml` package
  • Loading branch information
daniil-berg authored and sachin-sandhu committed Jan 16, 2025
1 parent 353eeab commit 9ffbfb1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions python/helpers/lib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
)

from packaging.requirements import InvalidRequirement, Requirement
# TODO: Replace 3p package `toml` with 3.11's new stdlib `tomllib` once we drop
# support for Python 3.10.
import toml
# TODO: Replace 3p package `tomli` with 3.11's new stdlib `tomllib` once we
# drop support for Python 3.10.
import tomli

# Inspired by pips internal check:
# https://github.com/pypa/pip/blob/0bb3ac87f5bb149bd75cceac000844128b574385/src/pip/_internal/req/req_file.py#L35
COMMENT_RE = re.compile(r'(^|\s+)#.*$')


def parse_pep621_dependencies(pyproject_path):
project_toml = toml.load(pyproject_path)
with open(pyproject_path, "rb") as file:
project_toml = tomli.load(file)

def parse_toml_section_pep621_dependencies(pyproject_path, dependencies):
requirement_packages = []
Expand Down
4 changes: 2 additions & 2 deletions python/helpers/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ hashin==1.0.3; python_version >= '3.9'
pipenv==2024.0.2
plette==2.1.0
poetry==1.8.5
# TODO: Replace 3p package `toml` with 3.11's new stdlib `tomllib` once we drop support for Python 3.10.
toml==0.10.2
# TODO: Replace 3p package `tomli` with 3.11's new stdlib `tomllib` once we drop support for Python 3.10.
tomli==2.0.1

# Some dependencies will only install if Cython is present
Cython==3.0.10

0 comments on commit 9ffbfb1

Please sign in to comment.