Skip to content

Commit

Permalink
refactor project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pohmelie committed Jan 3, 2024
1 parent 58c90ca commit 7900e8b
Show file tree
Hide file tree
Showing 28 changed files with 325 additions and 225 deletions.
4 changes: 0 additions & 4 deletions .coveragerc

This file was deleted.

2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

48 changes: 24 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.x"
- run: pip install flake8
- run: flake8
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.11"
- run: pip install -e ./[dev]
- run: pre-commit run -a

tests:
needs: lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e ./[dev]
- run: pytest
- uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
verbose: true
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e ./[dev]
- run: pytest
- uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
verbose: true

deploy:
needs: tests
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: casperdcl/deploy-pypi@v2
with:
password: ${{ secrets.PYPI_TOKEN }}
build: true
skip_existing: true
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: casperdcl/deploy-pypi@v2
with:
password: ${{ secrets.PYPI_TOKEN }}
build: true
skip_existing: true
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

.python-linters: &python-linters
pass_filenames: false
fail_fast: true
language: system
types: [python]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
fail_fast: true
- id: trailing-whitespace
- id: check-toml
fail_fast: true
- id: end-of-file-fixer
fail_fast: true

- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
hooks:
- id: add-trailing-comma
fail_fast: true

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.1.0
hooks:
- id: pretty-format-yaml
fail_fast: true
args:
- --autofix
- --preserve-quotes
- --indent=2

- repo: local
hooks:
- <<: *python-linters
id: black
name: Format with Black
entry: black
args: ["."]

- <<: *python-linters
id: ruff
name: Check with ruff
entry: ruff
args: ["check", "--fix", "."]
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

20 changes: 9 additions & 11 deletions examples/shadowsocks-like.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import functools
import socket

from siosocks.io.asyncio import ServerIO, ClientIO
from siosocks.interface import async_engine
from siosocks.protocol import SocksServer, SocksClient
from siosocks.io.asyncio import ClientIO, ServerIO
from siosocks.protocol import SocksClient, SocksServer


# This is very strong encryption method, believe me!
Expand All @@ -19,7 +19,6 @@ def decode(data: bytes):


class CommonProxy:

def __init__(self, proxied):
self._proxied = proxied

Expand All @@ -28,19 +27,16 @@ def __getattr__(self, name):


class IncomingDecoder(CommonProxy):

async def read(self, count):
return decode(await self._proxied.read(count))


class OutgoingEncoder(CommonProxy):

def write(self, data):
return self._proxied.write(encode(data))


class RemoteIO(ServerIO):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.incoming_reader = IncomingDecoder(self.incoming_reader)
Expand All @@ -58,17 +54,19 @@ async def open_connection(host=None, port=None, *, socks_host=None, socks_port=N


class LocalIO(ServerIO):

def __init__(self, *args, remote_host, remote_port, **kwargs):
super().__init__(*args, **kwargs)
self.__remote_host = remote_host
self.__remote_port = remote_port

async def connect(self, host, port):
self.outgoing_reader, self.outgoing_writer = await open_connection(host, port,
socks_host=self.__remote_host,
socks_port=self.__remote_port,
socks_version=5)
self.outgoing_reader, self.outgoing_writer = await open_connection(
host,
port,
socks_host=self.__remote_host,
socks_port=self.__remote_port,
socks_version=5,
)


async def socks_server_handler(reader, writer, *, io_factory, **kwargs):
Expand Down
66 changes: 66 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[project]
name = "siosocks"
version = "0.3.0"
description = "sans-io socks proxy client/server with couple io backends"
readme = "readme.md"
requires-python = ">= 3.11"
license = {file = "license.txt"}
authors = [
{name = "pohmelie", email = "[email protected]"},
]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]

[project.urls]
Github = "https://github.com/pohmelie/siosocks"

[project.optional-dependencies]
dev = [
# tests
"pytest-asyncio",
"pytest-cov",
"pytest-trio",
"pytest",
"trio",

# linters
"pre-commit",
"black",
"ruff",
]
trio = [
"trio",
]

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages.find.where = ["src"]

# tools
[tool.black]
line-length = 120
target-version = ["py311"]

[tool.ruff]
line-length = 120
target-version = "py311"
select = ["E", "W", "F", "Q", "UP", "I", "ASYNC"]
src = ["src"]

[tool.coverage]
run.source = ["./src/siosocks"]
run.omit = ["./src/siosocks/__main__.py"]
report.show_missing = true

[tool.pytest.ini_options]
addopts = "-x --durations 10 -p no:anyio --cov"
testpaths = "tests"
log_format = "%(asctime)s.%(msecs)03d %(name)-20s %(levelname)-8s %(filename)-15s %(lineno)-4d %(message)s"
log_date_format = "%H:%M:%S"
log_level = "DEBUG"
asyncio_mode = "strict"
7 changes: 0 additions & 7 deletions pytest.ini

This file was deleted.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- Fun

# Features
- Only tcp connect (no bind, no udp)
- Only tcp connect (no bind or udp associate)
- Both client and server
- Socks versions: 4, 4a, 5
- Socks5 auth: no auth, username/password
Expand Down
28 changes: 0 additions & 28 deletions setup.cfg

This file was deleted.

4 changes: 0 additions & 4 deletions setup.py

This file was deleted.

2 changes: 0 additions & 2 deletions siosocks/__init__.py

This file was deleted.

4 changes: 4 additions & 0 deletions src/siosocks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import importlib.metadata

__version__ = importlib.metadata.version(__package__)
version = tuple(map(int, __version__.split(".")))
Loading

0 comments on commit 7900e8b

Please sign in to comment.