rbs 1.5.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 461e236c7a74ee03996267e889af1db65986af4ea1a9a3d258f9e84b23587182
4
- data.tar.gz: 53196811eeefb96f59d641d8a3c359fa2f84c43513dbc5eb46fa872b006147af
3
+ metadata.gz: de88dd41e7cee057e4668ffd3ed94e91d5d09746cdbfcd26602cc04b9ef2abd1
4
+ data.tar.gz: '06092d8a703d157bc214f81155bc24009491db68073fbcedc5fde9b09aca85e7'
5
5
  SHA512:
6
- metadata.gz: 1f7e1f726bda298d0186a9cdc106835ff35baa82aef50c0177ca2d66dea051a21fb499694c56e0910b5e543ccf029f53c349d0f2d4c1e7b89462e78c099ccf32
7
- data.tar.gz: 90d95f9ff0087ef339dc777e8db736ec849869842046f79e1e6a41eb56ed9826eeddb94ec06185f80abf04130dc98690f72697f9ad201468717b006d0d9a7781
6
+ metadata.gz: 2a53e2b25733fd63c832748ae629275becb31badd9b120cf2b8c72c66cea7e084d0aefefeaa09c00f2364ab1335ee030b0b54e8a14f3f7dbe08e1523cfe1d7e2
7
+ data.tar.gz: 66b02700d2a81f5d8367451356af01a0cac8b0152194adb5f844abf92ffdfc16bcec975f2e21302477b32ee344242d3e0407105c3cf4e7a78387fa454003a418
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
7
+ - package-ecosystem: "bundler"
8
+ directory: "/steep"
9
+ schedule:
10
+ interval: "daily"
data/CHANGELOG.md CHANGED
@@ -2,6 +2,57 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.6.2 (2021-09-09)
6
+
7
+ ## Signature updates
8
+
9
+ * `Enumerator::Lazy#force` ([\#782](https://github.com/ruby/rbs/pull/782))
10
+ * `IO.readlines` ([\#780](https://github.com/ruby/rbs/pull/780))
11
+
12
+ ## Miscellaneous
13
+
14
+ * Set `$XDG_CACHE_HOME` during test ([\#781](https://github.com/ruby/rbs/pull/781))
15
+
16
+ ## 1.6.1 (2021-09-05)
17
+
18
+ This is a minor release including test fixes.
19
+
20
+ ## Miscellaneous
21
+
22
+ * Fix stdlib test for `Resolv::Hosts` by removing `/etc/hosts` dependency ([\#779](https://github.com/ruby/rbs/pull/779))
23
+ * Fix bundler related test for test-bundled-gems ([\#778](https://github.com/ruby/rbs/pull/778))
24
+
25
+ ## 1.6.0 (2021-09-05)
26
+
27
+ This release includes a preview of `rbs collection` commands, which is _bundler for RBS_.
28
+ The command helps you manage RBS files from gem_rbs_collection or other repositories.
29
+
30
+ This feature is a preview, and any feedback is welcome!
31
+
32
+ ## Signature updates
33
+
34
+ * objspace ([\#763](https://github.com/ruby/rbs/pull/763), [\#776](https://github.com/ruby/rbs/pull/776))
35
+ * tempfile ([\#767](https://github.com/ruby/rbs/pull/767), [\#775](https://github.com/ruby/rbs/pull/775))
36
+ * `IO#set_encoding_by_bom` ([\#106](https://github.com/ruby/rbs/pull/106))
37
+ * `OpenSSL::PKey::EC#dh_compute_key` ([\#775](https://github.com/ruby/rbs/pull/775))
38
+
39
+ ## Library changes
40
+
41
+ * Add `rbs collection` ([\#589](https://github.com/ruby/rbs/pull/589), [\#772](https://github.com/ruby/rbs/pull/772), [\#773](https://github.com/ruby/rbs/pull/773))
42
+
43
+ ## Miscellaneous
44
+
45
+ * Let `bin/annotate-with-rdoc` process nested constants/classes ([\#766](https://github.com/ruby/rbs/pull/766), [\#768](https://github.com/ruby/rbs/pull/768))
46
+ * Stop printing version mismatch message in CI ([\#777](https://github.com/ruby/rbs/pull/777))
47
+ * Update Steep and fix type errors ([\#770](https://github.com/ruby/rbs/pull/770), [\#774](https://github.com/ruby/rbs/pull/774))
48
+ * Add dependabot configuration ([\#771](https://github.com/ruby/rbs/pull/771))
49
+
50
+ ## 1.5.1 (2021-08-22)
51
+
52
+ ### Miscellaneous
53
+
54
+ * Fix Net_HTTP_test ([\#759](https://github.com/ruby/rbs/pull/759))
55
+
5
56
  ## 1.5.0 (2021-08-22)
6
57
 
7
58
  This release includes stdlib signature updates.
data/Gemfile CHANGED
@@ -16,6 +16,7 @@ gem 'stackprof'
16
16
  gem "goodcheck"
17
17
  gem "dbm"
18
18
  gem 'digest'
19
+ gem 'tempfile'
19
20
 
20
21
  # Test gems
21
22
  gem "rbs-amber", path: "test/assets/test-gem"
data/Steepfile CHANGED
@@ -1,13 +1,21 @@
1
+ D = Steep::Diagnostic
2
+
1
3
  target :lib do
2
4
  signature "sig"
3
5
  check "lib"
4
6
  ignore "lib/rbs/parser.rb"
5
7
  ignore "lib/rbs/prototype", "lib/rbs/test", "lib/rbs/test.rb"
6
8
 
7
- library "set", "pathname", "json", "logger", "monitor", "tsort"
9
+ library "set", "pathname", "json", "logger", "monitor", "tsort", "uri"
8
10
  signature "stdlib/strscan/0/"
9
11
  signature "stdlib/rubygems/0/"
10
12
  signature "stdlib/optparse/0/"
13
+
14
+ configure_code_diagnostics do |config|
15
+ config[D::Ruby::MethodDefinitionMissing] = :hint
16
+ config[D::Ruby::ElseOnExhaustiveCase] = :hint
17
+ config[D::Ruby::FallbackAny] = :hint
18
+ end
11
19
  end
12
20
 
13
21
  # target :lib do
data/core/enumerator.rbs CHANGED
@@ -249,6 +249,7 @@ class Enumerator::Generator[out Elem] < Object
249
249
  end
250
250
 
251
251
  class Enumerator::Lazy[out Elem, out Return] < Enumerator[Elem, Return]
252
+ alias force to_a
252
253
  end
253
254
 
254
255
  class Enumerator::Yielder < Object
data/core/io.rbs CHANGED
@@ -635,6 +635,8 @@ class IO < Object
635
635
  def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self
636
636
  | (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self
637
637
 
638
+ def set_encoding_by_bom: () -> Encoding?
639
+
638
640
  # Returns status information for *ios* as an object of type `File::Stat` .
639
641
  #
640
642
  # ```ruby
@@ -747,7 +749,7 @@ class IO < Object
747
749
 
748
750
  def self.read: (String name, ?Integer length, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> String
749
751
 
750
- def self.readlines: (String name, ?String sep, ?Integer limit, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> ::Array[String]
752
+ def self.readlines: (String name, ?String sep, ?Integer limit, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode, ?chomp: boolish) -> ::Array[String]
751
753
 
752
754
  def self.select: [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array) -> [Array[X], Array[Y], Array[Z]]
753
755
  | [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array, Numeric? timeout) -> [Array[X], Array[Y], Array[Z]]?
@@ -0,0 +1,116 @@
1
+ # RBS Collection manager
2
+
3
+ `rbs collection` sub command manages third party gems' RBS. In short, it is `bundler` for RBS.
4
+
5
+ ## Requirements
6
+
7
+ * `git(1)`
8
+ * `Gemfile.lock`
9
+
10
+
11
+ ## Usage
12
+
13
+ ### Setup
14
+
15
+ First, generate the configuration file, `rbs_collection.yaml`, with `rbs collection init`.
16
+
17
+ ```console
18
+ $ rbs collection init
19
+ created: rbs_collection.yaml
20
+
21
+ $ cat rbs_collection.yaml
22
+ # Download sources
23
+ sources:
24
+ - name: ruby/gem_rbs_collection
25
+ remote: https://github.com/ruby/gem_rbs_collection.git
26
+ revision: main
27
+ repo_dir: gems
28
+
29
+ # A directory to install the downloaded RBSs
30
+ path: .gem_rbs_collection
31
+
32
+ gems:
33
+ # Skip loading rbs gem's RBS.
34
+ # It's unnecessary if you don't use rbs as a library.
35
+ - name: rbs
36
+ ignore: true
37
+ ```
38
+
39
+ I also recommend updating `.gitignore`.
40
+
41
+ ```console
42
+ $ echo /.gem_rbs_collection/ >> .gitignore
43
+ ```
44
+
45
+ ### Install dependencies
46
+
47
+ Then, install gems' RBS with `rbs collection install`! It copies RBS from [the gem RBS repository](https://github.com/ruby/gem_rbs_collection) to `.gem_rbs_collection/` directory by default.
48
+ I recommend to ignore `.gem_rbs_collection/` from version control system, such as Git.
49
+
50
+ ```console
51
+ $ rbs collection install
52
+ Installing ast:2.4 (ruby/gem_rbs_collection@4b1a2a2f64c)
53
+ ...
54
+ It's done! 42 gems's RBSs now installed.
55
+ ```
56
+
57
+ Finally the third party RBSs are available! `rbs` commands, such as `rbs validate`, automatically load the third party RBSs.
58
+
59
+ ### Other commands
60
+
61
+ `rbs collection` has two more commands.
62
+
63
+ * `rbs collection update` updates `rbs_collection.lock.yaml`.
64
+ * `rbs collection clean` removes unnecessary rbs from `.gem_rbs_collection` directory.
65
+
66
+ ## Configuration
67
+
68
+ Configure `rbs collection` with editing `rbs_collection.yaml`.
69
+
70
+ ```yaml
71
+ # Download sources.
72
+ # You can add own collection git repository.
73
+ sources:
74
+ - name: ruby/gem_rbs_collection
75
+ remote: https://github.com/ruby/gem_rbs_collection.git
76
+ revision: main
77
+ repo_dir: gems
78
+
79
+ # A directory to install the downloaded RBSs
80
+ path: .gem_rbs_collection
81
+
82
+ gems:
83
+ # If the Gemfile.lock doesn't contain csv gem but you use csv gem,
84
+ # you can write the gem name explicitly to install RBS of the gem.
85
+ - name: csv
86
+
87
+ # If the Gemfile.lock contains nokogiri gem but you don't want to use the RBS,
88
+ # you can ignore the gem.
89
+ # `rbs collection` avoids to install nokogiri gem's RBS by this change.
90
+ # It is useful if the nokogiri RBS has a problem, such as compatibility issue with other RBS.
91
+ - name: nokogiri
92
+ ignore: true
93
+ ```
94
+
95
+ ## Files / Directories
96
+
97
+ * `rbs_collection.yaml`
98
+ * The configuration file.
99
+ * You need to edit it if:
100
+ * You don't want to ignore gem's RBS.
101
+ * You want to add gem's RBS explicitly.
102
+ * You can change the file path with `--collection` option. e.g. `rbs --collection another_conf.yaml collection install`.
103
+ * `rbs_collection.lock.yaml`
104
+ * RBS installs and loads RBS files with this file.
105
+ * It is auto-generated file. Do not edit this file.
106
+ * I recommend to manage it with VCS such as git.
107
+ * `.gem_rbs_collection/`
108
+ * RBS installs third party RBS files to the directory.
109
+ * I recommend to ignore it from VCS.
110
+ * You can change the path with `path` option of `rbs_collection.yaml` file.
111
+
112
+
113
+ ## How it works
114
+
115
+ `rbs collection` is integrated with Bundler.
116
+ `rbs collection install` command generates `gem_rbs_collection.lock.yaml` from `gem_rbs_collection.yaml` and `Gemfile.lock`. It uses `Gemfile.lock` to detects dependencies.
@@ -51,5 +51,6 @@ module RBS
51
51
  Regexp = Name.define(:Regexp)
52
52
  TrueClass = Name.define(:TrueClass)
53
53
  FalseClass = Name.define(:FalseClass)
54
+ Numeric = Name.define(:Numeric)
54
55
  end
55
56
  end
data/lib/rbs/cli.rb CHANGED
@@ -6,6 +6,7 @@ module RBS
6
6
  class CLI
7
7
  class LibraryOptions
8
8
  attr_accessor :core_root
9
+ attr_accessor :config_path
9
10
  attr_reader :repos
10
11
  attr_reader :libs
11
12
  attr_reader :dirs
@@ -16,6 +17,7 @@ module RBS
16
17
 
17
18
  @libs = []
18
19
  @dirs = []
20
+ @config_path = Collection::Config::PATH
19
21
  end
20
22
 
21
23
  def loader
@@ -25,6 +27,8 @@ module RBS
25
27
  end
26
28
 
27
29
  loader = EnvironmentLoader.new(core_root: core_root, repository: repository)
30
+ lock = config_path&.then { |p| Collection::Config.lockfile_of(p) }
31
+ loader.add_collection(lock) if lock
28
32
 
29
33
  dirs.each do |dir|
30
34
  loader.add(path: Pathname(dir))
@@ -52,6 +56,14 @@ module RBS
52
56
  self.core_root = nil
53
57
  end
54
58
 
59
+ opts.on('--collection PATH', "File path of collection configration (default: #{Collection::Config::PATH})") do |path|
60
+ self.config_path = Pathname(path).expand_path
61
+ end
62
+
63
+ opts.on('--no-collection', 'Ignore collection configration') do
64
+ self.config_path = nil
65
+ end
66
+
55
67
  opts.on("--repo DIR", "Add RBS repository") do |dir|
56
68
  repos << dir
57
69
  end
@@ -68,7 +80,7 @@ module RBS
68
80
  @stderr = stderr
69
81
  end
70
82
 
71
- COMMANDS = [:ast, :list, :ancestors, :methods, :method, :validate, :constant, :paths, :prototype, :vendor, :parse, :test]
83
+ COMMANDS = [:ast, :list, :ancestors, :methods, :method, :validate, :constant, :paths, :prototype, :vendor, :parse, :test, :collection]
72
84
 
73
85
  def parse_logging_options(opts)
74
86
  opts.on("--log-level LEVEL", "Specify log level (defaults to `warn`)") do |level|
@@ -819,11 +831,90 @@ EOB
819
831
 
820
832
  # @type var out: String
821
833
  # @type var err: String
822
- out, err, status = Open3.capture3(env_hash, *args)
834
+ out, err, status = __skip__ = Open3.capture3(env_hash, *args)
823
835
  stdout.print(out)
824
836
  stderr.print(err)
825
837
 
826
838
  status
827
839
  end
840
+
841
+ def run_collection(args, options)
842
+ warn "warning: rbs collection is experimental, and the behavior may change until RBS v2.0"
843
+
844
+ opts = collection_options(args)
845
+ params = {}
846
+ opts.order args.drop(1), into: params
847
+ config_path = options.config_path or raise
848
+ lock_path = Collection::Config.to_lockfile_path(config_path)
849
+
850
+ case args[0]
851
+ when 'install'
852
+ unless params[:frozen]
853
+ Collection::Config.generate_lockfile(config_path: config_path, gemfile_lock_path: Pathname('./Gemfile.lock'))
854
+ end
855
+ Collection::Installer.new(lockfile_path: lock_path, stdout: stdout).install_from_lockfile
856
+ when 'update'
857
+ # TODO: Be aware of argv to update only specified gem
858
+ Collection::Config.generate_lockfile(config_path: config_path, gemfile_lock_path: Pathname('./Gemfile.lock'), with_lockfile: false)
859
+ Collection::Installer.new(lockfile_path: lock_path, stdout: stdout).install_from_lockfile
860
+ when 'init'
861
+ if config_path.exist?
862
+ puts "#{config_path} already exists"
863
+ exit 1
864
+ end
865
+
866
+ config_path.write(<<~'YAML')
867
+ # Download sources
868
+ sources:
869
+ - name: ruby/gem_rbs_collection
870
+ remote: https://github.com/ruby/gem_rbs_collection.git
871
+ revision: main
872
+ repo_dir: gems
873
+
874
+ # A directory to install the downloaded RBSs
875
+ path: .gem_rbs_collection
876
+
877
+ gems:
878
+ # Skip loading rbs gem's RBS.
879
+ # It's unnecessary if you don't use rbs as a library.
880
+ - name: rbs
881
+ ignore: true
882
+ YAML
883
+ stdout.puts "created: #{config_path}"
884
+ when 'clean'
885
+ unless lock_path.exist?
886
+ puts "#{lock_path} should exist to clean"
887
+ exit 1
888
+ end
889
+ Collection::Cleaner.new(lockfile_path: lock_path)
890
+ when 'help'
891
+ puts opts.help
892
+ else
893
+ puts opts.help
894
+ exit 1
895
+ end
896
+ end
897
+
898
+ def collection_options(args)
899
+ OptionParser.new do |opts|
900
+ opts.banner = <<~HELP
901
+ Usage: rbs collection [install|update|init|clean|help]
902
+
903
+ Manage RBS collection, which contains third party RBS.
904
+
905
+ Examples:
906
+
907
+ # Initialize the configration file
908
+ $ rbs collection init
909
+
910
+ # Generate the lock file and install RBSs from the lock file
911
+ $ rbs collection install
912
+
913
+ # Update the RBSs
914
+ $ rbs collection update
915
+ HELP
916
+ opts.on('--frozen') if args[0] == 'install'
917
+ end
918
+ end
828
919
  end
829
920
  end
@@ -0,0 +1,29 @@
1
+ module RBS
2
+ module Collection
3
+ class Cleaner
4
+ attr_reader :lock
5
+
6
+ def initialize(lockfile_path:)
7
+ @lock = Config.from_path(lockfile_path)
8
+ end
9
+
10
+ def clean
11
+ lock.repo_path.glob('*/*') do |dir|
12
+ *_, gem_name, version = dir.to_s.split('/')
13
+ gem_name or raise
14
+ version or raise
15
+ next if needed? gem_name, version
16
+
17
+ FileUtils.remove_entry_secure(dir.to_s)
18
+ end
19
+ end
20
+
21
+ def needed?(gem_name, version)
22
+ gem = lock.gem(gem_name)
23
+ return false unless gem
24
+
25
+ gem['version'] == version
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,95 @@
1
+ module RBS
2
+ module Collection
3
+
4
+ # This class represent the configration file.
5
+ class Config
6
+ class LockfileGenerator
7
+ attr_reader :config, :lock, :gemfile_lock, :lock_path
8
+
9
+ def self.generate(config_path:, gemfile_lock_path:, with_lockfile: true)
10
+ new(config_path: config_path, gemfile_lock_path: gemfile_lock_path, with_lockfile: with_lockfile).generate
11
+ end
12
+
13
+ def initialize(config_path:, gemfile_lock_path:, with_lockfile:)
14
+ @config = Config.from_path config_path
15
+ @lock_path = Config.to_lockfile_path(config_path)
16
+ @lock = Config.from_path(lock_path) if lock_path.exist? && with_lockfile
17
+ @gemfile_lock = Bundler::LockfileParser.new(gemfile_lock_path.read)
18
+ end
19
+
20
+ def generate
21
+ config.gems.each do |gem|
22
+ assign_gem(gem_name: gem['name'], version: gem['version'])
23
+ end
24
+
25
+ gemfile_lock_gems do |spec|
26
+ assign_gem(gem_name: spec.name, version: spec.version)
27
+ end
28
+ remove_ignored_gems!
29
+
30
+ config.dump_to(lock_path)
31
+ config
32
+ end
33
+
34
+ private def assign_gem(gem_name:, version:)
35
+ locked = lock&.gem(gem_name)
36
+ specified = config.gem(gem_name)
37
+
38
+ return if specified&.dig('ignore')
39
+ return if specified&.dig('source') # skip if the source is already filled
40
+
41
+ if locked
42
+ # If rbs_collection.lock.yaml contain the gem, use it.
43
+ upsert_gem specified, locked
44
+ else
45
+ # Find the gem from gem_collection.
46
+ source = find_source(gem_name: gem_name)
47
+ return unless source
48
+
49
+ installed_version = version
50
+ best_version = find_best_version(version: installed_version, versions: source.versions({ 'name' => gem_name }))
51
+ # @type var new_content: RBS::Collection::Config::gem_entry
52
+ new_content = {
53
+ 'name' => gem_name,
54
+ 'version' => best_version.to_s,
55
+ 'source' => source.to_lockfile,
56
+ }
57
+ upsert_gem specified, new_content
58
+ end
59
+ end
60
+
61
+ private def upsert_gem(old, new)
62
+ if old
63
+ old.merge! new
64
+ else
65
+ config.add_gem new
66
+ end
67
+ end
68
+
69
+ private def remove_ignored_gems!
70
+ config.gems.reject! { |gem| gem['ignore'] }
71
+ end
72
+
73
+ private def gemfile_lock_gems(&block)
74
+ gemfile_lock.specs.each do |spec|
75
+ yield spec
76
+ end
77
+ end
78
+
79
+ private def find_source(gem_name:)
80
+ sources = config.sources
81
+
82
+ sources.find { |c| c.has?({ 'name' => gem_name, 'revision' => nil } ) }
83
+ end
84
+
85
+ private def find_best_version(version:, versions:)
86
+ candidates = versions.map { |v| Gem::Version.create(v) or raise }
87
+ return candidates.max || raise unless version
88
+
89
+ v = Gem::Version.create(version) or raise
90
+ Repository.find_best_version(v, candidates)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end