Added poetry

This commit is contained in:
Felix Bargfeldt 2022-03-15 23:41:35 +01:00
parent f5d8777f65
commit 7fc6faa620
No known key found for this signature in database
GPG key ID: 87CB84A4087C3603
9 changed files with 1190 additions and 131 deletions

View file

@ -25,13 +25,13 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install black
- name: Setup poetry
run: |
pip install --upgrade pip
pip install black
pip install poetry poethepoet
poetry install -n --no-root
- name: Check code formatting with black
run: black -l 120 . --diff --check
run: poe black --diff --check
mypy:
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository }}
@ -48,14 +48,13 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install mypy
- name: Setup poetry
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install mypy types-python-dateutil types-requests
pip install poetry poethepoet
poetry install -n --no-root
- name: Check typing with mypy
run: mypy PyCrypCli
run: poe mypy
linter:
runs-on: ubuntu-latest
@ -71,13 +70,13 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install wemake-python-styleguide
- name: Setup poetry
run: |
pip install --upgrade pip
pip install wemake-python-styleguide bandit==1.7.2
pip install poetry poethepoet
poetry install -n --no-root
- name: Check code style with wemake-python-styleguide
run: flake8 PyCrypCli --count --statistics --show-source
run: poe flake8
# - name: Lint with wemake-python-styleguide
# uses: wemake-services/wemake-python-styleguide@0.16.0
@ -98,36 +97,29 @@ jobs:
submodules: recursive
fetch-depth: 0
- name: Check Version
run: |
if [[ $GITHUB_REF = refs/tags/v* ]]; then
tag=${GITHUB_REF#refs/tags/v}
version=$(grep '^version =' pyproject.toml | cut -d'"' -f2)
if [[ "$tag" != "$version" ]]; then
echo "::error::Tag $tag does not match version $version"
exit 1
fi
fi
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install build dependencies
- name: Setup poetry
run: |
pip install --upgrade pip
pip install wheel
- name: Create Version
id: version
run: |
set -x
tag=${GITHUB_REF#refs/tags/v}
if [[ $GITHUB_REF = refs/tags/v* ]]; then
version="v$tag"
elif [[ $GITHUB_REF = refs/heads/* ]]; then
version=$(git describe --tags | sed 's/-/+/')
fi
version="$(echo $version | tr / -)"
echo ::set-output name=version::${version}
pip install poetry
poetry install -n --no-root
- name: Build python package
env:
VERSION: ${{ steps.version.outputs.version }}
run: python setup.py sdist bdist_wheel
run: poetry build
- name: Upload dist
uses: actions/upload-artifact@v2
@ -255,9 +247,7 @@ jobs:
path: dist
- name: Install Twine
run: |
pip install --upgrade pip
pip install twine
run: pip install twine
- name: Upload package to PyPi
run: python -m twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} dist/*

View file

@ -1,13 +1,27 @@
FROM python:3.10-alpine AS builder
RUN apk add --no-cache build-base gcc musl-dev libffi-dev
WORKDIR /build
RUN pip install poetry
COPY pyproject.toml /build/
COPY poetry.lock /build/
RUN poetry install -n --no-root
COPY README.md /build/
COPY PyCrypCli /build/PyCrypCli
RUN poetry build
FROM python:3.10-alpine
LABEL org.opencontainers.image.source=https://github.com/Defelo/PyCrypCli
WORKDIR /app
COPY --from=builder /build/dist/*.whl /tmp/
RUN pip install /tmp/*.whl && rm /tmp/*.whl
COPY requirements.txt /app/
RUN pip install -r requirements.txt
COPY PyCrypCli /app/PyCrypCli
CMD ["python", "-m", "PyCrypCli"]
CMD ["pycrypcli"]

View file

@ -125,7 +125,7 @@ class Client:
exception: Type[MicroserviceException]
for exception in MicroserviceException.__subclasses__():
if exception.error and (match := re.fullmatch(exception.error, error)):
raise exception(error, list(match.groups()))
raise exception(list(match.groups()))
raise InvalidServerResponseError(response)
if not response_data and retry:
@ -212,7 +212,7 @@ class Client:
if "error" in response:
error: str = response["error"]
if error == "permissions denied":
raise PermissionDeniedError()
raise PermissionDeniedError
raise InvalidServerResponseError(response)
return TokenResponse.parse(self, response)

View file

@ -1,5 +1,5 @@
import json
from typing import Any
from typing import Any, ClassVar
class ClientNotReadyError(Exception):
@ -66,213 +66,212 @@ class UnknownMicroserviceError(Exception):
class MicroserviceException(Exception):
error: str | None = None
error: ClassVar[str | None]
def __init__(self, error: str | None = None, args: list[Any] | None = None):
super().__init__(error or "")
self.error = error
def __init__(self, args: list[Any] | None = None):
super().__init__(self.error)
self.params = args
class InternalError(MicroserviceException):
error: str = "internal error"
error = "internal error"
class NoResponseTimeoutError(MicroserviceException):
error: str = "no response - timeout"
error = "no response - timeout"
class InvalidRequestError(MicroserviceException):
error: str = "invalid_request"
error = "invalid_request"
class AlreadyOwnADeviceError(MicroserviceException):
error: str = "already_own_a_device"
error = "already_own_a_device"
class PermissionDeniedError(MicroserviceException):
error: str = "permission_denied"
error = "permission_denied"
class DeviceNotFoundError(MicroserviceException):
error: str = "device_not_found"
error = "device_not_found"
class DevicePoweredOffError(MicroserviceException):
error: str = "device_powered_off"
error = "device_powered_off"
class DeviceNotOnlineError(MicroserviceException):
error: str = "device_not_online"
error = "device_not_online"
class DeviceIsStarterDeviceError(MicroserviceException):
error: str = "device_is_starter_device"
error = "device_is_starter_device"
class MaximumDevicesReachedError(MicroserviceException):
error: str = "maximum_devices_reached"
error = "maximum_devices_reached"
class ElementPartNotFoundError(MicroserviceException):
error: str = "element_(.+)_not_found"
error = "element_(.+)_not_found"
class PartNotInInventoryError(MicroserviceException):
error: str = "(.+)_not_in_inventory"
error = "(.+)_not_in_inventory"
class MissingPartError(MicroserviceException):
error: str = "missing_(.+)"
error = "missing_(.+)"
class IncompatibleCPUSocketError(MicroserviceException):
error: str = "incompatible_cpu_socket"
error = "incompatible_cpu_socket"
class NotEnoughRAMSlotsError(MicroserviceException):
error: str = "not_enough_ram_slots"
error = "not_enough_ram_slots"
class IncompatibleRAMTypesError(MicroserviceException):
error: str = "incompatible_ram_types"
error = "incompatible_ram_types"
class IncompatibleDriverInterfaceError(MicroserviceException):
error: str = "incompatible_drive_interface"
error = "incompatible_drive_interface"
class FileNotFoundError(MicroserviceException):
error: str = "file_not_found"
error = "file_not_found"
class FileNotChangeableError(MicroserviceException):
error: str = "file_not_changeable"
error = "file_not_changeable"
class FileAlreadyExistsError(MicroserviceException):
error: str = "file_already_exists"
error = "file_already_exists"
class ParentDirectoryNotFoundError(MicroserviceException):
error: str = "parent_directory_not_found"
error = "parent_directory_not_found"
class CanNotMoveDirIntoItselfError(MicroserviceException):
error: str = "can_not_move_dir_into_itself"
error = "can_not_move_dir_into_itself"
class DirectoriesCanNotBeUpdatedError(MicroserviceException):
error: str = "directories_can_not_be_updated"
error = "directories_can_not_be_updated"
class DirectoryCanNotHaveTextContentError(MicroserviceException):
error: str = "directory_can_not_have_textcontent"
error = "directory_can_not_have_textcontent"
class AlreadyOwnAWalletError(MicroserviceException):
error: str = "already_own_a_wallet"
error = "already_own_a_wallet"
class UnknownSourceOrDestinationError(MicroserviceException):
error: str = "unknown_source_or_destination"
error = "unknown_source_or_destination"
class NotEnoughCoinsError(MicroserviceException):
error: str = "not_enough_coins"
error = "not_enough_coins"
class AlreadyOwnThisServiceError(MicroserviceException):
error: str = "already_own_this_service"
error = "already_own_this_service"
class ServiceNotSupportedError(MicroserviceException):
error: str = "service_not_supported"
error = "service_not_supported"
class ServiceNotRunningError(MicroserviceException):
error: str = "service_not_running"
error = "service_not_running"
class CannotToggleDirectlyError(MicroserviceException):
error: str = "cannot_toggle_directly"
error = "cannot_toggle_directly"
class CouldNotStartServiceError(MicroserviceException):
error: str = "could_not_start_service"
error = "could_not_start_service"
class WalletNotFoundError(MicroserviceException):
error: str = "wallet_not_found"
error = "wallet_not_found"
class MinerNotFoundError(MicroserviceException):
error: str = "miner_not_found"
error = "miner_not_found"
class ServiceNotFoundError(MicroserviceException):
error: str = "service_not_found"
error = "service_not_found"
class UnknownServiceError(MicroserviceException):
error: str = "unknown_service"
error = "unknown_service"
class ServiceCannotBeUsedError(MicroserviceException):
error: str = "service_cannot_be_used"
error = "service_cannot_be_used"
class CannotDeleteEnforcedServiceError(MicroserviceException):
error: str = "cannot_delete_enforced_service"
error = "cannot_delete_enforced_service"
class AttackNotRunningError(MicroserviceException):
error: str = "attack_not_running"
error = "attack_not_running"
class ItemNotFoundError(MicroserviceException):
error: str = "item_not_found"
error = "item_not_found"
class CannotTradeWithYourselfError(MicroserviceException):
error: str = "cannot_trade_with_yourself"
error = "cannot_trade_with_yourself"
class UserUUIDDoesNotExistError(MicroserviceException):
error: str = "user_uuid_does_not_exist"
error = "user_uuid_does_not_exist"
class NetworkNotFoundError(MicroserviceException):
error: str = "network_not_found"
error = "network_not_found"
class AlreadyMemberOfNetworkError(MicroserviceException):
error: str = "already_member_of_network"
error = "already_member_of_network"
class InvitationAlreadyExistsError(MicroserviceException):
error: str = "invitation_already_exists"
error = "invitation_already_exists"
class CannotLeaveOwnNetworkError(MicroserviceException):
error: str = "cannot_leave_own_network"
error = "cannot_leave_own_network"
class CannotKickOwnerError(MicroserviceException):
error: str = "cannot_kick_owner"
error = "cannot_kick_owner"
class MaximumNetworksReachedError(MicroserviceException):
error: str = "maximum_networks_reached"
error = "maximum_networks_reached"
class InvalidNameError(MicroserviceException):
error: str = "invalid_name"
error = "invalid_name"
class NameAlreadyInUseError(MicroserviceException):
error: str = "name_already_in_use"
error = "name_already_in_use"
class NoPermissionsError(MicroserviceException):
error: str = "no_permissions"
error = "no_permissions"

View file

@ -1,4 +0,0 @@
[mypy]
strict = True
ignore_missing_imports = True
plugins=pydantic.mypy

1036
poetry.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,51 @@
[tool.poetry]
name = "PyCrypCli"
version = "2.1.0b0"
description = "Python Cryptic Game Client"
authors = ["Defelo <elodef42@gmail.com>"]
readme = "README.md"
license = "GPL-3.0-only"
homepage = "https://github.com/Defelo/PyCrypCli"
repository = "https://github.com/Defelo/PyCrypCli"
packages = [{ include = "PyCrypCli" }]
[tool.poetry.dependencies]
python = "^3.10"
websocket-client = "^1.3.1"
pyreadline = "^2.1"
pypresence = "^4.2.1"
sentry-sdk = "^1.5.7"
requests = "^2.27.1"
pydantic = "^1.9.0"
[tool.poetry.dev-dependencies]
flake8 = "^4.0.1"
bandit = "1.7.2"
black = "^22.1.0"
wemake-python-styleguide = "^0.16.1"
mypy = "^0.941"
types-requests = "^2.27.12"
[tool.poetry.scripts]
pycrypcli = "PyCrypCli.pycrypcli:main"
[tool.poe.tasks]
flake8 = "flake8 PyCrypCli --count --statistics --show-source"
black = "black PyCrypCli"
mypy = "mypy PyCrypCli"
lint = ["black", "mypy", "flake8"]
pre-commit = ["lint"]
[tool.black]
target-version = ["py310"]
line-length = 120
skip-magic-trailing-comma = true
[tool.mypy]
strict = true
ignore_missing_imports = true
plugins = ["pydantic.mypy"]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

View file

@ -1,7 +0,0 @@
websocket-client~=1.3
pyreadline~=2.1
pypresence~=4.2
python-dateutil~=2.8
sentry-sdk~=1.5
requests~=2.27
pydantic~=1.9

View file

@ -1,16 +0,0 @@
from setuptools import setup, find_packages
from os import environ
setup(
name="PyCrypCli",
version=environ["VERSION"],
url="https://github.com/Defelo/PyCrypCli",
author="Defelo",
author_email="elodef42@gmail.com",
description="Python Cryptic Game Client",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
packages=find_packages(),
install_requires=open("requirements.txt").read().splitlines(),
entry_points={"console_scripts": ["pycrypcli=PyCrypCli.pycrypcli:main"]},
)