Skip to content

Commit

Permalink
Introduce initial project code standards
Browse files Browse the repository at this point in the history
Added and applied code standards for both Rust and Python.
pre-commit hooks are now available and will be enforced in pull
requests.
  • Loading branch information
JacobCallahan committed Mar 30, 2024
1 parent a4105a8 commit 6cb1534
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 116 deletions.
118 changes: 59 additions & 59 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# This file was initially autogenerated by maturin v1.5.0
name: Build and Test

on:
Expand All @@ -16,7 +15,36 @@ permissions:
contents: read

jobs:
code_checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Run pre-commit checks
run: |
pip install pre-commit
pre-commit run --all-files
sdist:
needs: [code_checks]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

linux:
needs: [code_checks]
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -49,37 +77,16 @@ jobs:
with:
name: wheels-linux-${{ matrix.target }}
path: dist
# - name: Setup Docker
# run: |
# sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# sudo apt-get install docker-ce
- name: Install and Test
if: ${{ startsWith(matrix.target, 'x86_64') }}
# if: ${{ startsWith(matrix.target, 'x86_64') }}
shell: bash
run: |
set -e
pip install .[dev] --find-links dist --force-reinstall
pytest -v tests/
# - name: Install and Test
# if: ${{ !startsWith(matrix.target, 'x86') && matrix.target != 'ppc64' }}
# uses: uraimo/[email protected]
# with:
# arch: ${{ matrix.target }}
# distro: ubuntu22.04
# githubToken: ${{ github.token }}
# install: |
# apt-get update
# apt-get install -y --no-install-recommends python3 python3-pip
# pip3 install -U pip pytest
# run: |
# set -e
# pip3 install .[dev] --find-links dist --force-reinstall
# pip3 install pytest docker
# pytest -v tests/
windows:
needs: [code_checks]
runs-on: windows-latest
strategy:
matrix:
Expand All @@ -90,6 +97,12 @@ jobs:
with:
python-version: '3.10'
architecture: ${{ matrix.target }}
- name: Set Perl environment variables
run: |
echo "PERL=$((where.exe perl)[0])" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
echo "OPENSSL_SRC_PERL=$((where.exe perl)[0])" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
- name: Remove wincred from docker config
run: sed -i '/wincred/d' ~/.docker/config.json
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -101,24 +114,23 @@ jobs:
with:
name: wheels-windows-${{ matrix.target }}
path: dist
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Install and Test
# if: ${{ !startsWith(matrix.target, 'aarch64') }}
# shell: bash
# run: |
# set -e
# pip install .[dev] --find-links dist --force-reinstall
# pip install pytest docker
# pytest -v tests/
- name: Install and Test
if: ${{ !startsWith(matrix.target, 'aarch64') }}
shell: bash
run: |
set -e
pip install .[dev] --find-links dist --force-reinstall
pytest -v tests/
macos:
runs-on: macos-latest
needs: [code_checks]
runs-on: [macos-13, macos-14]
strategy:
matrix:
target: [x86_64, aarch64]
env:
OPENSSL_NO_VENDOR: 1
DOCKER_HOST: unix:///var/run/docker.sock
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -137,27 +149,15 @@ jobs:
with:
name: wheels-macos-${{ matrix.target }}
path: dist
# - name: Install and Test
# if: ${{ !startsWith(matrix.target, 'aarch64') }}
# shell: bash
# run: |
# set -e
# pip install .[dev] --find-links dist --force-reinstall
# pip install pytest docker pexpect
# pytest -v tests/

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

- name: setup-docker
# if: ${{ !startsWith(matrix.target, 'aarch64') }}
run: |
brew install docker
colima start
- name: Install and Test
# if: ${{ !startsWith(matrix.target, 'aarch64') }}
shell: bash
run: |
set -e
pip install .[dev] --find-links dist --force-reinstall
pytest -v tests/
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# checks and formatting for rust code
repos:
- repo: local
hooks:
- id: cargo-fmt
name: cargo fmt
entry: cargo fmt --
language: system
types: [rust]
pass_filenames: false
- repo: https://github.com/doublify/pre-commit-rust
rev: v1.0
hooks:
- id: clippy

