Skip to content

Commit

Permalink
feat: drop external dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dysonreturns committed Feb 6, 2024
1 parent 4ca8c2b commit ef6018c
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 15 deletions.
1 change: 1 addition & 0 deletions .standard.yml
Expand Up @@ -3,6 +3,7 @@ ruby_version: 3.3
ignore: # default: []
- 'data/**/*'
- 'lib/docker_build/**/*'
- 'lib/sc2ai/overrides/async/**/*'
# Testing by hand
- 'outside_*.rb'
- 'test/**/*'
Expand Down
6 changes: 0 additions & 6 deletions Gemfile
Expand Up @@ -2,11 +2,5 @@

source "https://rubygems.org"

if Gem.win_platform?
# These only matter on windows
gem "kdtree", git: "https://github.com/dysonreturns/kdtree.git", branch: "master"
gem "async-process", git: "https://github.com/dysonreturns/async-process.git", branch: "windows-pgroup-params"
end

# Specify your gem's dependencies in sc2ai.gemspec
gemspec
1 change: 0 additions & 1 deletion exe/sc2ai
Expand Up @@ -4,7 +4,6 @@
# require "pathname"
# $LOAD_PATH.unshift(Pathname(File.dirname(__FILE__)).parent.join("lib").expand_path.to_s)

require "sc2ai"
require "sc2ai/cli/cli"

# This got old quickly.
Expand Down
2 changes: 1 addition & 1 deletion lib/sc2ai.rb
Expand Up @@ -60,7 +60,7 @@
# noinspection RubyMismatchedArgumentType
Dir[File.join(__dir__, "sc2ai", "local_play", "**", "*.rb")].each { |file| require(file) }

# Facilitates creating and running Starcraft 2 AI instances.
# Facilitates StarCraft 2 AI
module Sc2
# Generic, single error for everything Sc2
class Error < StandardError; end
Expand Down
4 changes: 3 additions & 1 deletion lib/sc2ai/cli/new.rb
@@ -1,3 +1,5 @@
require "sc2ai/paths"

module Sc2
# Command line utilities
class Cli < Thor
Expand All @@ -10,7 +12,7 @@ class New < Thor::Group
argument :race, required: true, desc: "Choose a race", enum: %w[Terran Zerg Protoss Random]

def self.source_root
Paths.template_root.to_s
Sc2::Paths.template_root.to_s
end

def checkname
Expand Down
1 change: 0 additions & 1 deletion lib/sc2ai/local_play/client.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "async/process"
require_relative "client/configurable_options"

module Sc2
Expand Down
31 changes: 31 additions & 0 deletions lib/sc2ai/overrides/async/process/child.rb
@@ -0,0 +1,31 @@
# Overrides process spawn for windows pgroup

require "async/process"

module Async
module Process
class Child
def initialize(*args, **options)
# Setup a cross-thread notification pipe - nio4r can't monitor pids unfortunately:
pipe = ::IO.pipe
@input = Async::IO::Generic.new(pipe.first)
@output = pipe.last

@exit_status = nil

if Gem.win_platform?
options[:new_pgroup] = true
else
options[:pgroup] = true
end

@pid = ::Process.spawn(*args, **options)

@thread = Thread.new do
_, @exit_status = ::Process.wait2(@pid)
@output.close
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/sc2ai/paths.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "tmpdir"
require "pathname"

module Sc2
# Helps determine common paths to sc2 install dir, executable and maps.
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/new/run_example_match.rb.tt
Expand Up @@ -10,5 +10,5 @@ Sc2::Match.new(
$bot,
Sc2::Player::Computer.new(race: Api::Race::Random, difficulty: Api::Difficulty::VeryEasy)
],
map: "Equilibrium512AIE" # Or any of the downloaded map names
map: "Goldenaura512AIE" # Or any of the downloaded map names
).run
8 changes: 4 additions & 4 deletions sc2ai.gemspec
@@ -1,10 +1,8 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.expand_path("lib"))
$LOAD_PATH.unshift(File.expand_path("./lib"))
require_relative "lib/sc2ai/version"

# require "pp" # Fixes fakefs during specs for some reason. see fakefs github.

Gem::Specification.new do |spec|
spec.name = "sc2ai"
spec.version = Sc2::VERSION
Expand Down Expand Up @@ -45,12 +43,14 @@ Gem::Specification.new do |spec|

# Geometry
spec.add_dependency "perfect-shape", "1.0.8"
spec.add_dependency "kdtree", "0.4"

spec.add_dependency "numo-narray", "0.9.2.1"
spec.add_dependency "numo-linalg", "0.1.7"
spec.add_dependency "rumale", "0.28.1"

# TODO: Find a way to not depend on a patched gem and yank this
spec.add_dependency "sc2ai-kdtree", "~> 0.4"

# Pre-packaged ladder dependencies
# We add these locally, so that authors know what to use
# spec.add_dependency "activerecord", "7.1.2"
Expand Down

0 comments on commit ef6018c

Please sign in to comment.