In my gem development directory, I moved the file lib/project/module.rb to lib/project/helpers/module.rb and then did
bundle install
This gave me an invalid gemspec error
project at /path/project did not have a valid gemspec. This prevents
bundler from installing bins or native extensions, but that may not
affect its functionality. The validation message from Rubygems was:
["lib/project/module.rb"] are not files
Why am I getting this error?
The problem occured because gemspec uses git to validate the presence of required files.
Instead of doing a normal mv
mv lib/project/module.rb lib/project/helpers/
It's better to do a git mv
git mv lib/project/module.rb lib/project/helpers/
After reverting the move and doing the git mv, bundle install worked without any validation errors.
It is also better practice in general to do git mv rather than mv in a git repo, because it can potentially keep you commits looking cleaner. What's the purpose of git-mv?
Probably you have modified name of that file and didn't commit that changes.
git add .
Will solve the problem.
Related
When trying to install the gem "u2f" from the repo at "castle/ruby-u2f" I get an error message:
Fetching git://github.com/castle/ruby-u2f.git
fatal: Needed a single revision
Revision master does not exist in the repository git://github.com/castle/ruby-u2f.git. Maybe you misspelled it?
I cannot find any information about this error message. The text does not appear in any of the bundler source files, so I don't even know where to start debugging.
If anyone has any insight into the source and cause of this error, I'd love to know.
If you're trying to install a gem from a github source and got this, it may be because the repo changed its default branch from "master" to "main". Try adding branch: 'main' and see if it works.
Try pulling from the master branch
I git pull a project to the local (on MacOS), and almost the same problem occurred during the bundle install. But I tried the above answers to no avail.
I have two systems that use the same command line interface written in ruby. One system is using an older version that's incompatible with the scripts we have written. We'd like to use bundler to download all the dependencies for the 2.0 on our own system, and then migrate that bundle over to the system with the older version so that we can use 2.0 there as well.
We do not have the option to run bundle install on the other system because it's not open to the internets.
So the idea is on my system:
bundle init
...write Gemfile...
bundle install
tar -czf cli2.0.tar.gz ./Gemfile ./Gemfile.lock ./.bundle ./bundle
... move cli2.0.tar.gz to the other system ...
On system B:
tar -zxf cli2.0.tar.gz
bundle exec cli2.0 version
But at this point we get an error stating that bundler couldn't find any of the gems even though they're right there under ./bundle/ruby/2.3.0/!!
It looks like they have different versions of ruby, and ruby-gems installed.
Received some help from a coworker, the gist is I was doing it all wrong.
If you want to transport gems and see consistent performance with bundler do this.
bundle install <gem>
bundle package
This creates a cache of the downloaded gems for transport.
tar -czf ./transport.tar.gz ./Gemfile ./Gemfile.lock ./vendor
On the next machine:
tar -xzf ./transport.tar.gz
bundle exec <command>
Might be worth a try to make your second Gemfile (the one without internet access) reference the gems using paths.
i.e.
gem some_gem, path: "/home/you/some_path/some_gem"
See this question for more info on that.
If you don't have internet access but can transfer over files, it might be worth transferring the source code for a new version of bundler/RubyGems as well.
error: Your local changes to the following files would be overwritten by merge:
Library/Contributions/brew_bash_completion.sh
Library/Contributions/brew_fish_completion.fish
Library/Contributions/brew_zsh_completion.zsh
Library/Contributions/manpages/brew.1.md
...
Library/Formula/dmtx-utils.rb
Library/Formula/docbook-xsl.rb
Library/Formula/dromeaudio.rb
Library/Formula/dub.rb
Library/Formula/dvorak7min.rb
Library/Formula/dyld-headers.rb
Library/Formula/dylibbundler.rb
Library/For
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
I've seen this a few times and don't know what causes it; but if you're sure you haven't made any modifications to those files that you want to save, you can go into /usr/local (or wherever you keep the Homebrew installation) and type git reset --hard HEAD. Then try updating again.
Deleting files and reinstalling HOMEBREW solved the problem.
I'm currently attempting to create a ruby gem out of a script and, while it works if I take the scripts and put them in the same directory, if I put them in the appropriate /bin and /lib directories after generating my gem structure, build the gem and then attempt to execute it I'm given the uninitialized constant error. Under /bin the relevant section in the file "cjp" is:
Cjb.new(crontabDir, logDir, allowedFrequency, printOnly, testRun).
find_violations autoFix
The class is defined in the file cjp.rb under /lib
class Cjb
def initialize(crontabDir, logDir, allowedFrequency, printOnly, testRun)
#crontabDir, #logDir, #allowedFrequency, #printOnly, #testRun =
crontabDir, logDir, allowedFrequency, printOnly, testRun
Despite this, the error I get is:
ERROR: uninitialized constant Cjb
I also noticed that if I attempt to manually execute the "cjp" script under /bin without the lib script being in the same directory that it also gives the same error. It appears that I'm missing something.
Any help on what I'm missing here to get this working would be appreciated.
bundle gem uses git to manage gem manifest.
If you do not see all your expected files when you run git ls-files in your gem project dir, then you need to add them.
To add individual files:
git add <filename>
To add everything (run from root of project):
git add .
This may have caught you out if you were not expecting to use git on your project. If you don't know git, and have time, it is really recommended to help you manage your project code. In fact so much so that bundle simply assumes that's what you want to do (although other code management tools are available)
TL;DR:
Don't run bundle within an existing git repository. Weird things will happen without any error messages.
Original Question:
I've built a gem by adapting the steps in this tutorial:
http://net.tutsplus.com/tutorials/ruby/gem-creation-with-bundler/
As a final step, I've run gem build .gemspec
This succeeds, but when I install the gem I find the critical file, the one which contains my code, isn't in the gem. Another file in the same (lib) directory, "version.rb", does exist in the gem.
I don't know how to start debugging this...how does bundler/gem build decide which files to include in the gem?
Edit:
My workflow is:
gem build <project_name>.gemspec
gem unpack <project_name>
=> confirm file does not exist in <unpacked>/lib/
gem install <project name>
=> confirm file structure in ~/home/stefan/.rvm/... contains gem, but does not contain desired file
Edit 2 / Resolution:
I was finally able to get this working by committing all my code to a remote repository, creating a clean clone, and building the gem. The new gem included all the required files.
A bit of history...I originally created the code and committed it before thinking about making a gem (this is my first gem). I then used bundle inside the original repository, which didn't complain, but was probably the reason for the weirdness.
One of the things bundler did for you is start a local git repo to version-manage your gem code. Check that you have added the file in git
git add lib/gem_name/missing_file.rb
Bundler generated gems use git internally to track "membership" of source files for the gem. You can see this in the .gemspec where it uses backticks to call out to git and generate a file list:
gem.files = `git ls-files`.split($/)
Note this also means you should pay attention to what you list in .gitignore