Class: CreateProj::Creator::PythonCreator
- Inherits:
-
CreateProj::Creator
- Object
- CreateProj::Creator
- CreateProj::Creator::PythonCreator
- Defined in:
- lib/createproj/creator/python.rb
Overview
Class for creating Ruby project
Instance Method Summary collapse
-
#check_bash_script ⇒ Object
Check that a bash script.
-
#initialize(*args) ⇒ PythonCreator
constructor
A new instance of PythonCreator.
-
#install_dependencies ⇒ Object
Installs dependencies in the new sandbox.
-
#install_sandbox ⇒ Object
Create an virtualenv with the project name and creates file dictating virtualenv.
-
#virtualenv_name ⇒ String
Creates a namespaced virtualenv name.
-
#write_venv_file ⇒ Object
Write a .venv file with the name of the virtualenv.
Constructor Details
#initialize(*args) ⇒ PythonCreator
Returns a new instance of PythonCreator.
5 6 7 8 9 10 11 12 13 |
# File 'lib/createproj/creator/python.rb', line 5 def initialize(*args) super(*args) @precommit_template = 'lint-pre-commit' @precommit_options = { linter: 'pylint', file_ext: '.py' } @gitignore_files = %w(*.pyc) @packages_to_install = { 'pylint' => '1.4.0' } end |
Instance Method Details
#check_bash_script ⇒ Object
Check that a bash script
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/createproj/creator/python.rb', line 39 def check_bash_script command = <<-eos If you want the virtual env to be automatically activated upon entering the directory, follow the instructions in this gist (https://gist.github.com/mattjmcnaughton/4d599b62b60b59f9229f). eos puts command unless File.exist?(File.join("#{Dir.home}", '.virtualenv_sourcer')) end |
#install_dependencies ⇒ Object
Installs dependencies in the new sandbox
install_dependencies #=> pylint written in Gemfile
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/createproj/creator/python.rb', line 80 def install_dependencies File.open('requirements.txt', 'w+') do |f| @packages_to_install.each do |k, v| f.write("#{k}==#{v}\n") end end command = 'Enter the directory and run pip install requirements.txt' puts command end |
#install_sandbox ⇒ Object
TODO:
Automate creating the virtualenv
Create an virtualenv with the project name and creates file dictating virtualenv
Check that the user has installed a bash script that will automatically ‘workon ENV` when entering directory with a .venv file
64 65 66 67 68 69 70 71 |
# File 'lib/createproj/creator/python.rb', line 64 def install_sandbox # make system call to virtualenvwrapper to create the virtualenv command = "Run mkvirtualenv #{virtualenv_name}" puts command write_venv_file check_bash_script end |
#virtualenv_name ⇒ String
Creates a namespaced virtualenv name
21 22 23 |
# File 'lib/createproj/creator/python.rb', line 21 def virtualenv_name "#{@name}-createproj" end |
#write_venv_file ⇒ Object
Write a .venv file with the name of the virtualenv
31 32 33 34 35 36 |
# File 'lib/createproj/creator/python.rb', line 31 def write_venv_file # must have both .ruby-gemset and .ruby-version file File.open('.venv', 'w+') do |f| f.write(virtualenv_name) end end |