How to organize your code into a python package that can be installed with pip and published to pypi or other python repositories.
!SLIDE
!SLIDE
pip install my-project
do_something
or
git clone [email protected]:me/my-project.git
cd my-project
pip install -r requirements.txt
echo "$PATH=~/my-project/:$PATH" >> ~/.bashrc
python do_something.py
!SLIDE
git submodules
vs pip install my-project==0.2.7
!SLIDE
Entry points are a way to make your python program available neatly
entry_points={
'console_scripts': [
'my_project = my_project.__main__:main'
]
},
!SLIDE
What you need to easily distribute your software via:
- public pypi
- private pypi repo (internal to company, say)
- just from github
!SLIDE
!SLIDE
!SLIDE
It's far easier to get hired with good work in the public eye
!SLIDE
pip install package-name
vs
git clone github.com:someguy/someproject.git
cd someproject
vi README
pip install -r requirements.txt
// scratches head???
// gives up *shrug*
!SLIDE
- Have some working code
- Create a setup.py file
- Profit!
!SLIDE
- Just barely works
- Where most of us start
!SLIDE
- Better, using argparse rather than sys.argv
- Can we do better?
!SLIDE
- Uses setup.py so installable
- No "package hygiene" -> look in virtualenv
!SLIDE
- Installable
- Hygienic
- Not easy to use from shell
!SLIDE
- Installable
- Package-hygienic
- CLI binary
!SLIDE
- Installable
- Package-hygienic
- CLI binary
- Includes dependencies
- Easy to read/understand
!SLIDE
- Installable
- Package-hygienic
- CLI binary
- Includes dependencies
- Easy to read/understand
- Documented!
!SLIDE
I started with these directions: http://peterdowns.com/posts/first-time-with-pypi.html
Turns out they're totally wrong now!
- Register accounts with test and prod
- Create a .pypirc file
- Publish in test
- Publish in prod
!SLIDE
!SLIDE
[distutils]
index-servers =
pypi
testpypi
[pypi]
repositoy=https://pypi.python.org/pypi
username=MikeSandfordArundo
password=WHOAWHOAWHOA
[testpypi]
repository=https://test.pypi.org/legacy/
username=MikeSandfordArundo
password=WHOAWHOAWHOA
!SLIDE
(virt) sandford@mjolnir ~/talks/echoer $ python setup.py sdist
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'entry_points'
warnings.warn(msg)
/usr/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
running sdist
running check
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
warning: sdist: standard file not found: should have one of README, README.txt
writing manifest file 'MANIFEST'
creating Echoer-2.2
creating Echoer-2.2/echoer
making hard links in Echoer-2.2...
hard linking setup.cfg -> Echoer-2.2
hard linking setup.py -> Echoer-2.2
hard linking echoer/__init__.py -> Echoer-2.2/echoer
hard linking echoer/cli.py -> Echoer-2.2/echoer
creating dist
Creating tar archive
removing 'Echoer-2.2' (and everything under it)
(virt) sandford@mjolnir ~/talks/echoer $ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Uploading distributions to https://test.pypi.org/legacy/
Enter your username: MikeSandfordArundo
Enter your password:
Uploading Echoer-2.2.tar.gz
100%|███████████████████████████████████████████████████████████████| 3.42k/3.42k [00:01<00:00, 3.31kB/s]
(virt) sandford@mjolnir ~/talks/echoer $
!SLIDE
(virt) sandford@mjolnir ~/talks/echoer $ twine upload dist/*Uploading distributions to https://upload.pypi.org/legacy/
Uploading Echoer-2.2.tar.gz
100%|███████████████████████████████████████████████████████████████| 3.42k/3.42k [00:00<00:00, 14.6kB/s]
(virt) sandford@mjolnir ~/talks/echoer $
!SLIDE
- Packagecloud.io
- Gemfury.com
- Cloudrepo.io
- Self-hosted
- pyshop
- pypiserver
- extrapypi
- pypicloud
!SLIDE
- Classifiers
- Keywords
find_packages
- Data files
- Project URLs
- Extra dependencies (dev, test, docs)
!SLIDE
!SLIDE