Skip to content

Conversation

dhoomakethu
Copy link
Contributor

Closes #2

pymodbus on  dev [$?] via 🐍 v3.8.13 (pymodbus)
❯ pymodbus.server --host 0.0.0.0 --verbose run --modbus-config /Users/sanjay/repo/pymodbus/pymodbus/server/reactive/default_config.json --modbus-server tcp --modbus-framer socket --modbus-port 5020 --unit-id 1 --unit-id 2 -u 4 -r 1 --timeout 2
2024-02-17 13:14:56,530 INFO  logging:97 Modbus server started
2024-02-17 13:14:56,530 DEBUG logging:103 Awaiting connections server_listener
2024-02-17 13:14:56,531 INFO  logging:97 Server listening.

__________                          .______.                    _________
\______   \___.__. _____   ____   __| _/\_ |__  __ __  ______  /   _____/ ______________  __ ___________
 |     ___<   |  |/     \ /  _ \ / __ |  | __ \|  |  \/  ___/  \_____  \_/ __ \_  __ \  \/ // __ \_  __ \\
 |    |    \___  |  Y Y  (  <_> ) /_/ |  | \_\ \  |  /\___ \   /        \  ___/|  | \/\   /\  ___/|  | \/
 |____|    / ____|__|_|  /\____/\____ |  |___  /____//____  > /_______  /\___  >__|    \_/  \___  >__|
           \/          \/            \/      \/           \/          \/     \/                 \/


SERVER >

  • The issue was with typing module on python3.8 and use of from __future__ import annotations.

Works also on the other versions of python

@alexrudd2
Copy link
Collaborator

alexrudd2 commented Feb 19, 2024

Hmm, it's still not working for me after python3 -m pip install -e . I'll have to keep experimenting.

alex@antorak:~/git/repl/pymodbus/repl/client$ python3 -m pip list | grep pymodbus
pymodbus                           3.7.0.dev0       /home/alex/git/pymodbus
pymodbus-repl                      0.1.1
alex@antorak:~/git/repl/pymodbus/repl/client$ python3 --version
Python 3.10.12
alex@antorak:~/git/repl/pymodbus/repl/client$ python3 main.py
Traceback (most recent call last):
  File "/home/alex/git/repl/pymodbus/repl/client/main.py", line 15, in <module>
    from pymodbus import __version__ as pymodbus_version
ImportError: cannot import name '__version__' from 'pymodbus' (unknown location)

Edit: well, it works with poetry shell still.

@dhoomakethu
Copy link
Contributor Author

@alexrudd2 do not use -e option with pip install . Just run poetry install or pip install .`

@alexrudd2
Copy link
Collaborator

I did some more testing with both pip install [-e] . and poetry install

The namespace problem is still there.
main.py is running from the new repl repo correctly. I tested this by adding a NotImplementedError in client/main.py: CLI.__init__(), which was raised.

However, imports in the other files are pulling in the "old" REPL code from the pymodbus repo. I tested this by adding a NotImplementedError in client/completer:CmdCompleter.__init__(), which was not raised. So that means it was importing from the pymodbus code.

@dhoomakethu
Copy link
Contributor Author

Can you try a fresh virtual env and run just poetry install from the root of this repo please ?

@alexrudd2
Copy link
Collaborator

alexrudd2 commented Feb 19, 2024

alex@antorak:~/git/repl$ python3 -m pip uninstall pymodbus-repl
<...>
  Successfully uninstalled pymodbus_repl-0.1.0

alex@antorak:~/git/repl$ git reset --hard main
HEAD is now at a75dc4c Merge pull request #1 from pymodbus-dev/Updates-1

alex@antorak:~/git/repl$ gh pr checkout 5
Switched to branch 'repl-server-startup'
Your branch is up to date with 'origin/repl-server-startup'.
Already up to date.

alex@antorak:~/git/repl$ python3 -m poetry install
<..>
Installing the current project: pymodbus-repl (0.1.1)

alex@antorak:~/git/repl$ python3 pymodbus/repl/client/main.py tcp
Traceback (most recent call last):
  File "/home/alex/git/repl/pymodbus/repl/client/main.py", line 15, in <module>
    from pymodbus import __version__ as pymodbus_version
ImportError: cannot import name '__version__' from 'pymodbus' (unknown location)

alex@antorak:~/git/repl$ poetry shell
Spawning shell within /home/alex/.cache/pypoetry/virtualenvs/pymodbus-repl-aORKxoe6-py3.10
. /home/alex/.cache/pypoetry/virtualenvs/pymodbus-repl-aORKxoe6-py3.10/bin/activate

 alex@antorak:~/git/repl$ python3 pymodbus/repl/client/main.py tcp
<runs `main.py` from `repl` but with `CmdCompleter` from `pymodbus` >

@alexrudd2
Copy link
Collaborator

alex@antorak:~/git/repl$ git reset --hard main
HEAD is now at a75dc4c Merge pull request #1 from pymodbus-dev/Updates-1

alex@antorak:~/git/repl$ python3 -m poetry env remove 3.10
< removed venv >

alex@antorak:~/git/repl$ gh pr checkout 4
Switched to branch 'pymodbus_repl'

alex@antorak:~/git/repl$ python3 -m poetry install
<..>
Installing the current project: pymodbus-repl (0.1.1)

alex@antorak:~/git/repl$ python3 -m poetry shell
alex@antorak:~/git/repl$ python3 pymodbus_repl/client/main.py tcp
<runs `main.py` from `repl`  with all code from `repl` >

@dhoomakethu
Copy link
Contributor Author

@alexrudd2 can you give this branch a try repl-server-startup?
Here is a demo of local setup https://asciinema.org/a/7agPdg9JYBgjLzIABQws7mrOk

@alexrudd2
Copy link
Collaborator

Yes, I did. the gh cli command automatically I showed above switches to the PR branch.

alex@antorak:~/git/repl$ gh pr checkout 5
Switched to branch 'repl-server-startup'

@dhoomakethu
Copy link
Contributor Author

dhoomakethu commented Feb 19, 2024

@alexrudd2 I see what you are pointing at, it works fine for client but for server its picking from the repl directory from the pymodbus installation. However, if we install dev branch of pymodbus it should work from with in the repl repo. Let me try out a quick fix for that.

@alexrudd2
Copy link
Collaborator

From your asciicinema sharing, I believe you are still importing code from pymodbus (but can't be certain). Can you try the NotImplementedException test I performed?

repl/server/cli.py

async def run_repl(server):
    """Run repl server."""
    raise NotImplementedError  # <-- ADD THIS
    await main(server)

If the code is importing from pymodbus, it will not crash. If it is importing from the local code, it will crash.

@alexrudd2
Copy link
Collaborator

@alexrudd2 I see what you are pointing at

OK, I'm glad. It's difficult to explain :)

it works fine for client [...]

It is not about client versus server. it works fine only for client/main.py and server/main.py. But any imports in those files are not correct. (For instance, client/completer.py or server/cli.py.)

@dhoomakethu
Copy link
Contributor Author

@alexrudd2 I see your point, the simplest fix would be to go with your PR for this.

@dhoomakethu
Copy link
Contributor Author

Certain changes from this PR will be cherry picked once #4 is merged.

|____| / ____\____|__ /\____/\____ | /\ |____|_ /\___ > __/|____/
\/ \/ \/ \/ \/ \/|__|
v1.3.1 - {pymodbus_version}
v0.1.1 - {pymodbus_version}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should go "backwards" with the version number here. Instead, probably better to change the whole package to 1.4.0? or perhaps 2.0.0 to indicate a major break?

Copy link
Collaborator

@alexrudd2 alexrudd2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why from __future__ import annotations does not work as it should. However, your fix works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pymodbus.server fails to run
2 participants