# checks and formatting for python code
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.4
hooks:
- id: ruff-format # Formatter
- id: ruff # Linter
args: [--fix, --exit-non-zero-on-fix]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Hussh: SSH for humans.
[![image](https://img.shields.io/pypi/v/hussh.svg)](https://pypi.python.org/pypi/hussh)
[![image](https://img.shields.io/pypi/pyversions/hussh.svg)](https://pypi.python.org/pypi/hussh)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/hussh)
[![Actions status](https://github.com/jacobcallahan/hussh/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/jacobcallahan/hussh/actions)

Hussh (pronounced "hush") is a client-side ssh library that offers low level performance through a high level interface.
Expand Down
9 changes: 5 additions & 4 deletions benchmarks/bench_fabric.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import memray
import timeit
from pprint import pprint
from pathlib import Path
from pprint import pprint
import timeit

import memray

results_dict = {}

Expand Down Expand Up @@ -71,7 +72,7 @@
pprint(results_dict, sort_dicts=False)

if Path("bench_results.json").exists():
results = json.loads(Path("bench_results.json").read_text())
results = json.loads(Path("bench_results.json").read_text())
else:
results = {}
results.update({"fabric": results_dict})
Expand Down
10 changes: 6 additions & 4 deletions benchmarks/bench_hussh.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import memray
import timeit
from pprint import pprint
from pathlib import Path
from pprint import pprint
import timeit

import memray

results_dict = {}

Expand All @@ -11,6 +12,7 @@
with memray.Tracker("memray-bench_hussh.bin"):
start_time = timeit.default_timer()
from hussh import Connection

results_dict["import_time"] = f"{(timeit.default_timer() - start_time) * 1000:.2f} ms"

host_info = json.loads(Path("target.json").read_text())
Expand Down Expand Up @@ -62,7 +64,7 @@
pprint(results_dict, sort_dicts=False)

if Path("bench_results.json").exists():
results = json.loads(Path("bench_results.json").read_text())
results = json.loads(Path("bench_results.json").read_text())
else:
results = {}
results.update({"hussh": results_dict})
Expand Down
11 changes: 6 additions & 5 deletions benchmarks/bench_paramiko.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import memray
import timeit
from pprint import pprint
from pathlib import Path
from pprint import pprint
import timeit

import memray

results_dict = {}

Expand All @@ -11,6 +12,7 @@
with memray.Tracker("memray-bench_paramiko.bin"):
start_time = timeit.default_timer()
import paramiko

results_dict["import_time"] = f"{(timeit.default_timer() - start_time) * 1000:.2f} ms"

host_info = json.loads(Path("target.json").read_text())
Expand All @@ -33,7 +35,6 @@
result = stdout.read()
results_dict["cmd_time"] = f"{(timeit.default_timer() - temp_time) * 1000:.2f} ms"


# small file (1kb)
temp_time = timeit.default_timer()
sftp = ssh.open_sftp()
Expand Down Expand Up @@ -73,7 +74,7 @@
pprint(results_dict, sort_dicts=False)

if Path("bench_results.json").exists():
results = json.loads(Path("bench_results.json").read_text())
results = json.loads(Path("bench_results.json").read_text())
else:
results = {}
results.update({"paramiko": results_dict})
Expand Down
23 changes: 12 additions & 11 deletions benchmarks/bench_ssh2-python.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import memray
import timeit
from pprint import pprint
from pathlib import Path
from pprint import pprint
import timeit

import memray

results_dict = {}

Expand All @@ -11,8 +12,10 @@
with memray.Tracker("memray-bench_ssh2-python.bin"):
start_time = timeit.default_timer()
import socket
from ssh2.session import Session

from ssh2 import sftp
from ssh2.session import Session

results_dict["import_time"] = f"{(timeit.default_timer() - start_time) * 1000:.2f} ms"

host_info = json.loads(Path("target.json").read_text())
Expand Down Expand Up @@ -50,9 +53,7 @@
| sftp.LIBSSH2_SFTP_S_IRGRP
| sftp.LIBSSH2_SFTP_S_IROTH
)
FILE_FLAGS = (
sftp.LIBSSH2_FXF_CREAT | sftp.LIBSSH2_FXF_WRITE | sftp.LIBSSH2_FXF_TRUNC
)
FILE_FLAGS = sftp.LIBSSH2_FXF_CREAT | sftp.LIBSSH2_FXF_WRITE | sftp.LIBSSH2_FXF_TRUNC
data = Path("1kb.txt").read_bytes()
sftp_conn = session.sftp_init()
with sftp_conn.open("/root/1kb.txt", FILE_FLAGS, SFTP_MODE) as f:
Expand All @@ -61,7 +62,7 @@

temp_time = timeit.default_timer()
with sftp_conn.open("/root/1kb.txt", sftp.LIBSSH2_FXF_READ, sftp.LIBSSH2_SFTP_S_IRUSR) as f:
read_data= b""
read_data = b""
for _rc, data in f:
read_data += data
Path("small.txt").write_bytes(read_data)
Expand All @@ -77,7 +78,7 @@

temp_time = timeit.default_timer()
with sftp_conn.open("/root/14kb.txt", sftp.LIBSSH2_FXF_READ, sftp.LIBSSH2_SFTP_S_IRUSR) as f:
read_data= b""
read_data = b""
for _rc, data in f:
read_data += data
Path("medium.txt").write_bytes(read_data)
Expand All @@ -93,7 +94,7 @@

temp_time = timeit.default_timer()
with sftp_conn.open("/root/64kb.txt", sftp.LIBSSH2_FXF_READ, sftp.LIBSSH2_SFTP_S_IRUSR) as f:
read_data= b""
read_data = b""
for _rc, data in f:
read_data += data
Path("large.txt").write_bytes(read_data)
Expand All @@ -105,7 +106,7 @@
pprint(results_dict, sort_dicts=False)

if Path("bench_results.json").exists():
results = json.loads(Path("bench_results.json").read_text())
results = json.loads(Path("bench_results.json").read_text())
else:
results = {}
results.update({"ssh2-python": results_dict})
Expand Down
Loading

0 comments on commit 6cb1534

Please sign in to comment.