How to locally develop a python package?

后端 未结 5 487
鱼传尺愫
鱼传尺愫 2021-01-30 18:15

I\'m trying to make changes to an existing python module, and then test it locally. What\'s the best way to do this?

I cloned the github module and made changes, but I\'

5条回答
  •  礼貌的吻别
    2021-01-30 18:54

    The approach of the answer by abc adding the module path to the system path is fine for local, instant testing, but it's not the full solution, for example when C code needs to be compiled or command line hooks must be set. For a full test you might want to install the package instead.

    A typical Python has a setup.py and can be packaged into a distribution file (wheel, ...) which can then be installed locally from a local file.

    The workflow would be:

    • create a package distributable (may include a command like python setup.py bdist_wheel)
    • create a new virtual environment for testing (or de-install any previously installed, non-modified version of the package)
    • installe the package from the locally created distributable (may be as simple as pip install --no-index --find-links=..)
    • run the tests

    This results in exactly the same situation every future user of the package will find itself in and is a complete test (including the installing process), but it's also a lot of effort, that's why I usually only us the system path method during development, but the full installation way only directly before a release.

提交回复
热议问题