bee_python 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/lib/bee_task_python.rb +60 -21
- metadata +5 -5
data/README
CHANGED
data/lib/bee_task_python.rb
CHANGED
@@ -356,17 +356,67 @@ module Bee
|
|
356
356
|
|
357
357
|
# Check Python dependencies using PIP (see http://pypi.python.org/pypi/pip).
|
358
358
|
# Takes a single parameter that is the map of dependencies that gives version
|
359
|
-
# for a given dependency. A
|
359
|
+
# for a given dependency. A version set to ~ (or nil) indicates that this
|
360
360
|
# dependency is needed in any version (useful for developement libraries used
|
361
361
|
# for development).
|
362
362
|
#
|
363
363
|
# Example:
|
364
364
|
#
|
365
365
|
# - python.dependencies: { Django: "1.2.3", PyYAML: ~ }
|
366
|
-
def dependencies(
|
367
|
-
error "python.
|
368
|
-
|
366
|
+
def dependencies(deps)
|
367
|
+
error "python.dependencies parameter is a Map" unless
|
368
|
+
deps.kind_of?(Hash)
|
369
369
|
puts "Checking Python dependencies..."
|
370
|
+
installed = installed_dependencies()
|
371
|
+
check_dependencies(deps, installed)
|
372
|
+
end
|
373
|
+
|
374
|
+
# Check Python dependencies using PIP (see http://pypi.python.org/pypi/pip).
|
375
|
+
# Takes a single parameter that is the requirements file name. A dependency
|
376
|
+
# may specify no version, in this case we check that dependency in installed
|
377
|
+
# in any version..
|
378
|
+
#
|
379
|
+
# Example:
|
380
|
+
#
|
381
|
+
# - python.requirements: requirements.txt
|
382
|
+
def requirements(reqs)
|
383
|
+
error "python.requirements parameter is a string" unless
|
384
|
+
reqs.kind_of?(String)
|
385
|
+
puts "Checking Python requirements..."
|
386
|
+
installed = installed_dependencies()
|
387
|
+
content = File.read(reqs).strip
|
388
|
+
dependencies = {}
|
389
|
+
for line in content
|
390
|
+
if line =~ /.+==.+/
|
391
|
+
name, version = line.scan(/[^=]+/).map{|e| e.strip}
|
392
|
+
dependencies[name] = version
|
393
|
+
else
|
394
|
+
dependencies[line.strip] = nil
|
395
|
+
end
|
396
|
+
end
|
397
|
+
check_dependencies(dependencies, installed)
|
398
|
+
end
|
399
|
+
|
400
|
+
private
|
401
|
+
|
402
|
+
# Add directories to the Python path environment variable.
|
403
|
+
# - dirs: directory (string) or list of directories to add to path.
|
404
|
+
def add_python_path(dirs)
|
405
|
+
if dirs and dirs.length > 0
|
406
|
+
dirs = Array(dirs)
|
407
|
+
puts "Adding to PYTHONPATH: '#{dirs.join(',')}'" if @verbose
|
408
|
+
if ENV['PYTHONPATH']
|
409
|
+
ENV['PYTHONPATH'] = dirs.join(File::PATH_SEPARATOR) +
|
410
|
+
File::PATH_SEPARATOR + ENV['PYTHONPATH'] if dirs.length > 0
|
411
|
+
else
|
412
|
+
ENV['PYTHONPATH'] = dirs.join(File::PATH_SEPARATOR)
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
# Get installed dependencies running PIP and return them as a map
|
418
|
+
# with dependencies names and versions.
|
419
|
+
def installed_dependencies
|
370
420
|
lines = `pip freeze`.strip.split("\n")
|
371
421
|
installed = {}
|
372
422
|
for line in lines
|
@@ -377,6 +427,12 @@ module Bee
|
|
377
427
|
installed[name] = version
|
378
428
|
end
|
379
429
|
end
|
430
|
+
installed
|
431
|
+
end
|
432
|
+
|
433
|
+
# Check that dependencies (as a map) are installed. Throws an error if
|
434
|
+
# not.
|
435
|
+
def check_dependencies(dependencies, installed)
|
380
436
|
for name in dependencies.keys.sort
|
381
437
|
if installed.has_key?(name)
|
382
438
|
if not dependencies[name] or dependencies[name] == '*'
|
@@ -394,23 +450,6 @@ module Bee
|
|
394
450
|
end
|
395
451
|
end
|
396
452
|
|
397
|
-
private
|
398
|
-
|
399
|
-
# Add directories to the Python path environment variable.
|
400
|
-
# - dirs: directory (string) or list of directories to add to path.
|
401
|
-
def add_python_path(dirs)
|
402
|
-
if dirs and dirs.length > 0
|
403
|
-
dirs = Array(dirs)
|
404
|
-
puts "Adding to PYTHONPATH: '#{dirs.join(',')}'" if @verbose
|
405
|
-
if ENV['PYTHONPATH']
|
406
|
-
ENV['PYTHONPATH'] = dirs.join(File::PATH_SEPARATOR) +
|
407
|
-
File::PATH_SEPARATOR + ENV['PYTHONPATH'] if dirs.length > 0
|
408
|
-
else
|
409
|
-
ENV['PYTHONPATH'] = dirs.join(File::PATH_SEPARATOR)
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
453
|
end
|
415
454
|
|
416
455
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bee_python
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michel Casabianca
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-09-
|
18
|
+
date: 2013-09-11 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|