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

Use #is_a_path? conditionally on Bundler version #19

Merged
merged 21 commits into from
Aug 15, 2018

Conversation

garettarrowood
Copy link
Member

Needs a test still.

Any comments on this implementation?

[31] pry(#<CobraCommander::ComponentTree::Tree::Ruby>)> bundler_definition.locked_bundler_version
=> "1.16.3"

@garettarrowood
Copy link
Member Author

Related to #16 & #17 .

@garettarrowood
Copy link
Member Author

garettarrowood commented Aug 10, 2018

Actually -- This appears to fix a broken ComponentTree test in CI on the pr build. So there is some proof of concept.

end

def bundler_minor_version
bundler_definition.locked_bundler_version.split(".")[1].to_i
Copy link
Member

Choose a reason for hiding this comment

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

Do you care about the locked version, or the version in use at runtime?

Copy link
Member Author

Choose a reason for hiding this comment

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

The one in use at runtime.

Good catch with that method name.

It appears though, that this actually returns the runtime version. As the locked version in this repo was 1.16.0 for me, but my local version was 1.16.3.


Given how much Bundler's api appears to change, what about something like:

stout, _ = Open3.capture2("bundler", "-v")

More reliable, or hacky?

Copy link
Member

Choose a reason for hiding this comment

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

Less reliable: the version in use and the version in the path might potentially be different.

Is Bundler::VERSION not defined? If not, I would ask rubygems for the version of Bundler that has been loaded.

Copy link
Member Author

Choose a reason for hiding this comment

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

Bundler::VERSION is accessible :).

@garettarrowood
Copy link
Member Author

@benlangfeld - Ready for review.

The last PR build actually passed. But travis failed to retrieve libraries in a couple spots.

You can see from the large amount of commits that I had trouble getting travis-ci to use the Bundler version. What we had setup in the travis.yml wasn't working. Evident by the frozen logic starting to fail. This issue and comment was the only method I was able to get to work. I can list the various ways I tried if you like.

Good news. Bundler API's #set_local and #frozen? are backwards compatible. So no Bundler version logic is needed in the test itself.

On a whim I added some Ruby versions to the new travis matrix. And currently there are 4 minor versions of Bundler specified. All together, that means 12 separate builds for both travis-ci/pr and travis-ci/push, or 24 in total. Do you think this is appropriate coverage, or should something be eliminated to reduce the amount of builds?

.travis.yml Outdated
- sudo apt-get -qq install graphviz
rvm:
- 2.3.7
Copy link
Member

Choose a reason for hiding this comment

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

I think we can be aggressive and state support only for Ruby > 2.5.0

.travis.yml Outdated
env:
- BUNDLER_VERSION=1.13.6
- BUNDLER_VERSION=1.14.6
- BUNDLER_VERSION=1.15.4
Copy link
Member

Choose a reason for hiding this comment

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

Equally, we can probably ignore Bundler < 1.15.0.

before_install:
- gem install bundler -v 1.13.6
- "find /home/travis/.rvm/rubies -wholename '*default/bundler-*.gemspec' -delete"
Copy link
Member

Choose a reason for hiding this comment

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

Does gem uninstall not work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately not. I tried in the before_install and install phases. Travis returns:

$ gem uninstall bundler
ERROR:  While executing gem ... (Gem::InstallError)
    gem "bundler" cannot be uninstalled because it is a default gem

Related issue

@@ -93,6 +99,14 @@ def gemfile_path
def gemfile_lock_path
File.join(@root_path, "Gemfile.lock")
end

def bundler_version_supporting_path_method?
@bundler_version_supporting_path_method ||= bundler_minor_version >= 16
Copy link
Member

Choose a reason for hiding this comment

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

I would actually do a comparison on the whole version. There’s a helper method somewhere in Rubygems (maybe Gem::Version comparison operator) to do that more accurately than ignoring the major version.

format(gems)
end
end

def path?(dep)
if bundler_version_supporting_path_method?
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it, I wonder if we shouldn’t just rely on responds_to? here?

def path?(source)
return if source.nil?
if source.respond_to?(:path?)
source.path? && source.path.to_s != "."
Copy link
Member

Choose a reason for hiding this comment

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

Last nit: any chance of reducing the duplication here?

Copy link
Member Author

@garettarrowood garettarrowood Aug 13, 2018

Choose a reason for hiding this comment

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

I'll see what I can do. I was thinking that if source does respond to path?, it may still return falsy. And if it does return falsy, then it may not respond to path (without the ?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants