Having developed a console utility, you decide to publish it on PyPI. Well, is it true that what could be better than making it available through pip install ? Googling what is needed for this, you may stumble upon the only post I have found on a topic that is not only from 2014, it also requires you to create a bunch of folders and files for completely unnecessary things.
How to solve this problem without a headache in 2019? I already asked this question and therefore, having read a ton of documentation, I created this tutorial for you. Here is a step by step guide.
1. Create an account on PyPI ( link for registration )
2. Create an entry point to the application (for example, entry.py with the following contents)
def main(): print("It's alive!")
3. Install poetry
curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python source $HOME/.poetry/env
( poetry can be installed differently, for example, pip install - user poetry - approx. transl.)
4. Create an environment
cd myproject # , poetry init
5. Configure the console command (to do this, add the following lines in the appeared file pyproject.toml )
[tool.poetry.scripts] APPLICATION-NAME = 'entry:main'
APPLICATION-NAME need to change the name of the console command.
6. Publish the utility! (use the username and password from step 1)
poetry publish --username PYPI_USERNAME --password PYPI_PASS --build
Done! Now another person needs only two commands to install:
$ sudo pip install PROJECT-NAME $ APPLICATION-NAME
Where PROJECT-NAME is the name you gave the project in step 4, and APPLICATION-NAME is the name of the command from step 5.
Whenever you want to update a module, just change the version number in the pyproject.toml file :
version = "0.1.0"
And repeat step 6:
poetry publish --username PYPI_USERNAME --password PYPI_PASS --build
Add the following lines to the .travis.yml file
language: python dist: xenial before_install: - curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python - source $HOME/.poetry/env install: - poetry install script: - poetry build deploy: - provider: script skip_cleanup: true script: poetry publish --username $PYPI_USER --password $PYPI_PASS on: branch: master python: '3.7' tags: true
And set the PYPI_USER and PYPI_PASS environment variables at travis-ci.com . After that, it will be possible to publish the package using the commands:
git tag -a v1.2 # Replace version number with yours git push --tags
Source: https://habr.com/ru/post/456304/
All Articles