# Python Packaging Best Practices š
## Installation Flow
1. Keep setup.py simple - just handle installation
2. Use entry_points for commands
3. Separate installation from first run
4. Use wrapper scripts for complex startup sequences
## Race Conditions
- ā Don't: Run commands directly in setup.py
- ā Don't: Try to import package during install
- ā
Do: Use wrapper scripts (start.sh) for first run
- ā
Do: Show clear instructions after install
## Example Pattern
```bash
# Wrapper script (start.sh)
#!/bin/bash
pip install -e .
sleep 1 # Wait for install
linux-cheats --cli # Run CLI
linux-cheats --web & # Start web
```
## Setup.py Pattern
```python
setup(
entry_points={
'console_scripts': [
'main-command=package.main:main',
'setup-command=package.scripts.setup:post_install',
],
}
)
```
## Post-Install Pattern
```python
def post_install():
"""Show instructions after install"""
print("\n⨠Installation complete!")
print("To start, run: command-name")
```
## Remember
- Keep installation and execution separate
- Use wrapper scripts for complex flows
- Follow the principle of least surprise
- Give clear user instructions
css
html
python
shell
First Time Repository
Python
Languages:
CSS: 5.8KB
HTML: 14.9KB
Python: 21.8KB
Shell: 0.2KB
Created: 12/5/2024
Updated: 12/6/2024