Skip to main content

colab miscellaneous utils

Project description

colab miscellaneous utils Codacy BadgeCode style: blackLicense: MITPyPI version

Miscellaneous utils mainly intended for use in colab

Demo: notebooks in Colab

git push from Colab

Open In Colab (in Chinese, shouldn't be too difficult to follow without knowing any Chinese though, just click through :smiley:)

Reverse ssh tunnel for ssh to Colab VM

Open In Colab in English (I may provide a Chinese version later)

Installation

pip install clmutils  # clm: colab-misc

Usage

Set up git using clmutils.setup_git

Assume you configure git as follows:

git config --global user.email your-email-address
git config --global user.name your-github-username

With clmutils, you'd do:

from clmutils import setup_git`

user_email = "your-email-address"
user_name = "your-github-username"
gh_key = \
"""
-----BEGIN EC PRIVATE KEY-----
MH.............................................................9
AwEHoUQDQgAEoLlGQRzIVHYw3gvC/QFw3Ru45zGawaBaCq6jTqdyH2Kp8zIB3TdJ
K9ztlJBRRAOHh5sPhQ4QpdZH1v1rWeDWIQ==
-----END EC PRIVATE KEY-----
""".strip() + "\n"

setup_git(user_email=user_email, user_name=user_name, priv_key=gh_key)

You then upload the public key for gh_key to https://github.com/settings/keys.

Refer to Step 2 https://support.cloudways.com/using-git-command-line-ssh/ for how to generate a private/public key pair. You can also use clmutils.gen_keypair to do that in Python.

Set up git in 4 steps

  1. Write a private key to ~/.ssh/gh-key
from clmutils import create_file
gh_key = \
"""
-----BEGIN EC PRIVATE KEY-----
MH.............................................................9
AwEHoUQDQgAEoLlGQRzIVHYw3gvC/QFw3Ru45zGawaBaCq6jTqdyH2Kp8zIB3TdJ
K9ztlJBRRAOHh5sPhQ4QpdZH1v1rWeDWIQ==
-----END EC PRIVATE KEY-----
""".strip() + "\n"
# Do not remove .strip() + "\n"
# the private key is very picky about format

create_file(gh_key, dest="~/.ssh/gh-key")
  1. Set up github.com config for git push
from clmutils import append_content
config_github_entry = \
"""
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/gh-key
"""
append_content(config_github_entry, dest="~/.ssh/config")
  1. Verify that everything is OK, from a cell
!ssh -o StrictHostKeyChecking=no -T git@github.com

If you see something similar to

Hi your-name! You've successfully authenticated, but GitHub does not provide shell access.

you are good to go.

  1. git config --global You can now set up git config global from a cell, e.g.
!git config --global user.email your-email-address
!git config --global user.name your-github-username
# !ssh-keyscan github.com >> ~/.ssh/known_hosts

You are ready to clone your own repo, run your app and generate new data, update the repo and push to github.

Utils planned

  • :white_check_mark: setup_git sets up git for github.com

  • :white_check_mark: create_file creates a file with given mode, e.g. for .ssh/id_rsa or IdentityFile in .ssh/config

  • :white_check_mark: apppend_content appends some content to a file, e.g., for appended a public key to .ssh/authorized_keys

  • :white_check_mark: chmod600 chmod of a file

  • :white_check_mark: gen_keypair generates private/public key pair.

  • reverse_ssh_tunnel sets up a reverse ssh tunnel to a remote host with via autossh

  • More

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clmutils-0.1.3.tar.gz (7.4 kB view hashes)

Uploaded Source

Built Distribution

clmutils-0.1.3-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page