Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Structuring Your Python Project
Search
Matt Bachmann
January 20, 2016
Programming
4k
1
Share
Structuring Your Python Project
For people who know some Python and want to structure their first project
Matt Bachmann
January 20, 2016
More Decks by Matt Bachmann
See All by Matt Bachmann
Property Based Testing: Hypothesis
bachmann1234
0
800
Diff-Cover
bachmann1234
1
280
Opening The Floodgates: Unicode Identifiers in Python
bachmann1234
0
360
Other Decks in Programming
See All in Programming
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
530
さぁV100、メモリをお食べ・・・
nilpe
0
110
Modding RubyKaigi for Myself
yui_knk
0
820
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.8k
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
140
権限チェックの一貫性を型で守る TypeScript による多層防御
mnch
4
980
誰も頼んでない機能を出荷した話
zekutax
0
150
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
1.3k
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
OCRを使ってゲームのアイテムをデータ化する
kishikawakatsumi
0
120
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
1.8k
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
2.2k
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
160
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Building AI with AI
inesmontani
PRO
1
1k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
200
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Raft: Consensus for Rubyists
vanstee
141
7.5k
Evolving SEO for Evolving Search Engines
ryanjones
0
210
Transcript
Structuring Your Python Project Matt Bachmann
Agenda • Directory Structure • Isolating Your Environment • Installing
Dependencies • Packaging Your Project • Releasing to the World
Our Project • Display Current Weather > forcastio 42.3907 -71.1157
Currently: rain - Mixed precipitation tomorrow through Thursday, with temperatures falling to 41°F on Monday.
Project Structure
The Code
Style Checking Your Code
The Tests
Running Your Tests
License
Documentation
Documentation • All projects should have a readme ◦ Description
◦ Installation ◦ Usage • Moving Beyond Readme! ◦ Sphinx • Write docs in reStructuredText ◦ Renders in Github and PyPi. PyPi does not support Markdown
Specifying Dependencies and Isolating Your Project
Isolate Your Project • Install virtualenv > pip install virtualenv
• Create an isolated environment > virtualenv venv • Turn that environment on > source venv/bin/activate
Installing Dependencies Install a package pip install <package name> Upgrade
a package pip install -U <package name> Uninstall a package pip uninstall <package name> List Installed packages pip freeze Install packages from a file pip install -r <requirements file>
Installing Dependencies • requirements.txt requests==2.8.1 • test-requirements.txt coverage==4.0.3 flake8==2.5.0 mock==1.3.0
pyflakes==1.0.0 pytest==2.8.3
Deploying Your Project
Setup.py setup( name='displayforecastio', version='1.0', author='Matt Bachmann', url='https://github.com/Bachmann1234/displayforecastio', description='Display the current
weather in your terminal', license='Apache 2.0', packages=[‘displayforecastio'], install_requires=['requests==2.8.1'], entry_points={ 'console_scripts': ['forcastio = displayforecastio.app:run'], } )
What This Gives You • Install your project from project
root > pip install . • After installation you have a command! > forecastio 42.3907 -71.1157 • Share your project with the world
Pip Editable Installs • pip install -e <path to your
project> ◦ Installs a project by pointing to it ◦ Won’t work over pypi • Change your code, your installation reflects the changes • Super handy debugging tool • Fun way to explore other people’s projects!
Deploying Your Project To PyPI Step 1: Register for an
account
Deploying Your Project To PyPI Step 2: Create a .pypirc
in your home directory > cat .pypirc [server-login] username:Matt.Bachmann password:NotAChance
Deploying Your Project To PyPI Step 3: Register Your package
(from project root) > python setup.py register <Name>
Deploying Your Project To PyPI DONE!
Deploying Your Project To PyPI > pip install displayforecastio >
forecastio 42.3907 -71.1157 Currently: rain - Mixed precipitation tomorrow through Thursday, with temperatures falling to 42°F on Saturday.
Deploying Your Project To PyPI • Deploying Updates ◦ After
updating the version in setup.py > python setup.py sdist upload
References • Documentation ◦ https://readthedocs.org/ ◦ http://sphinx-doc.org/contents.html • Example Projects
◦ https://github.com/Bachmann1234/terminalweather ◦ https://github.com/pypa/sampleproject • Flake8 ◦ https://flake8.readthedocs.org/en/latest/ ◦ https://www.youtube.com/watch?v=wf-BqAjZb8M (Not about flake8 but an important lesson for anyone caring about style) • Folder Structure ◦ http://learnpythonthehardway.org/book/ex46.html • Licensing ◦ http://choosealicense.com/ • Pip ◦ http://pip.readthedocs.org/en/stable/user_guide/
References • PyPi ◦ https://pypi.python.org • reStructuredText ◦ http://docutils.sourceforge.net/ •
Setup.py ◦ https://docs.python.org/2/distutils/setupscript.html • Virtualenv ◦ http://virtualenv.readthedocs.org/en/latest/userguide.html