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

Handle imports with same relative path #1262

Merged

Conversation

CraigSiemens
Copy link
Contributor

Changes

  • Identify merged includes using the full path to the file rather than just filePath which can be relative to the basePath and not unique.
  • Added comments to the path properties to make it clearer what they contain.
  • Other minor cleanup (renaming a parameter and making things private).

@CraigSiemens
Copy link
Contributor Author

I wouldn't mind some feedback on whether tests should be added to this (I assume they should) and what they would look like. I think it'd either need a new fixture or an existing on to be updated but I don't know the preferred path.

@yonaskolb
Copy link
Owner

Thanks @CraigSiemens, some great changes. Does #1275 also solve your issue? If so perhaps we can merge that first, and you can add your documentation on top.

In terms of a test case, adding it to Tests/Fixtures/paths_test.yml is probably a good place

@CraigSiemens
Copy link
Contributor Author

I tried it out and #1275 does fix the issue too.

I'm working on rebasing my branch onto master. I did find some improvements for the cachedSpecFiles that I'll add into this branch.

@CraigSiemens CraigSiemens force-pushed the handle-imports-with-same-relative-path branch from b877e65 to 8c894a8 Compare November 19, 2022 00:12
@CraigSiemens CraigSiemens force-pushed the handle-imports-with-same-relative-path branch from 8c894a8 to 220b388 Compare November 19, 2022 00:20
public init(path: Path, basePath: Path) throws {
var cachedSpecFiles: [Path: SpecFile] = [:]
let spec = try SpecFile(filePath: path, basePath: basePath, cachedSpecFiles: &cachedSpecFiles)
let spec = try SpecFile(path: path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is revering a change from #1275. Internally the init creates the cachedSpecFiles so callers don't have to make it.

Comment on lines -77 to -81
if let specFile = cachedSpecFiles[filePath] {
return specFile
} else {
return try SpecFile(include: include, basePath: basePath, relativePath: relativePath, cachedSpecFiles: &cachedSpecFiles, variables: variables)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

filePath, which is for the current spec, is not the correct key to use when looking for the specFile of an include that has it's own path.

@CraigSiemens
Copy link
Contributor Author

CraigSiemens commented Nov 19, 2022

@yonaskolb I believe I'm done rebasing/fixing so it's free for a re-review when you have a moment.

I've added in tests to paths_test.yml and verified they they failed before any of these changes were added to master.

I also made a couple minor changes to the usage of cachedSpecFiles, I left a reason for some of them above.

@yonaskolb
Copy link
Owner

Thanks @CraigSiemens, I can hopefully get to this soon.

@ma-oli would you mind casting an eye over this too, as you were recently in this area.

@ma-oli
Copy link
Contributor

ma-oli commented Nov 23, 2022

I’m off right now until Monday but I’m happy to have a look when I’m back.

@CraigSiemens
Copy link
Contributor Author

Hey @ma-oli, have you had a chance to take a look at it yet?

@ma-oli
Copy link
Contributor

ma-oli commented Dec 12, 2022

Hey; sorry about the delay. I'm looking at it now and I'm seeing some issues. I'll keep you posted.

@yonaskolb
Copy link
Owner

This issue has also come in #1299

try self.init(filePath: path, basePath: path.parent(), cachedSpecFiles: &cachedSpecFiles, variables: variables)
public init(path: Path, basePath: Path? = nil, cachedSpecFiles: inout [Path: SpecFile], variables: [String: String] = [:]) throws {
let basePath = basePath ?? path.parent()
let filePath = try path.relativePath(from: basePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using a relative path ( "-r ." for instance) as a project root results in this line throwing an unmatchedAbsolutePath error. We might want to use basePath?.absolute(), either here or in SpecLoader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's interesting, I'll try and take a look at that.

Copy link
Contributor

@ma-oli ma-oli left a comment

Choose a reason for hiding this comment

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

I think it's good but this breaks using a relative path as a project root. Shouldn't be a big deal to fix I think.

@CraigSiemens CraigSiemens requested a review from ma-oli December 14, 2022 23:12
@CraigSiemens
Copy link
Contributor Author

@ma-oli @yonaskolb I've added the fix for handling relative project paths.

@CraigSiemens
Copy link
Contributor Author

@yonaskolb Any chance this could get merged since it's got an approval?

@yonaskolb
Copy link
Owner

@yonaskolb Any chance this could get merged since it's got an approval?

Yep, could you please add a changelog entry. Also does this fix #1299?

@CraigSiemens
Copy link
Contributor Author

Yeah, it should fix that issue. I've merged in master and updated the changelog.

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

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

Fantastic, thanks for all your work on this @CraigSiemens 🙏

@yonaskolb yonaskolb merged commit 0500db2 into yonaskolb:master Jan 16, 2023
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