class CreateProj::Creator::PythonCreator

Class for creating Ruby project

Public Class Methods

new(*args) click to toggle source
Calls superclass method CreateProj::Creator::Creator::new
# 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

Public Instance Methods

check_bash_script() click to toggle source

Check that a bash script

# 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() click to toggle source

Installs dependencies in the new sandbox

@example Write pylint to a requirements.txt and

       prompt `pip install -r requirements.txt`
install_dependencies #=> pylint written in Gemfile

@return Nothing

# 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() click to toggle source

Create an virtualenv with the project name and creates file dictating virtualenv

@todo Automate creating the virtualenv

Check that the user has installed a bash script that will automatically ‘workon ENV` when entering directory with a .venv file

@example Create rvm sandbox for project named test

install_sandbox #=> Executes `mkvirtualenv NAME`, write .env file,
                    and check for bash script

@return Nothing

# 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() click to toggle source

Creates a namespaced virtualenv name

@example Get virtualenv name if project name is test

virtualenv_name #=> 'test-createproj'

@return [String] that has unique integer name

# File lib/createproj/creator/python.rb, line 21
def virtualenv_name
  "#{@name}-createproj"
end
write_venv_file() click to toggle source

Write a .venv file with the name of the virtualenv

@example

write_venv_file #=> `cat .venv` #=> NAME

@return Nothing

# 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