Skip to content

Commit

Permalink
Fallback if toml file parsing failed (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger authored Jan 16, 2025
1 parent b5f58b2 commit 14dc0be
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 2 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,15 @@ jobs:
exit 1
fi
shell: bash

test-malformed-pyproject-file-fallback:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install using malformed pyproject.toml
id: setup-uv
uses: ./
with:
pyproject-file: "__tests__/fixtures/malformed-pyproject-toml-project/pyproject.toml"
- run: uv sync
working-directory: __tests__/fixtures/uv-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
Empty file.
6 changes: 6 additions & 0 deletions __tests__/fixtures/malformed-pyproject-toml-project/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from malformed-pyproject-toml-project!")


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "malformed-pyproject-toml-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = []

[malformed-toml
10 changes: 9 additions & 1 deletion dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/utils/pyproject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ export function getUvVersionFromConfigFile(
core.warning(`Could not find file: ${filePath}`);
return undefined;
}
let requiredVersion = getRequiredVersion(filePath);
let requiredVersion: string | undefined;
try {
requiredVersion = getRequiredVersion(filePath);
} catch (err) {
const message = (err as Error).message;
core.warning(`Error while parsing ${filePath}: ${message}`);
return undefined;
}

if (requiredVersion?.startsWith("==")) {
requiredVersion = requiredVersion.slice(2);
Expand Down

0 comments on commit 14dc0be

Please sign in to comment.