Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Apr 20, 2024
2 parents 526948e + e3e2c19 commit 725f421
Show file tree
Hide file tree
Showing 29 changed files with 585 additions and 344 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*$py.class
*.pyc
env/
# weigths and biases
wandb/


# benchmark results
benchmarks/results/
Expand All @@ -21,8 +18,6 @@ benchmarks/results/*

# runs/data/models/logs/~
data/**
!data/key.json


# C extensions
*.so
Expand Down
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ FROM python:3.12-slim-bookworm
ENV PYTHONUNBUFFERED True
ARG DEBIAN_FRONTEND=noninteractive

COPY . /commune

WORKDIR /commune

RUN usermod -s /bin/bash root
Expand All @@ -24,11 +22,12 @@ RUN pip install setuptools wheel

#RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

COPY ./requirements.txt /commune/requirements.txt
RUN pip install -r requirements.txt

RUN pip install -e .

RUN apt-get install -y nodejs npm
RUN npm install -g pm2
COPY . /commune
RUN pip install -e .

CMD [ "tail -f /dev/null" ]
ENTRYPOINT ["tail", "-f", "/dev/null"]
5 changes: 5 additions & 0 deletions commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4554,6 +4554,11 @@ def create_key(cls , key = None):
def add_key(cls, key, *args, **kwargs):
return c.module('key').add_key(key, *args, **kwargs)

@classmethod
def new_key(cls, *args, **kwargs):
return c.module('key').new_key( *args, **kwargs)


@classmethod
def save_keys(cls, *args, **kwargs):
return c.module('key').save_keys(*args, **kwargs)
Expand Down
87 changes: 87 additions & 0 deletions commune/ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import commune as c
import streamlit as st
from typing import *
import json
import paramiko

class SSH(c.Module):
@classmethod
def cmd(cls, *cmd_args,
host:str= None,
cwd:str=None,
verbose=False,
sudo=False,
key=None,
timeout=10,
generator=True,
**kwargs ):
"""s
Run a command on a remote server using Remote.
:param host: Hostname or IP address of the remote machine.
:param port: Remote port (typically 22).
:param username: Remote username.
:param password: Remote password.
:param command: Command to be executed on the remote machine.
:return: Command output.
"""
command = ' '.join(cmd_args).strip()

if command.startswith('c '):
command = command.replace('c ', cls.executable_path + ' ')

if cwd != None:
command = f'cd {cwd} && {command}'

# Create an Remote client instance.
client = paramiko.SSHClient()

# Automatically add the server's host key (this is insecure and used for demonstration;
# in production, you should have the remote server's public key in known_hosts)
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# Connect to the remote server
client.connect(host['host'],
port=host['port'],
username=host['user'],
password=host['pwd'])

if sudo and host['user'] != "root":
command = "sudo -S -p '' %s" % command

stdin, stdout, stderr = client.exec_command(command)

try:
if sudo:
stdin.write(host['pwd'] + "\n")
stdin.flush()
color = c.random_color()
# Print the output of ls command
outputs = {'error': '', 'output': ''}

if generator:
for line in stdout.readlines():
if verbose:
c.print(f'[bold]{host["host"]}[/bold]', line.strip('\n'), color=color)
yield line

for line in stdout.readlines():
if verbose:
c.print(f'[bold]{host_name}[/bold]', line.strip('\n'), color=color)
outputs['output'] += line

for line in stderr.readlines():
if verbose:
c.print(f'[bold]{host_name}[/bold]', line.strip('\n'))
outputs['error'] += line

if len(outputs['error']) == 0:
outputs = outputs['output']

# stdin.close()
# stdout.close()
# stderr.close()
# client.close()
except Exception as e:
c.print(e)
return outputs
1 change: 1 addition & 0 deletions data/keymems.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ services:
- ~/.commune:/config/.commune
- ~/.commune:/root/.commune
- ./:/commune
#- /var/run/docker.sock:/var/run/docker.sock #Nuclear option
- /var/run/docker.sock:/var/run/docker.sock #Nuclear option
ports:
- 50050-50250:50050-50250
# - 8501-8511:8501-8511

restart: unless-stopped
134 changes: 0 additions & 134 deletions docs/blackpaper.md

This file was deleted.

14 changes: 13 additions & 1 deletion docs/blackpaper/1_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Module Key

Each module is represented as a key which is an sr25519 key. The public key is used to register the module onto the blockchain. The key is used to sign, encrypt,decrypt and verify messages. These keys can also represent other keys on any other chain through transfering its seed entropy to another chain key format. This allows for modules to exist on any chain

![Alt text](image_module_key.png)

For Warning for Anti-Python Peeps

The module is designed from a python class, but this can be implemented in rust, javascript, or any other language, even if they are functional programming languages (via structs). You can think of the module as a class in any language, where it is a collection of functions that change a state. This is the core foundation of the module.
Expand All @@ -30,6 +32,9 @@ class Model(c.Module):

```

![Alt text](image_module.png)


I can serve this as an api which runs in the background

```python
Expand Down Expand Up @@ -100,9 +105,16 @@ c add_shortcut wombo w
{'success': True, 'msg': 'added shortcut (wombo -> w)'}
Namespaces
Namespaces are a way to organize modules. Each namespace is a collection of modules that associates. To see the namespace of a network
```python
c.namespace(network='local')
```
```bash
{'subnet.add.subnet.vali': '0.0.0.0:50214', 'subnet.vali::0': '0.0.0.0:50086', 'vali': '0.0.0.0:50204'}
```


Fo

12 changes: 0 additions & 12 deletions docs/blackpaper/2_namespace.md

This file was deleted.

Loading

0 comments on commit 725f421

Please sign in to comment.