conda 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 468bb39448975aef91684345ee12a2924d8442d1
4
+ data.tar.gz: c152bcc2f9a18b4fd0f4b875bc50aa4de7c4d6c2
5
+ SHA512:
6
+ metadata.gz: 2280a7a6a92e2fc5c8ac77bdf9502257bbe3cb0fe980c3352aa6b780a6a17538ae1f0176a6c78ed12b45b659b85282c9545d7df98f20486d596aaf0571e7d2c8
7
+ data.tar.gz: 8e9a3789c5647a54ecfbcc1aa61244450decfedbab4e839bd03ed8496e31b7a0e708aa92d37a3f647cc6e12c2982195784a0b8a27bdb4d5e290218289e72323d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in conda.gemspec
4
+ gemspec
@@ -0,0 +1,44 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Isuru Fernando
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
23
+ -------------------------------------------------------------------------------
24
+ conda.rb is a port of Conda.jl to ruby. License of Conda.jl follow.
25
+
26
+ Copyright (c) 2015: Guillaume Fraux
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a copy
29
+ of this software and associated documentation files (the "Software"), to deal
30
+ in the Software without restriction, including without limitation the rights
31
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32
+ copies of the Software, and to permit persons to whom the Software is
33
+ furnished to do so, subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in
36
+ all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44
+ THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # Conda
2
+
3
+ ## Installation
4
+
5
+ Execute:
6
+
7
+ gem install conda --user
8
+
9
+ Note: `--user` switch is important as conda.rb needs to be installed in a
10
+ writable folder.
11
+
12
+ ## Usage
13
+
14
+ To use the package do:
15
+
16
+ require 'conda'
17
+
18
+ To install a conda package do
19
+
20
+ Conda.add("jupyter")
21
+
22
+ To use a custom channel do
23
+
24
+ Conda.add_channel("conda-forge")
25
+
26
+ To update a package do
27
+
28
+ Conda.update("jupyter")
29
+
30
+ To install a specific version of a package do
31
+
32
+ Conda.install("jupyter==1.0")
33
+
34
+ To get the version of a package do
35
+
36
+ Conda.version("jupyter")
37
+
38
+ ## Development
39
+
40
+ gem build conda.gemspec
41
+ gem install conda-0.1.0.gem
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the
46
+ [MIT License](https://github.com/isuruf/conda.rb).
47
+
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "conda"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Isuru Fernando"]
9
+ spec.email = ["isuruf@gmail.com"]
10
+
11
+ spec.summary = "Ruby interface to Conda for binary packages"
12
+ spec.homepage = "https://github.com/isuruf/conda.rb"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+
17
+ end
18
+
@@ -0,0 +1,194 @@
1
+ require 'fileutils'
2
+ require 'open-uri'
3
+
4
+ module Conda
5
+ "Prefix for installation of all the packages."
6
+ PREFIX = File.absolute_path(File.join(File.dirname(__FILE__), "..", "usr"))
7
+
8
+ "Prefix for the executable files installed with the packages"
9
+ BINDIR = Gem.win_platform? ? File.join(PREFIX, "Library", "bin") : File.join(PREFIX, "bin")
10
+
11
+ "Prefix for the library files installed with the packages"
12
+ LIBDIR = Gem.win_platform? ? File.join(PREFIX, "Library", "lib") : File.join(PREFIX, "lib")
13
+
14
+ "Prefix for the python scripts. On UNIX, this is the same than Conda.BINDIR"
15
+ SCRIPTDIR = Gem.win_platform? ? File.join(PREFIX, "Scripts") : BINDIR
16
+
17
+ "Prefix where the `python` command lives"
18
+ PYTHONDIR = Gem.win_platform? ? PREFIX : BINDIR
19
+
20
+ "Path to the `conda` binary"
21
+ CONDA = Gem.win_platform? ? File.join(SCRIPTDIR, "conda.exe") : File.join(SCRIPTDIR, "conda")
22
+
23
+ "Path to the condarc file"
24
+ CONDARC = File.join(PREFIX, "condarc-ruby")
25
+
26
+ """
27
+ Use a cleaned up environment for the command `cmd`.
28
+ Any environment variable starting by CONDA will interact with the run.
29
+ """
30
+ def Conda.run_in_env(cmd)
31
+ env = ENV.to_hash
32
+ to_remove = []
33
+ for var in env.keys
34
+ if var.start_with?("CONDA")
35
+ to_remove << var
36
+ end
37
+ end
38
+ for var in to_remove
39
+ env[var] = nil
40
+ end
41
+ env["CONDARC"] = CONDARC
42
+ ENV.replace(env)
43
+ return `#{cmd}`
44
+ end
45
+
46
+ "Get the miniconda installer URL."
47
+ def Conda._installer_url()
48
+ res = "http://repo.continuum.io/miniconda/Miniconda3-latest-"
49
+ if RbConfig::CONFIG["host"].include? "darwin"
50
+ res += "MacOSX"
51
+ elsif RbConfig::CONFIG["host"].include? "linux"
52
+ res += "Linux"
53
+ elsif Gem.win_platform?
54
+ res += "Windows"
55
+ else
56
+ raise("Unsuported OS.")
57
+ end
58
+ res += (RbConfig::CONFIG["host"].include? "x86_64") ? "-x86_64" : "-x86"
59
+ res += Gem.win_platform? ? ".exe" : ".sh"
60
+ return res
61
+ end
62
+
63
+ "Install miniconda if it hasn't been installed yet; Conda._install_conda(true) installs Conda even if it has already been installed."
64
+ def Conda._install_conda(force=false)
65
+
66
+ if force || !(File.file? (CONDA))
67
+ # Ensure PREFIX exists
68
+ Dir.mkdir(PREFIX) unless File.exists?(PREFIX)
69
+ print("Downloading miniconda installer ...\n")
70
+ if Gem.win_platform?
71
+ installer = File.join(PREFIX, "installer.exe")
72
+ else
73
+ installer = File.join(PREFIX, "installer.sh")
74
+ end
75
+ IO.copy_stream(open(Conda._installer_url()), installer)
76
+
77
+ print("Installing miniconda ...\n")
78
+ if Gem.win_platform?
79
+ `#{installer} /S /AddToPath=0 /RegisterPython=0 /D#{PREFIX}`
80
+ else
81
+ `chmod 755 #{installer}`
82
+ `#{installer} -b -f -p #{PREFIX}`
83
+ end
84
+ Conda.add_channel("defaults")
85
+ end
86
+ end
87
+
88
+ "Install a new package."
89
+ def Conda.add(pkg)
90
+ Conda._install_conda()
91
+ Conda.run_in_env("#{CONDA} install -y #{pkg} 1>&2")
92
+ end
93
+
94
+ "Uninstall a package."
95
+ def Conda.rm(pkg)
96
+ Conda._install_conda()
97
+ run_in_env("#{CONDA} remove -y #{pkg} 1>&2")
98
+ end
99
+
100
+ "Update all installed packages."
101
+ def Conda.update()
102
+ Conda._install_conda()
103
+ for pkg in Conda.installed_packages()
104
+ run_in_env("#{CONDA} update -y #{pkg} 1>&2")
105
+ end
106
+ end
107
+
108
+ "List all installed packages as an dict of tuples with (version_number, fullname)."
109
+ def Conda.installed_packages_dict()
110
+ Conda._install_conda()
111
+ package_dict = {}
112
+ for line in Conda.run_in_env("#{CONDA} list --export").split()
113
+ if not line.start_with? "#"
114
+ name, version, build_string = line.split("=")
115
+ package_dict[name] = [Gem::Version.new(version), line]
116
+ end
117
+ end
118
+ return package_dict
119
+ end
120
+
121
+ "List all installed packages as an array."
122
+ def Conda.installed_packages()
123
+ return Conda.installed_packages_dict().keys
124
+ end
125
+
126
+ "List all installed packages to standard output."
127
+ def Conda.list()
128
+ Conda._install_conda()
129
+ Conda.run_in_env("#{CONDA} list 1>&2")
130
+ end
131
+
132
+ "Get the exact version of a package."
133
+ def Conda.version(name)
134
+ Conda._install_conda()
135
+ packages = JSON.parse(run_in_env("#{CONDA} list --json"))
136
+ for package in packages
137
+ if package.startswith? name or package.include? "::#{name}"
138
+ return package
139
+ end
140
+ end
141
+ raise("Could not find the #{name} package")
142
+ end
143
+
144
+ "Search a specific version of a package"
145
+ def Conda.search(pkg, ver=nil)
146
+ Conda._install_conda()
147
+ ret=JSON.parse(run_in_env("#{CONDA} search #{pkg} --json"))
148
+ if ver == nil
149
+ return ret.keys
150
+ end
151
+ out = []
152
+ for k in ret.keys
153
+ for i in ret[k].length
154
+ if ret[k][i]["version"] == ver
155
+ out << k
156
+ end
157
+ end
158
+ end
159
+ out
160
+ end
161
+
162
+ "Check if a given package exists."
163
+ def Conda.exists(package)
164
+ if package.include? ("==")
165
+ pkg,ver=package.split("==") # Remove version if provided
166
+ return Conda.search(pkg,ver).include? pkg
167
+ else
168
+ return Conda.search(package).include? package
169
+ end
170
+ end
171
+
172
+ "Get the list of channels used to search packages"
173
+ def Conda.channels()
174
+ Conda._install_conda()
175
+ ret=JSON.parse(Conda.run_in_env("#{CONDA} config --get channels --json"))
176
+ if ret["get"].has_key? "channels"
177
+ return ret["get"]["channels"]
178
+ else
179
+ return []
180
+ end
181
+ end
182
+
183
+ "Add a channel to the list of channels"
184
+ def Conda.add_channel(channel)
185
+ Conda._install_conda()
186
+ Conda.run_in_env("#{CONDA} config --add channels #{channel} --force")
187
+ end
188
+
189
+ "Remove a channel from the list of channels"
190
+ def Conda.rm_channel(channel)
191
+ Conda._install_conda()
192
+ Conda.run_in_env("#{CONDA} config --remove channels #{channel} --force")
193
+ end
194
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Isuru Fernando
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - isuruf@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - conda.gemspec
26
+ - lib/conda.rb
27
+ homepage: https://github.com/isuruf/conda.rb
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.5.1
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Ruby interface to Conda for binary packages
51
+ test_files: []