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

Default to forward slash-separated paths for path translation #2145

Merged
merged 7 commits into from
Jan 17, 2025

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Jan 14, 2025

Changes

This came up in #2122 where relative library paths showed up with backslashes on Windows. It's hard to run acceptance tests where paths may be in either form. This change updates path translation logic to always use forward slash-separated paths, including for absolute paths.

Tests

  • Unit tests pass.
  • Confirmed that code where library paths are used uses the filepath package for path manipulation. The functions in this package always normalize their inputs to be platform-native paths.
  • Confirmed that code that uses absolute paths works with forward slash-separated paths on Windows.

@pietern pietern temporarily deployed to test-trigger-is January 16, 2025 09:26 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is January 16, 2025 09:34 — with GitHub Actions Inactive
@pietern pietern requested a review from denik January 16, 2025 09:34
@@ -774,8 +773,8 @@ func TestTranslatePathJobEnvironments(t *testing.T) {
diags := bundle.Apply(context.Background(), b, mutator.TranslatePaths())
require.NoError(t, diags.Error())

assert.Equal(t, strings.Join([]string{".", "job", "dist", "env1.whl"}, string(os.PathSeparator)), b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[0])
assert.Equal(t, strings.Join([]string{".", "dist", "env2.whl"}, string(os.PathSeparator)), b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[1])
assert.Equal(t, "./job/dist/env1.whl", b.Config.Resources.Jobs["job"].JobSettings.Environments[0].Spec.Dependencies[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

question - might not be in scope for this PR - sometimes the paths have ./ in front ("./job/dist/env1.whl"), sometimes they don't ("job/dist/task.jar").

Should we standardize on that? Why not drop "./" from everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I recall correctly, this has its roots in the need to differentiate between a path reference and a PyPI package.

Agree that we should revisit and see if it can be normalized.

@andrewnester Do you recall the specifics?

Copy link
Contributor

Choose a reason for hiding this comment

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

Originally I think that was the reason but now I think we can safely drop it

@pietern pietern temporarily deployed to test-trigger-is January 16, 2025 09:38 — with GitHub Actions Inactive
if errors.Is(err, fs.ErrNotExist) {
if filepath.Ext(localFullPath) != notebook.ExtensionNone {
if path.Ext(localFullPath) != notebook.ExtensionNone {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to perform similar clean up across the whole codebase, or at least in bundle?

(main) ~/work/cli % git grep filepath bundle | wc -l
     507

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few other places where we do the same (e.g. sync includes), but definitely not everywhere.

The filepath package must be used for relative path computations because on Windows it makes sure it doesn't escape the drive or UNC path. I recall that also for globbing the input paths need to use the platform-native separator or they don't work.

@pietern pietern temporarily deployed to test-trigger-is January 16, 2025 12:52 — with GitHub Actions Inactive
@pietern pietern added this pull request to the merge queue Jan 17, 2025
Merged via the queue into main with commit 9061635 Jan 17, 2025
9 checks passed
@pietern pietern deleted the path-translation-forward-slashes branch January 17, 2025 09:43
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.

3 participants