This project serves as an example for building a python package and uploading to TestPyPi. See instructions below for a step-by-step guide on how to achieve this.
After creating your own environment, use
pip install ranboardom
import ranboardom as rb
rb.board()
Which outputs something like this without any function arguments:
[['e' '"' '*' '<' '*']
['*' '*' 'h' '*' '*']
['*' '*' 'o' '*' '*']
['7' '$' '*' '*' '*']
['*' 'w' '*' '*' '*']]
- create a separate venv for poetry under the root_directory/venv for example
python -m venv venv/packaging
- activate environment
source venv/packaging/bin/activate
- install poetry, which will be used to build our code into a python package called ranboardom
pip install -U pip setuptools
pip install poetry
- check installed version of poetry
poetry --version
- install the dependencies listed in pyproject.toml
poetry install
- test if the package was installed under the current environment
python -c "import ranboardom as rb; rb.board(10, 10, 'o')"
- to build the package use the following command in the root directory:
poetry build
- this creates a folder called dist/ with the wheel and sdist, either can be used to install the package using
cd dist
pip install ranboardom-0.1.0-py3-none-any.whl
- we need to add TestPyPI to the list of repositories poetry knows abouy (only needed when publishing dummy or test releases)
poetry config repositories.test-pypi https://test.pypi.org/legacy/
- publish the built package to TestPyPi (this requries a token, which can be generated following this guide)
poetry publish -r test-pypi -u __token__ -p TOKEN_COMES_HERE
The repository is uploaded under here
- installing the package should be possible from any device and environment (to tell pip to search also on test pypi, we need the following flags):
pip install --index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
ranboardom
--extra-index-url
is used to let pip know that not all dependencies are located under test pypi, but rather look for them under pypi
Complete guide for packaging your code is available here