rbs-src 0.4.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76ab3d8f7dcde911852a0703e6439f7d3169d96a232e75c7f59b96f82ab40f89
4
- data.tar.gz: a0d55fd33ccdfe73ac01249761809ccbb8a5f0a0787b811bbc208c197c8219e0
3
+ metadata.gz: e7ade9d16159cd243f1f3849c3cecf99ff9e9bcb8988380778a19d56ab09f0e1
4
+ data.tar.gz: 85bd20a7118741b61d5e0186893a8f990a8f257c03a19fbc3a3410f056cb1257
5
5
  SHA512:
6
- metadata.gz: 790e7db58006f2d72714db5f74b50e7690184197da889bd2c0e02f3865f6ad9325a56c89d86c5904ea3971ac06254f810a2b3f0a62ec46fad085a5c8eda9ad0d
7
- data.tar.gz: 4cfd4d0df57c79f8dd50c00299c003f603f564977714375113de22df482300b6364b43e6a0917f36a0c68411ffa735a76e0e4f4f85fffbf8aeb450bf2582ad17
6
+ metadata.gz: 0c238d9c2c9a514bd62259176db2790507dc9543e9b0bd93d5530956d722158dc0f1bfd6f63ee5db037e0f3f89e581446f7935349d4336b4934c8aed774514cd
7
+ data.tar.gz: 177efc73a82a9de0bb01ed8155db0f843acaeedfb37bffb82e3de05db9140f21893e8ef1f0d47694e183d1eda9f0184d9b887e443ad9ba31f2eaf23274e7800f
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs-src (0.4.0)
4
+ rbs-src (0.6.0)
5
+ rainbow (~> 3.1.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -43,6 +43,8 @@ Load gem dependencies from `rbs_collection.lock.yaml` and set up all repositorie
43
43
 
44
44
  $ rbs-src setup
45
45
 
46
+ If the git repository content is edited, it runs `git stash` and `git reset --hard`.
47
+
46
48
  #### For Steep users
47
49
 
48
50
  You need to edit your Steepfile to let the type checker stop using rbs-collection.
@@ -78,6 +80,18 @@ The command will clone the git repository for `active_emoji-0.0` and make a syml
78
80
  You can add directories in the repository for `active_emoji-0.0` and start writing RBS files through the symlink.
79
81
  Once you finished the edit, you can push the RBS files to upstream!
80
82
 
83
+ ### rbs-src status
84
+
85
+ The command checks the status of all git repositories.
86
+
87
+ $ rbs-src status
88
+ [ok] activesupport tmp/rbs-src/activesupport-7.0
89
+ [dirty] rainbow tmp/rbs-src/rainbow-3.0
90
+ [commit_mismatch] ast tmp/rbs-src/ast-2.4
91
+
92
+ You may want to delete the repositories to reset, but use this command to ensure you don't have uncommitted changes.
93
+ (Note `rbs-src status` doesn't check if you pushed the commits to remotes.)
94
+
81
95
  ## Development
82
96
 
83
97
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/rbs/src/cli.rb CHANGED
@@ -67,6 +67,67 @@ module Rbs
67
67
  end
68
68
 
69
69
  0
70
+
71
+ when "status"
72
+ rbs_collection_lock_path = RBS::Collection::Config.to_lockfile_path(RBS::Collection::Config::PATH)
73
+ repository_prefix = Pathname("tmp/rbs-src")
74
+
75
+ OptionParser.new do |opts|
76
+ opts.on("--rbs-collection-lock=PATH", "The path to rbs_collection.lock.yaml (default: #{rbs_collection_lock_path})") { rbs_collection_lock_path = Pathname(_1) }
77
+ opts.on("--repo-prefix=PREFIX", "The location to put repository in (default: #{repository_prefix})") { repository_prefix = Pathname(_1) }
78
+
79
+ opts.banner = <<~BANNER
80
+ Usage: rbs-src status
81
+
82
+ Prints the status of git repositories.
83
+
84
+ Example:
85
+ $ rbs-src status [GEMs...]
86
+
87
+ Options:
88
+ BANNER
89
+ end.parse!(argv)
90
+
91
+ unless argv.empty?
92
+ gems = Set.new(argv)
93
+ end
94
+
95
+ repository_prefix.mkpath
96
+
97
+ lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
98
+ lockfile_path: rbs_collection_lock_path,
99
+ data: YAML.safe_load(rbs_collection_lock_path.read)
100
+ )
101
+
102
+ loader = LockfileLoader.new(
103
+ lockfile: lockfile,
104
+ repository_prefix: repository_prefix,
105
+ rbs_prefix: rbs_prefix
106
+ )
107
+
108
+ non_ok_count = 0
109
+
110
+ runner = CommandRunner.new(stdout: stdout)
111
+
112
+ loader.each_gem do |gem, repo, commit|
113
+ if !gems || gems.include?(gem.name)
114
+ status = gem.status(runner, commit: commit)
115
+ case status
116
+ when :ok
117
+ string = Rainbow("ok").blue
118
+ when :dirty
119
+ string = Rainbow("dirty").red
120
+ when :commit_mismatch
121
+ non_ok_count = non_ok_count + 1
122
+ string = Rainbow("commit_mismatch").yellow
123
+ end
124
+
125
+ stdout.puts "[#{string}] #{gem.name} #{gem.repository_root}"
126
+ end
127
+ end
128
+
129
+ non_ok_count == 0 ? 0 : 1
130
+
70
131
  when "setup"
71
132
  rbs_collection_lock_path = RBS::Collection::Config.to_lockfile_path(RBS::Collection::Config::PATH)
72
133
  repository_prefix = Pathname("tmp/rbs-src")
@@ -78,19 +139,18 @@ module Rbs
78
139
  opts.on("--rbs-prefix=PREFIX", "The location to put symlinks in (default: #{rbs_prefix})") { rbs_prefix = Pathname(_1) }
79
140
 
80
141
  opts.banner = <<~BANNER
81
- Usage: rbs-src setup [options]
142
+ Usage: rbs-src setup [options]
82
143
 
83
- Set up git repositories and symlinks in rbs_collection.yaml.
144
+ Set up git repositories and symlinks in rbs_collection.yaml.
84
145
 
85
- Example:
86
- $ rbs-src setup
87
-
88
- Options:
89
- BANNER
146
+ Example:
147
+ $ rbs-src setup
90
148
 
149
+ Options:
150
+ BANNER
91
151
  end.parse!(argv)
92
152
 
93
- rbs_prefix.mkpath
153
+ repository_prefix.mkpath
94
154
  rbs_prefix.mkpath
95
155
 
96
156
  lockfile = RBS::Collection::Config::Lockfile.from_lockfile(
@@ -108,10 +168,12 @@ module Rbs
108
168
 
109
169
  loader.each_gem do |gem, repo, commit|
110
170
  runner.push "Setting up #{gem.name}-#{gem.version}" do
111
- runner.push "Cloning git repository into #{gem.repository_root}" do
112
- if gem.repository_root.directory?
113
- runner.puts "Skipping already exist"
114
- else
171
+ if gem.repository_root.directory?
172
+ runner.push "Checking out commit in #{gem.repository_root}" do
173
+ gem.checkout(runner, repository_url: repo, commit: commit)
174
+ end
175
+ else
176
+ runner.push "Cloning git repository into #{gem.repository_root}" do
115
177
  gem.clone(runner, repository_url: repo, commit: commit)
116
178
  end
117
179
  end
@@ -159,7 +221,7 @@ module Rbs
159
221
  else
160
222
  puts "Unknown command: #{command}"
161
223
  puts
162
- puts " known commands: setup, link"
224
+ puts " known commands: setup, status, link"
163
225
  1
164
226
  end
165
227
  end
@@ -38,6 +38,17 @@ module Rbs
38
38
  end
39
39
  end
40
40
 
41
+ def query?(*command, chdir: Pathname.pwd)
42
+ # @type var out: String
43
+ # @type var status: Process::Status
44
+
45
+ out, status = Open3.capture2e(*command, chdir: chdir)
46
+
47
+ if status.success?
48
+ out
49
+ end
50
+ end
51
+
41
52
  def query!(*command, chdir: Pathname.pwd)
42
53
  # @type var out: String
43
54
  # @type var status: Process::Status
data/lib/rbs/src/gem.rb CHANGED
@@ -19,8 +19,38 @@ module Rbs
19
19
  repository_root.join(repository_dir, name, version)
20
20
  end
21
21
 
22
- def rbs_path
23
- rbs_prefix + "#{name}-#{version}"
22
+ def rbs_path(suffix = version)
23
+ rbs_prefix + "#{name}-#{suffix}"
24
+ end
25
+
26
+ def status(runner, commit:)
27
+ unless runner.query!("git", "status", "-s", "-z", chdir: repository_root).split("\0").empty?
28
+ return :dirty
29
+ end
30
+
31
+ if runner.query!("git", "rev-parse", "HEAD", chdir: repository_root).chomp != commit
32
+ return :commit_mismatch
33
+ end
34
+
35
+ :ok
36
+ end
37
+
38
+ def checkout(runner, repository_url:, commit:)
39
+ unless runner.query!("git", "status", "-s", "-z", chdir: repository_root).split("\0").empty?
40
+ runner.puts "📣 Stashing uncommited changes... Restore the changes by: `git stash pop`"
41
+ runner.execute!("git", "stash", "-u", "-m", "Stash by rbs-src on #{name}-#{version}", chdir: repository_root)
42
+ end
43
+
44
+ return if runner.query!("git", "rev-parse", "HEAD", chdir: repository_root).chomp == commit
45
+
46
+ unless runner.query?("git", "cat-file", "-e", commit, chdir: repository_root)
47
+ runner.puts "💾 Fetching from #{repository_url}..."
48
+ runner.execute!("git", "remote", "set-url", "origin", repository_url, chdir: repository_root)
49
+ runner.execute!("git", "fetch", "origin", chdir: repository_root)
50
+ end
51
+
52
+ runner.puts "💪 Checking out the commit #{commit}..."
53
+ runner.execute!("git", "checkout", commit, chdir: repository_root)
24
54
  end
25
55
 
26
56
  def clone(runner, repository_url:, commit:)
@@ -36,6 +66,9 @@ module Rbs
36
66
  end
37
67
 
38
68
  def link
69
+ Pathname.glob(rbs_path("*").to_s).each do |path|
70
+ File.unlink(path.to_s)
71
+ end
39
72
  File.symlink(repository_path.relative_path_from(rbs_path.parent), rbs_path)
40
73
  end
41
74
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rbs
4
4
  module Src
5
- VERSION = "0.4.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
data/lib/rbs/src.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "src/version"
4
4
 
5
5
  require "rbs"
6
6
  require "open3"
7
+ require "rainbow"
7
8
 
8
9
  require "rbs/src/gem"
9
10
  require "rbs/src/lockfile_loader"
@@ -2,7 +2,7 @@
2
2
  sources:
3
3
  - type: git
4
4
  name: ruby/gem_rbs_collection
5
- revision: '04470595f7a634757e160f61aafeb50536322bba'
5
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
6
6
  remote: https://github.com/ruby/gem_rbs_collection.git
7
7
  repo_dir: gems
8
8
  path: ".gem_rbs_collection"
@@ -47,6 +47,14 @@ gems:
47
47
  version: '0'
48
48
  source:
49
49
  type: stdlib
50
+ - name: rainbow
51
+ version: '3.0'
52
+ source:
53
+ type: git
54
+ name: ruby/gem_rbs_collection
55
+ revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
56
+ remote: https://github.com/ruby/gem_rbs_collection.git
57
+ repo_dir: gems
50
58
  - name: rbs
51
59
  version: 3.1.2
52
60
  source:
data/sig/open3.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Open3
2
+ def self.capture2e: (*String, ?chdir: Pathname) -> [String, Process::Status]
3
+ | (Hash[String, String] env, *String, ?chdir: Pathname) -> [String, Process::Status]
4
+ end
@@ -14,6 +14,8 @@ module Rbs
14
14
  def execute!: (*String, ?chdir: Pathname) -> void
15
15
 
16
16
  def query!: (*String, ?chdir: Pathname) -> String
17
+
18
+ def query?: (*String, ?chdir: Pathname) -> String?
17
19
  end
18
20
  end
19
21
  end
data/sig/rbs/gem.rbs CHANGED
@@ -19,11 +19,15 @@ module Rbs
19
19
  def repository_path: () -> Pathname
20
20
 
21
21
  # The path of the directory in the `#rbs_prefix` that contains the RBS files of the gem
22
- def rbs_path: () -> Pathname
22
+ def rbs_path: (?String suffix) -> Pathname
23
23
 
24
24
  def clone: (CommandRunner, repository_url: String, commit: String?) -> void
25
25
 
26
+ def checkout: (CommandRunner, repository_url: String, commit: String) -> void
27
+
26
28
  def link: () -> void
29
+
30
+ def status: (CommandRunner, commit: String) -> (:ok | :dirty | :commit_mismatch)
27
31
  end
28
32
  end
29
33
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-src
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.1
13
27
  description: rbs-src
14
28
  email:
15
29
  - matsumoto@soutaro.com
@@ -34,6 +48,7 @@ files:
34
48
  - lib/rbs/src/version.rb
35
49
  - rbs_collection.lock.yaml
36
50
  - rbs_collection.yaml
51
+ - sig/open3.rbs
37
52
  - sig/rbs/cli.rbs
38
53
  - sig/rbs/command_runner.rbs
39
54
  - sig/rbs/gem.rbs
@@ -62,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
77
  - !ruby/object:Gem::Version
63
78
  version: '0'
64
79
  requirements: []
65
- rubygems_version: 3.4.10
80
+ rubygems_version: 3.4.6
66
81
  signing_key:
67
82
  specification_version: 4
68
83
  summary: rbs-src