code: def lock(
      ctx,
      state,
      **kwargs
  ):
      
      from ..core import ensure_project, do_init, do_lock
  
      # Ensure that virtualenv is available.
      ensure_project(three=state.three, python=state.python, pypi_mirror=state.pypi_mirror)
      if state.installstate.requirementstxt:
          do_init(
              dev=state.installstate.dev,
              requirements=state.installstate.requirementstxt,
              pypi_mirror=state.pypi_mirror,
              pre=state.installstate.pre,
          )
      do_lock(
          ctx=ctx,
          clear=state.clear,
          pre=state.installstate.pre,
          keep_outdated=state.installstate.keep_outdated,
          pypi_mirror=state.pypi_mirror,
      )
docs: Generates Pipfile.lock.