如何加载在红宝石钩蟒蛇文件?(How to load the python file in ruby

2019-10-30 04:22发布

我尝试添加的钩子忽略二进制文件中gitlab犯,所以我说,在新的Python(的.py)挂钩/opt/gitlab/embedded/service/gitlab-shell/lib和我装在该文件中/opt/gitlab/embedded/service/gitlab-shell/hooks/pre-receive.rb

但是,当我试图提交文件,我得到了下面的异常在提交屏幕

远程:钩/预接收:17:在require_relative': cannot load such file -- /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_ignore_binary.py (LoadError) remote: from hooks/pre-receive:17:in

我预先收到挂钩文件

#!/opt/gitlab/embedded/bin/ruby
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']

#!/usr/bin/env ruby
#!/usr/bin/env python

# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.

refs = $stdin.read
key_id = ENV.delete('GL_ID')
protocol = ENV.delete('GL_PROTOCOL')
repo_path = Dir.pwd
gl_repository = ENV['GL_REPOSITORY']

require_relative '../lib/gitlab_ignore_binary.py'
require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_reference_counter'
require_relative '../lib/gitlab_access'


# It's important that on pre-receive `increase_reference_counter` gets executed
# last so that it only runs if everything else succeeded. On post-receive on the
# other hand, we run GitlabPostReceive first because the push is already done
# and we don't want to skip it if the custom hook fails.
if GitlabAccess.new(gl_repository, repo_path, key_id, refs, protocol).exec &&
    GitlabCustomHook.new(repo_path, key_id).pre_receive(refs) &&
    GitlabReferenceCounter.new(repo_path).increase

  exit 0
else
  exit 1
end

为什么我不能老是能够加载.py文件?

Answer 1:

从这个基本片断内核#要求或许应该总结一下你:

如果文件名的扩展名为“.RB”,它被加载的一个源文件; 如果扩展名是“所以”,名为“.o”或“.DLL”,或默认在当前平台上的共享库扩展,红宝石加载共享库的Ruby扩展。 否则,红宝石试图加入“.RB”,“所以”,等的名字,直到找到。 如果无法找到指定的文件,一个LoadError将提高。

在阿里纳斯你是怎么想到这个的行为? Ruby解释器应该如何处理Python文件?



文章来源: How to load the python file in ruby hook?