A mini project that create the required python packaging template folders, submit to GitHub & enable pip installation.
- Objectives:
-
- Upload a python project to GitHub and enable py-installable.
-
- Required Tools:
-
- Cookie Cutter– for templating. Use pip install cookiecutter.
- GitHub account, Github desktop, Git shell — version control, git command line.
- PyPI account — for uploading to pypi so a user can just do “pip install your_project”.
-
- Steps:
-
- Cookie Cutter to set up the template directory and required folders with relevant docs and files (Readme.md, .gitignore, setup.py etc) for uploading. –> See commands section 1 below.
- use commands in cmd prompt or Git shell for windows (preferred Git shell if you executing additional git commands in step 2).
- Create a folder with same name as the directory name created in step 1 and place the relevant python codes inside.
- Use Git commands to upload files to GitHub. The below commands will only work if the repository is first created in your GitHub account. –> See commands section 2 below.
- Alternatively, you can use the GUI version for the GitHub instead of command line to submit your project to the repository.
- Create a .pypirc in same directory as the setup.py file. This will be used to provide the info to upload to pypi. –> See section 3
- Updates:
- Ensure setuptools and wheel are up to date and install twine
- pip install -U setuptools wheel; pip install twine
- Package the code
- python setup.py sdist bdist_wheel
- Upload the package
- twine upload –repository pypi dist/*
- Ensure setuptools and wheel are up to date and install twine
- Cookie Cutter to set up the template directory and required folders with relevant docs and files (Readme.md, .gitignore, setup.py etc) for uploading. –> See commands section 1 below.
-
Windows Command prompt for step 1
pip install cookiecutter cookiecutter https://github.com/wdm0006/cookiecutter-pipproject.git cd projectname
Git Commands for step 3
git init git add -A git commit -m 'first commit' git remote add origin http://repository_url # works only if repository is created in Git. See Git commands for repository url. git push origin master git tag {{version}} -m 'adds the version you entered in cookiecutter as the first tag for release, change the version 0.0.1 etc' git push --tags origin master
.pypirc contents for step 5
[distutils] # this tells distutils what package indexes you can push to index-servers = pypi [pypi] repository: https://pypi.python.org/pypi username: {{your_username}} password: {{your_password}}
Further notes
- Most of the commands above are from Will McGinnis’ post and python packaging tutorial
- To create an empty file in windows for the .pypirc, use cmd echo >.pypirc
- Uploading to PyPI require a verfiied email address else there will be error uploading.
- When encounter “fatal: remote origin already exists.”. See link
- Basic GIT commands. See link
- Updates: uploading packages to pypi using twine. (link)
- Making changes to the code and uploading (link)
Update changes to github
git add -A git commit -m 'whatever' git push origin master git tag {{version}} -m 'adds the version you entered in cookiecutter as the first tag for release, change the version 0.0.1 etc' git push --tags origin master
Update changes to pypi
Simply upload your new code to github, create a new release, then adapt the setup.py file (new download_url — according to your new release tag, new version), then run the setup.py and the twin command again
python setup.py sdist twine upload dist
One comment