Skip to content

Commit

Permalink
fix: Broken version info
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinying committed Oct 10, 2024
1 parent f24ef04 commit f70294c
Show file tree
Hide file tree
Showing 10 changed files with 480 additions and 425 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@ jobs:
with:
token: ${{ steps.app-token.outputs.token }}
release-type: python
include-v-in-tag: false
draft: false # must be 'false' for the first release
10 changes: 10 additions & 0 deletions .release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"packages": {
".": {
"release-type": "python",
"draft": false,
"prerelease": false,
"version-file": "modsim/__init__.py"
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ref,holding_reg14,40018,float32,rw
A docker image has been provided for user to directly run the program,

```bash
docker run -p 5020:5020 helloysd/modsim:latest
docker run -p 5020:5020 topmaker/modsim:latest
```

The above one-line command will create a virtual Modbus TCP device running at `localhost:5020`.
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ networks:
services:
modsim:
# build: .
image: helloysd/modsim:latest
image: topmaker/modsim:latest
container_name: modsim
restart: unless-stopped
networks:
Expand Down
1 change: 1 addition & 0 deletions modsim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.5.0"
10 changes: 5 additions & 5 deletions modsim/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
ModbusSequentialDataBlock,
ModbusServerContext,
ModbusSlaveContext,
ModbusSparseDataBlock,
)
from pymodbus.device import ModbusDeviceIdentification
from pymodbus.payload import BinaryPayloadBuilder
Expand All @@ -43,7 +42,8 @@
StartAsyncUdpServer,
)

from .utils import __version__, get_commandline, get_utc_time, get_logger
from . import __version__
from .utils import get_commandline, get_utc_time, get_logger

_logger = get_logger()

Expand All @@ -55,7 +55,7 @@ def setup_server(args: Any) -> Any:
# 0x100 will respond with an invalid address exception.
# This is because many devices exhibit this kind of behavior (but not all)
if not args.context:
_logger.info("### Create datastore")
_logger.info("Create datastore")
# ----------------------------------------------------------------------- #
# build your payload
# ----------------------------------------------------------------------- #
Expand Down Expand Up @@ -131,7 +131,7 @@ def setup_server(args: Any) -> Any:

async def run_async_server(args: Any) -> Any:
"""Run server."""
txt = f"### start ASYNC server, listening on {args.port} - {args.comm}"
txt = f"Start ASYNC server, listening on {args.port} - {args.comm}"
_logger.info(txt)
if args.comm == "tcp":
address = ("", args.port) if args.port else None
Expand Down Expand Up @@ -221,7 +221,7 @@ async def run_async_server(args: Any) -> Any:

def app() -> None:
_logger.info(
f"Start modsim v{__version__} at {get_utc_time().strftime('%Y-%m-%d %H:%M:%S')} UTC"
f"Starting modsim v{__version__} at {get_utc_time().strftime('%Y-%m-%d %H:%M:%S')} UTC"
)

run_args = setup_server(get_commandline())
Expand Down
19 changes: 4 additions & 15 deletions modsim/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""A collection of utility tools
"""
"""A collection of utility tools"""

import argparse
import logging.config
from datetime import datetime, timezone
import importlib.metadata as metadata # For Python 3.8+
from typing import Any, Optional, Dict
from pymodbus.transaction import (
ModbusAsciiFramer,
Expand All @@ -14,24 +12,16 @@
ModbusTlsFramer,
)

from . import __version__

# global
args: Optional[argparse.Namespace] = None
config: Dict[str, Any] = {}


def get_version() -> str:
try:
return metadata.version(__package__)
except metadata.PackageNotFoundError:
return "unknown"


__version__ = get_version()


def get_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description=f"{__package__} v{__version__} - My python app template"
description=f"Modsim v{__version__} - A Simple Modbus TCP Device Simulator used for modpoll tool"
)
parser.add_argument(
"-v", "--version", action="version", version=f"{__package__} v{__version__}"
Expand Down Expand Up @@ -117,7 +107,6 @@ def get_logger() -> logging.Logger:
format="%(asctime)s | %(levelname).1s | %(processName)s | %(name)s | %(message)s",
)
logger = logging.getLogger(__name__)
logger.info("start logging")
return logger


Expand Down
850 changes: 452 additions & 398 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "modbus-tcp-simulator"
name = "modsim"
version = "0.5.0"
description = "A Simple Modbus TCP Device Simulator used for modpoll tool"
authors = ["Ying Shaodong <[email protected]>"]
Expand All @@ -10,7 +10,8 @@ packages = [{ include = "modsim" }]

[tool.poetry.dependencies]
python = ">=3.8.2,<4.0"
pymodbus = "~3.5.4"
importlib-metadata = "^8.3.0"
pymodbus = "~3.6.9"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.5.0"
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pymodbus==3.5.4 ; python_full_version >= "3.8.2" and python_version < "4.0"
importlib-metadata==8.5.0 ; python_full_version >= "3.8.2" and python_version < "4.0"
pymodbus==3.6.9 ; python_full_version >= "3.8.2" and python_version < "4.0"
zipp==3.20.2 ; python_full_version >= "3.8.2" and python_version < "4.0"

0 comments on commit f70294c

Please sign in to comment.