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
Shareable Mini-Gemfiles? #6939
Comments
I'm a bit unclear on what the issue is w/r/t |
To put it very simply, I am unable to call
Fundamentally I want composable gemfiles... and My example only went one deep, but it is oversimplified. |
Just thought of another way to describe the idea. I could make a gem that would ship a set of dependencies that relate to a specific context, much like the This idea is similar, in two distinct parts. First, make a set of individual gems, using an example namespace of "tan":
And then make another set of gems, using a sub-namespace of the first, "tan-dem":
That is a lot of gems to build, and maintain... and each one is very thin, mostly existing to provide a set of dependencies that live in a gemspec... 😩 But what if...That could all be replaced with a single gem that ships a set of re-usable gemfiles! 🤩 It won't work if gemfiles can't be eval'd multiple layers deep. They can't use |
Also of note: another downside of gemspecs as a "solution" for this use case is the lack of control over source (for good reason - I'm not complaining about that, nor do I think it should change - I've read the relevant threads). My shareable gemfile gem concept is intended to encode a high level of understanding about specific context's library ecosystem. For example, simplecov-rcov emits deprecation warnings, and may never be fixed, thus we are relying on forks to fix problems. This can only be done in a Gemfile unless I hard fork the gem and release a fixed alternate. 😬
In other words, accomplishing the goal via releasing a bunch of new gems with gemspecs, would force me to still copy paste lines like the one above into each projects Gemfile, which is exactly what I want to avoid (I maintain many dozens of public gems, and many-more-still private ones). |
Gemfiles I guess I need to figure out why it isn't working in a stack of gems. The issue I had was definitely that |
Ok, I'm imagining something like if Another way to express this might be: gemspecs don't support everything that a Gemfile does, and gems can't ship with more than one gemspec. Wouldn't it be nice if a gem could contain multiple Gemfile-like lists of dependencies accessible by name? I think if you could do that, the I had read your idea before and it sounded very complex, but the I think your point about simplecov makes sense and made me rethink the idea. It could be nice to configure packages of dependencies like this. I guess the simplest version of this would be a directive in a Gemfile that loads another gemfile (from a gem or where?). Having to install gems before we can finish resolving seems odd though. How would you manage these sub-gemfiles? |
Yes, a directive similar to Bundler plugins seem to already have access to a method like this:
I'm testing it out now, but it doesn't do what you would expect it to... at all. :/ Calling from within the relevant hook doesn't change the behavior.
Essentially it does nothing. |
I also tried using |
This actually runs without errors, but once again, has no effect on the final
|
An example where I've implemented the non-shared-pattern I am trying to replace with this shared-pattern is here, where I have:
I've already replicated this pattern many times, improving it a little each time, and it is getting hard to keep track of where the latest, best, version of the pattern is to copy to a new gem. Every time I find myself in this situation I know it is time to write a new gem to encode the pattern. |
I almost have it working!
Working
Not Working
Example 1$ bundle exec rake
bundler: failed to load command: rake (/Users/pboling/.asdf/installs/ruby/3.2.2/bin/rake)
/Users/pboling/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/bundler/rubygems_integration.rb:308:in `block in replace_bin_path': can't find executable rake for gem rake. rake is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception) Example 2$ bundle info rake
Could not find gem 'rake'. Example 3I have constrained rake to version 12, so it should show as outdated re: version 13, but it does not. $ bundle outdated
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/..........
Bundle up to date! Very ConfusedWhat I don't understand is, why is being A) installed, and B) listed normally in the lockfile, not precisely, literally, and exclusively, the requirement for |
@martinemde - I've pushed a POC that isn't working (except as noted in my last comment), but that is structured like what I'd hope to get working. Now that it is pushed, and I switch the plugin to load from git, I get another very interesting error.
Can bundler plugins not have depeendencies? Or can they not be loaded from a git source? |
I've also noticed that the before install all hook for a plugin does not run on a cold bundle install (i.e. first ever run), only on a warm run. This partially defeats the purpose of the hook (and entirely for my use case). :( |
I'm trying to use a layered config for my Gemfiles for CI (e.g. on Github Actions, Bitbucket Pipelines, CircleCI etc).
I hoped I could have a set of shared mini-gemfiles that I would use discretely for various CI parts, and which could be re-used across applications.
The mini-gemfiles would be for discrete contexts like "coverage", "debugging", "testing", "documentation", "style", etc. If this was to work, I'd create a Bundler plugin that would ship these shareable gemfiles, so integration would be a one liner (plugins auto-install, and auto-configure on a bundler hook).
But it turns out that Bundler's definition of
eval_gemfile
usesinstance_eval
, which changes the "current class" (or "default definee" if you like), and results in the self-sameeval_gemfile
being unavailable to the mini-Gemfile context. If it was to useclass_eval
instead the receiver would remain as the current class, and I think it would work. Also, I may be waaaay off base here, as to why it isn't working.I'm wondering if this was an intentional decision, or just a chance, and also if there is a security consideration that would make a change to
class_eval
unwise.Example
In the context of code coverage, we have to both run the test suite on a supported platform, and analyze the results.
We could have two mini-Gemfiles as follows, each providing in context documentation for various choices that may require deep knowledge of the gem library ecosystem, and which I don't want to have to find repeatedly for every project I create:
gemfiles/contexts/coverage.gemfile
gemfiles/contexts/testing.gemfile
gemfiles/coverage.gemfile
Why?
The basis for this idea is that I end up doing this in every project, and it is a significant amount of re-work, most of which I could standardize across all my projects.
https://gitlab.com/rubocop-lts/standard-rubocop-lts/-/tree/main/gemfiles
The text was updated successfully, but these errors were encountered: