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

make embed assets relative to where annotation lives or abs from proj… #30

Merged
merged 4 commits into from
Jan 10, 2023

Conversation

jhsinger-klotho
Copy link
Contributor

…ect root

• Does any part of it require special attention?
• Does it relate to or fix any issue? closes #578

make embed assets relative to where annotation lives or abs from project root
Added docs in pr linked below

Standard checks

  • Unit tests: Any special considerations? added
  • Docs: Do we need to update any docs, internal or public? https://github.com/klothoplatform/docs/pull/139
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working? it should be because previously we would only match paths from the root of the project which we still should.

func (m *assetPathMatcher) ModifyPathsForAnnotatedFile(path string) error {
newInclude := []string{}
for _, pattern := range m.include {
absPath, err := filepath.Abs(pattern)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems odd to convert the pattern to an absolute path, perhaps IsAbs would be better?

Also, do we expect these paths to be standard unix or platform-specific? These calls will all be platform specific. If platform specific is intended, the TrimPrefix later on the leading slash won't work on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IsAbs is probably better

so youre saying we will see the path for our files as static/file on mac or linux and /static/file on windows?

If so then why dont we convert everything to an absolute path from the klotho root in readdir so we have a standard path we can follow? Our internal compiler logic shouldnt be dependent on the platform we are running on.

Comment on lines 108 to 119
absPath, err := filepath.Abs(pattern)
if err != nil {
return err
}
if absPath == pattern {
newExclude = append(newExclude, strings.TrimPrefix(pattern, "/"))
continue
}
relPath, err := filepath.Rel(filepath.Dir("."), filepath.Join(filepath.Dir(path), pattern))
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Seems like this could be extracted into a reusable function.

@@ -75,6 +84,45 @@ type assetPathMatcher struct {
err error
}

func (m *assetPathMatcher) ModifyPathsForAnnotatedFile(path string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Having this be a mutator function seems a bit weird to me. An assetPathMatcher isn't valid before calling this function and I'm not sure if it'd behave right if called twice, so callers need to make sure to call it exactly once on construction. Seems like it might be better served in a NewAssetPathMatcher constructor function.

if filepath.IsAbs(path) {
return strings.TrimPrefix(path, "/"), nil
}
relPath, err := filepath.Rel(filepath.Dir("."), filepath.Join(filepath.Dir(currentPath), path))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think the Rel might be redundant since the currentPath is always an input file path (where the annotation was specified) which is always relative to '.'. I'm not sure why it was there originally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your right, just pushed up a change which makes the logic much simpler

@github-actions
Copy link

github-actions bot commented Jan 9, 2023

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 24%
github.com/klothoplatform/klotho/pkg/core 21%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 45%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 58%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 52%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 37%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 9%
github.com/klothoplatform/klotho/pkg/lang/javascript 46%
github.com/klothoplatform/klotho/pkg/lang/python 60%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 7%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 60%
github.com/klothoplatform/klotho/pkg/runtime 75%
github.com/klothoplatform/klotho/pkg/static_unit 32%
github.com/klothoplatform/klotho/pkg/validation 73%
Summary 42% (3604 / 8606)

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.

2 participants