gijzelaerr / python-snap7

A Python wrapper for the snap7 PLC communication library
http://python-snap7.readthedocs.org/
MIT License
643 stars 246 forks source link

implement `__main__.py` enty points #409

Closed Cube707 closed 1 year ago

Cube707 commented 1 year ago

This PR implements entripoints via __main__.py files, which closes #407. This can replace the existing bin/snap7-server.py script and offer a much more pythonic way to achive the same.

Currently implemented:

Usage: python -m snap7.server [OPTIONS]

  Command entrypoint to start a dummy server.

Options:
  -p, --port INTEGER  Port the server will listen on.
  --dll FILE          Path to the snap7 DLL (if it is not on path).
  --help              Show this message and exit.

Diskussion

There are still a few question I feel should be discussed:


tests are not working right now...

keeping this a draft untill discussion is done

Cube707 commented 1 year ago

@gijzelaerr could you take a look at this?

Cube707 commented 1 year ago

Implemented the changes.

Current behavior:

Usage: python -m snap7.server [OPTIONS]
# or
Usage: snap7-server [OPTIONS]

  Start a S7 dummy server with some default values.

Options:
  -p, --port INTEGER  Port the server will listen on.
  -v, --verbose       Also print debug-output.
  --version           Show the version and exit.
  -h, --help          Show this message and exit.

[Hidden option: ]
  --dll PATH

I now fully removed the old script. It would cause name-collisions with the new entry-point. The new entry-point is a drop-in replacement. Only preople who provieded a first argument (the path to the dll) to the old script will get an Error: Got unexpected extra argument (foo)

gijzelaerr commented 1 year ago

there seems to be a conflict with master.

Cube707 commented 1 year ago

rebased, should merge now

Cube707 commented 1 year ago

@gijzelaerr should be ready

gijzelaerr commented 1 year ago

i think i've fixed master, if you merge master into your branch the build should work

Cube707 commented 1 year ago

@gijzelaerr I rebase onto the new state of master and now all tests pass. Great work fixing the workflows