-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
formula2requirements.rb
59 lines (48 loc) · 1.9 KB
/
formula2requirements.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# homebrew-core: 23f83804493c17380cb03e8b2c15088a6acf51d5
require "fileutils"
require "uri"
require "formulary"
require "formula"
OUT = "#{__dir__}/requirements"
# Completely blow away the existing requirements dir, and then re-create it:
# this clears out any requirements files that have been orphaned by upstream
# formula deletion.
FileUtils.rm_rf OUT
FileUtils.mkdir_p OUT
Formula.all.sort.each do |f|
# Skip formulae that aren't in homebrew/core.
next unless f.tap.name == "homebrew/core"
# Look for formulae that have PyPI resources; skip those that don't.
python_resources = f.resources.select { |r| r.url =~ /files\.pythonhosted\.org/ }
next if python_resources.empty?
# Skip deprecated and disabled formulae.
next if f.deprecated? || f.disabled?
requirement_file = "#{OUT}/#{f.name}-requirements.txt"
puts f.name
File.open requirement_file, "w" do |io|
python_resources.each do |pr|
# Each pythonhosted resource URL looks something like this:
# https://files.pythonhosted.org/packages/PREFIX/PREFIX/LONG_BLAKE_HASH/PKGNAME-X.Y.Z.ext
#
# The only things we care about from the URL itself are
# the version (X.Y.Z) and the extension (and we only care about the
# latter so we can strip it correctly).
path = URI::parse(pr.url).path
suffix = if path.end_with? ".zip"
".zip"
elsif path.end_with? ".tar.gz"
".tar.gz"
elsif path.end_with? ".tar.bz2"
".tar.bz2"
elsif path.end_with? "-py3-none-any.whl"
"-py3-none-any.whl"
elsif path.end_with? "-py2.py3-none-any.whl"
"-py2.py3-none-any.whl"
else
abort "barf: unexpected suffix in #{path}"
end
version = path.rpartition("-").last.delete_suffix suffix
io.puts "#{pr.name}==#{version}"
end
end
end