Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use uv as package manager and fix tests #29

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Polysh Tests

on:
push:
branches:
- '*'

jobs:
polysh-tests:
name: python
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Set up Python
run: uv python install

- name: Install the project
run: uv sync --all-extras --dev

- name: Prepare test environment
run: |
sudo apt-get update
sudo apt-get install -y openssh-server
sudo service ssh start
ssh-keygen -t ed25519 -N "" -f ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
ssh -vvvv localhost 'cat ~/.ssh/config'

- name: Run tests
run: |
uv run python -m unittest discover --verbose --failfast
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

62 changes: 62 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[project]
name = "polysh"
authors = [{ email = "[email protected]" }]
version = "0.14.0"
description = "Control thousands of SSH sessions from a single prompt"
readme = "README.rst"
requires-python = ">=3.5,<=3.12"
dependencies = []
classifiers = [ # Optional
"Intended Audience :: System Administrators",
"Intended Audience :: Developers",
"Topic :: System :: Systems Administration",
"Topic :: System :: Shells",
"Topic :: System :: Clustering",
"Topic :: System :: Distributed Computing",

"Environment :: Console",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",

"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
"Development Status :: 5 - Production/Stable",

# This does not influence pip when choosing what to install. It is used
# for the package list on the pypi website.
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]

[project.urls]
Homepage = "https://github.com/innogames/polysh"
Documentation = "https://github.com/innogames/polysh"
Repository = "https://github.com/innogames/polysh"
Issues = "https://github.com/innogames/polysh/issues"
Changelog = "https://github.com/innogames/polysh/blob/master/CHANGELOG.rst"

[project.license]
file = "LICENSE"

[project.scripts]
polysh = "polysh.main:main"

[project.optional-dependencies]
logging = [
"raven>=6.10.0",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
dev-dependencies = [
"pexpect>=4.9.0",
"coverage>=5.5",
]
22 changes: 0 additions & 22 deletions run.py

This file was deleted.

74 changes: 0 additions & 74 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion polysh/__init__.py → src/polysh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Polysh - Library Entry Point

Copyright (c) 2006 Guillaume Chazarain <[email protected]>
Copyright (c) 2020 InnoGames GmbH
Copyright (c) 2024 InnoGames GmbH
"""
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Polysh - Buffered Dispatcher Class

Copyright (c) 2006 Guillaume Chazarain <[email protected]>
Copyright (c) 2018 InnoGames GmbH
Copyright (c) 2024 InnoGames GmbH
"""
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,15 +32,15 @@ class BufferedDispatcher(asyncore.file_dispatcher):
def __init__(self, fd: int) -> None:
asyncore.file_dispatcher.__init__(self, fd)
self.fd = fd
self.read_buffer = b''
self.write_buffer = b''
self.read_buffer = b""
self.write_buffer = b""

def handle_read(self) -> None:
self._handle_read_chunk()

def _handle_read_chunk(self) -> bytes:
"""Some data can be read"""
new_data = b''
new_data = b""
buffer_length = len(self.read_buffer)
try:
while buffer_length < self.MAX_BUFFER_SIZE:
Expand All @@ -66,7 +66,7 @@ def _handle_read_chunk(self) -> bytes:
buffer_length += len(piece)

finally:
new_data = new_data.replace(b'\r', b'\n')
new_data = new_data.replace(b"\r", b"\n")
self.read_buffer += new_data
return new_data

Expand All @@ -76,13 +76,16 @@ def readable(self) -> bool:

def writable(self) -> bool:
"""Do we have something to write?"""
return self.write_buffer != b''
return self.write_buffer != b""

def dispatch_write(self, buf: bytes) -> bool:
"""Augment the buffer with stuff to write when possible"""
self.write_buffer += buf
if len(self.write_buffer) > self.MAX_BUFFER_SIZE:
console_output('Buffer too big ({:d}) for {}\n'.format(
len(self.write_buffer), str(self)).encode())
console_output(
"Buffer too big ({:d}) for {}\n".format(
len(self.write_buffer), str(self)
).encode()
)
raise asyncore.ExitNow(1)
return True
34 changes: 22 additions & 12 deletions polysh/callbacks.py → src/polysh/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
echo "FOO""BAR" so that the sent string does not contain FOOBAR.

Copyright (c) 2006 Guillaume Chazarain <[email protected]>
Copyright (c) 2018 InnoGames GmbH
Copyright (c) 2024 InnoGames GmbH
"""
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -32,34 +32,44 @@
from typing import Callable
from typing import Tuple

DIGITS_LETTERS = list(map(str, list(range(10)))) + \
list(map(chr, list(range(ord('a'), ord('z') + 1)))) + \
list(map(chr, list(range(ord('A'), ord('Z') + 1))))
DIGITS_LETTERS = (
list(map(str, list(range(10))))
+ list(map(chr, list(range(ord("a"), ord("z") + 1))))
+ list(map(chr, list(range(ord("A"), ord("Z") + 1))))
)


def random_string(length: int) -> str:
def random_char() -> str:
return DIGITS_LETTERS[random.randint(0, len(DIGITS_LETTERS) - 1)]
return ''.join([random_char() for i in range(length)])

return "".join([random_char() for i in range(length)])

COMMON_PREFIX = 'polysh-{}:'.format(random_string(5)).encode()

COMMON_PREFIX = "polysh-{}:".format(random_string(5)).encode()
NR_GENERATED_TRIGGERS = 0

# {'random_string()': (function, repeat)}
CALLBACKS = {}


def add(name: bytes, function: Callable, repeat: bool) -> Tuple[bytes, bytes]:
name = name.replace(b'/', b'_')
name = name.replace(b"/", b"_")
global NR_GENERATED_TRIGGERS
nr = NR_GENERATED_TRIGGERS
NR_GENERATED_TRIGGERS += 1
trigger = (COMMON_PREFIX + name + b':' + random_string(5).encode() + b':' +
str(nr).encode() + b'/')
trigger = (
COMMON_PREFIX
+ name
+ b":"
+ random_string(5).encode()
+ b":"
+ str(nr).encode()
+ b"/"
)
CALLBACKS[trigger] = (function, repeat)
trigger1 = trigger[:int(len(COMMON_PREFIX) / 2)]
trigger2 = trigger[len(trigger1):]
trigger1 = trigger[: int(len(COMMON_PREFIX) / 2)]
trigger2 = trigger[len(trigger1) :]
return trigger1, trigger2


Expand All @@ -72,7 +82,7 @@ def process(line: bytes) -> bool:
if start < 0:
return False

end = line.find(b'/', start) + 1
end = line.find(b"/", start) + 1
if end <= 0:
return False

Expand Down
Loading
Loading