ãMojoð¥ãColaboratoryã¯PythonããMojoãž
Colab ã§ãMojo ã䜿圹èŽããŸããã
çŸåšã
Colab 掻çšäŸ
äžã«ãæ°å€èšç®ã§å¥œãŸããŠãã
ãã¡ãã¯ã
ãŸããéæ¥çãªããã
ãéæ¥çããšèšããŸãã®ã¯ãããã¡ã€ã«ãäœããããã³ãã³ããå®è¡ããããšããæé ãèžãŸãã°ãªããªããšããããšã§ããç¡åç
æ¬é¡
ä»åäœæããipynb
ååŒã®ãã¡ã€ã«ã¯ã以äžã§å
±æããŠãããŸãã
ã€ã³ã¹ããŒã«
æé ã¯æ¬¡ã®äºã€ã§ãã
-
modular
ã®å°å ¥ -
modular
ã«ããmojo
ã®å°å ¥
ãããã
curl -s https://get.modular.com | sh -
次ã«ã
modular install mojo
å ¬åŒæé ãç¡èŠããŠããããšã«ã€ããŠ
äžã«ãæé ã¯äºã€ããšç³ããŸããããå ¬åŒã«ã¯åã€ã®æé ãèžããšãããŸãã
-
modular
ã®å°å ¥(å šãåã) -
python
ã®ä»®æ³ç°å¢ãäœæããäœåãããpython3 -m venv mojo-venv && source mojo-venv/bin/activate
- (ä»®æ³ç°å¢å
ã§)
modular
ã«ããmojo
ã®å°å ¥(åã) - ç°å¢å€æ°ãèšå®ãã
MOJO_PATH=$(modular config mojo.path) \ && BASHRC=$( [ -f "$HOME/.bash_profile" ] && echo "$HOME/.bash_profile" || echo "$HOME/.bashrc" ) \ && echo 'export MODULAR_HOME="'$HOME'/.modular"' >> "$BASHRC" \ && echo 'export PATH="'$MOJO_PATH'/bin:$PATH"' >> "$BASHRC" \ && source "$BASHRC"
ãããç¡èŠããçç±ã¯å¹Ÿã€ããããŸãããæãæ·±å»ãªãã®ã¯ããç°å¢å€æ°ãèšå®ã§ããªããç¹ã§ãããã¡ãã¯ãå
é§è
ã確èªããŠããåé¡ã®ããã§ãããå³ã¡ãmojo
ã³ãã³ããçŽ çŽã«å®è¡ã§ããªãã®ã§ãã察åŠãšããŠã¯ãã³ãã³ãå®è¡æã«æ¯åºŠç°å¢å€æ°ãèšå®ããããmojo
æ¬äœãçŽæ¥å®è¡ãããã®ããããã§ãããã
æ¬èšäºã§ã¯ã³ãã³ãã䜿ãããšãæ§ããªããããæé ãç¡èŠããŠçŽãã«mojo
ãå°å
¥ããŠããŸãã
ã©ã³ã¿ã€ã
éåžž
ã©ã³ã¿ã€ã èšå®ã®éãæ¹
ãã©ã³ã¿ã€ã ã®ã¿ã€ããå€æŽããšããã®ãéžæãããšã次ã®ç»é¢ãåºãŠããŸãã
ã©ã³ã¿ã€ã ã確èªã»å€æŽã§ãã
åè£ã«èŠããŸãéãã
以äžã§æºåãçµããŸãããæåŸã«ãå®éã«è©ŠäœããŠã¿ããã®ãäŸã«ãå®è¡ã®ä»æ¹ã«ã€ããŠè¿°ã¹ãŠãããŸãã
ã»ã«ã§å®è¡
å®è¡äŸ
ã³ããŒã¯ãã¡ã
fn print_mojo(number: UInt8):
for _ in range(number):
print("ð¥", end="")
print_mojo(2)
æå®åæ°åã ãð¥ã衚瀺ããã ãã®ãç¡å³ä¹Ÿç¥ãªããã°ã©ã ã§ããæ¬æ¥ãšã©ãŒã瀺ãæ³¢ç·ãæ®ã£ãŠããŸããã®ã®ãå®è¡ã確èªã§ããŠããŸãã
å®è¡ãã¡ã€ã«ãçæãã
æ°èŠãã¡ã€ã«ãäœæããéã¯ã%%file ãã¡ã€ã«å
ããå§ããŠèšè¿°ããŸãã
ãã¡ã€ã«ãäœã(æ¡åŒµåã¯.mojo
ã.ð¥
)
ã³ããŒã¯ãã¡ã
%%file print_mojo.mojo
from sys import argv
fn print_mojo(number: UInt8):
for _ in range(number):
print("ð¥", end="")
fn main():
var args = argv()
var n: UInt8
try:
n = atol(args[1])
except:
n = 1
print_mojo(n)
å®è¡ãã¡ã€ã«ãçæããå®è¡ããŸãã
å®è¡ãã¡ã€ã«ãçæ(äž)ãå®è¡(äž)
ã³ããŒã¯ãã¡ã
!/root/.modular/pkg/packages.modular.com_mojo/bin/mojo build print_mojo.mojo -o print_mojo.out
!./print_mojo.out 5
/root/.modular/pkg/packages.modular.com_mojo/bin/mojo ãšã¯
â»ãã®èš»éã§ã¯ã
/root/.modular/pkg/packages.modular.com_mojo/bin/mojo
ã¯ãmojo
ã®æ¬äœãååšããå Žæã«å€ãªããŸããã!whoami
ã§ç¢ºèªãããšãåŸäººããã°ã€ã³ããŠããã®ã¯root
ãŠãŒã¶ãŒã§ããããšã確èªã§ããŸãã
root
ãŠãŒã¶ãŒã®/root
ã«.modular
ãçæãããŠããŸããæŽã«ãã®é
äžpkg/packages.modular.com_mojo/bin
ã«mojo
ãã€ã³ã¹ããŒã«ãããŸãããŠãŒã¶ãŒãç°ãªãã°ãåœç¶åãŠãŒã¶ãŒã®/home/ãŠãŒã¶ãŒå
以äžã«ããããååšããŸãã
åœåã$HOME
ãçšããŠæ¬¡ã®ããã«ããŠããŸããã
!$HOME/.modular/pkg/packages.modular.com_mojo/bin/mojo
ã³ãã³ãã©ã€ã³åŒæ°ãäžãããšãã¯æ¬¡ã®ããã«ãªããŸãã
!$HOME/.modular/pkg/packages.modular.com_mojo/bin/mojo xxx.mojo $åŒæ°
ãã®æããªãã$åŒæ°
ãç¡èŠãããŠããŸã£ãããã$HOME
ã䜿çšããªãããã«ããŠããŸãã
ä»åŸãä»æ§å€æŽã«ãã£ãŠãã®ãã¹ãå€åããå Žåã«ã¯ãé©åãªãã®ã«ä¿®æ£ããŠäžããã
è£
以äžã
ãããã
äžäœäºæ
Google API
ãšæ€çŽ¢ãããšããã®ããŒãžã«å°éããã¯ãã§ãã
ååã¯å©çšèŠçŽã«åæããããæ±ããããããã§ãã®ã§ãåæããŠç¶è¡ããŸãã
åæããªããã°å
ã«é²ããªã
ãç¡æãã©ã€ã¢ã«ãã®éå§ã¯ãèªç±ã«ã
ãããžã§ã¯ãäœæ
æ¢ã«äœæããŠããæ¹ã¯æ¬¡ãž
ããããžã§ã¯ãã®éžæããšããé ç®ã確èªããŸãã
ãããžã§ã¯ããäžèŠ§ããŸããããã®æç¹ã§ã¯äœãäœæããŠããªãã®ã§äœã衚瀺ãããŸããããæ°ãããããžã§ã¯ãããéžæããŸãã
äœæãããããžã§ã¯ãåã決å®ããŸããæããç¡ããã°ãã®ãŸãŸã§äœæããŸãã
äœæåŸããããžã§ã¯ããéžæããŸãã
Cloud Shell
å ã»ã©ããå³äžã«ããã¢ã€ã³ã³ã«æ³šç®ã
äžçªå·Šã
å·Šã®ã¢ã€ã³ã³ãéžæãããšãç»é¢äžãå é ãããŸããããã§ã¯ã¡ãã»ãŒãžãã§ã§ããã®ã§ãç¶è¡ããŸãã
æ¥ç¶äžã®ç»é¢ã衚瀺ãããŠããéãå°ãåŸ ã¡ãŸãã
æ¥ç¶ãå®äºãããšã次ã®ãããªç»é¢ã«åãæ¿ãããŸãããã®ç»é¢ã«ã¯å人æ å ±ãå«ãŸããã®ã§ãã¹ã¯ãªãŒã³ã·ã§ãããªã©ã¯ããã¹ãã§ãããŸããã
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to ãããžã§ã¯ãå.
Use âgcloud config set project [PROJECT_ID]â to change to a different project.
ãŠãŒã¶ãŒå@cloudshell:~ (ãããžã§ã¯ãå)$
äœæãããã¡ã€ã«ã¯ä¿æããã倱ãããŸããããã ããèªèº«ã®ããã«èµ·å ããŠãã(.modular/pkg/packages.modular.com_mojo/bin
ã«ããã°å³ã¡æ°žç¶ããåŸãŠç¹å¥ã®å¯ŸåŠãçµãããŠäœ¿çšãåŸã)
ãšããã§ãããšãã£ã¿ãéãããéžæãããšãåäžã®ãã®ã§ã¯ãªããããäžæ¹ã«ããæ¡åŒµæ©èœããä»æ¹ã«ã¯ãªãããšããããŸãã䜿ããåŠãã¯å¥œã¿ã®åé¡ã§ãããã(ãããŸããã衚瀺ãé
ãã ãã ã£ãã®ãããããŸããã)
å人çã«ãšãŠãããããã
Discussion