|
1 | 1 | # Python Package Example |
2 | 2 | This repository contains a basic python package example with the aim of showing how a good python package should look like. |
3 | 3 |
|
| 4 | +Install: |
| 5 | +``` |
| 6 | +pip install helloworld |
| 7 | +``` |
| 8 | +Install locally: |
| 9 | +``` |
| 10 | +git clone https://github.com/mkmenta/python-package-example.git |
| 11 | +cd python-package-example |
| 12 | +pip install -e . |
| 13 | +``` |
| 14 | +If you are developing, you should run `pip install -e .` every time you change `setup.py` or the dependencies etc. to make sure that everything works. |
| 15 | + |
| 16 | +Usage example: |
| 17 | +```python |
| 18 | +from helloworld import say_hello |
| 19 | + |
| 20 | +# Generate "Hello world!" |
| 21 | +say_hello() |
| 22 | + |
| 23 | +# Generate "Hello mkmenta!" |
| 24 | +say_hello("mkmenta") |
| 25 | +``` |
| 26 | + |
| 27 | +### Developing |
| 28 | +To install the package along with the tools you need to develop it run the following (local installation with the `"dev"` extras: |
| 29 | +``` |
| 30 | +git clone https://github.com/mkmenta/python-package-example.git |
| 31 | +cd python-package-example |
| 32 | +pip install -e ."[dev]" |
| 33 | +``` |
| 34 | +### A note about requirements |
| 35 | +The requirements needed to **run** the package should go in the `install_requires` argument of `setup()` in the `setup.py`. |
| 36 | + |
| 37 | +The requirements needed to **develop** the package should go in the `extras_require` argument dict (under the `"dev"` key) of `setup()` in the `setup.py`. |
| 38 | + |
| 39 | +This is preferred to a `requirements.txt` file, because this is code and it can be understood directly during the installation of the package itself. |
| 40 | + |
| 41 | +The `requirements.txt` should be used to recreate enviroments with specific versions (e.g.`requests==2.22.0`), not to share software. |
| 42 | + |
| 43 | +### Building and distribution |
| 44 | +Build without installi i.e. build wheel: |
| 45 | +``` |
| 46 | +python3 setup.py bdist_wheel |
| 47 | +``` |
| 48 | + |
| 49 | +Source distribution: |
| 50 | +``` |
| 51 | +python3 setup.py sdist |
| 52 | +``` |
| 53 | +For the source distribution, remember to: |
| 54 | +- Check out the warnings of `python3 setup.py sdist`. |
| 55 | +- Check that every file from the repo is packed in the tar file (`tar tzf dist/helloworld-X.X.X.tar.gz`) as written in the `MANIFEST.in`. A useful tool is `check-manifest`. |
| 56 | + |
| 57 | +### Uploading to PyPI |
| 58 | +``` |
| 59 | +python3 setup.py bdist_wheel sdist |
| 60 | +twine upload dist/* |
| 61 | +``` |
| 62 | + |
| 63 | +### Other useful stuff |
| 64 | +- This repo is prepared for PyCharm and it has some run configurations (in `.idea/runConfigurations`). |
| 65 | + |
4 | 66 | ## References |
5 | 67 | - Mark Smith - Publish a (Perfect) Python Package on PyPI ([video](https://www.youtube.com/watch?v=GIF3LaRqgXo&list=WL&index=9&t=779s)) |
| 68 | +- `.gitignore` file from [gitignore.io](gitignore.io) |
| 69 | +- License from [choosealicense.com](choosealicense.com) |
| 70 | +- PyPI classifiers from https://pypi.org/classifiers/ |
0 commit comments