Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
43 changes: 43 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

database.sqlite
pastebin.db

.env
.venv
env/
venv/
ENV/

frontend/node_modules/
frontend/dist/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's ignored, but not fully removed from the repo?


.vscode/
.idea/
*.swp
*.swo
*~

.DS_Store
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add common Python ignores here (like pycache and others)

Thumbs.db

*.log
logs/
41 changes: 12 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,55 +1,38 @@
# Use Python as base image
# Use Python 3.11 specifically
FROM python:3.11-slim

# Install system dependencies for database
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs

# Set working directory
WORKDIR /app

# Copy requirements
COPY requirements.txt ./

# Install dependencies
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy source code
COPY . .

# Build the frontend
# Build frontend
WORKDIR /app/frontend
RUN npm install
RUN npm run build
RUN npm install && npm run build

# Go back to app directory
WORKDIR /app

# Copy built frontend
RUN mkdir -p static && cp -r frontend/dist/* static/

# Initialize database
RUN python -c "
import asyncio
from backend.database import create_tables, get_engine
from backend.models.user import User
from sqlalchemy.ext.asyncio import AsyncSession
import bcrypt

async def init():
engine = get_engine()
await create_tables(engine)
async with AsyncSession(engine) as session:
admin = User(username='admin', password=bcrypt.hashpw(b'admin', bcrypt.gensalt()).decode(), role='admin')
session.add(admin)
await session.commit()

asyncio.run(init())
"

# Expose port
EXPOSE 8000
EXPOSE 3000

# Start the server
CMD ["python", "main.py"]
65 changes: 49 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,56 @@ DO NOT USE THIS IN PRODUCTION!

## Prerequisites

- Python 3.9 or higher
- Node.js (v14 or higher)
- Python 3.11 (required - Python 3.13 has compatibility issues with some dependencies)
- Node.js (v18 or higher)
- npm (Node Package Manager)

## Installation

1. Clone the repository:
```bash
git clone [repository-url]
cd python-pastebin
cd python-learn_pastebin
```

2. Install Python dependencies:
2. Create and activate virtual environment:
```bash
# Create virtual environment
python3.11 -m venv venv

# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
```

3. Install Python dependencies:
```bash
pip install --upgrade pip
pip install -r requirements.txt
```

3. Install frontend dependencies:
4. Install frontend dependencies and build:
```bash
cd frontend
npm install
npm run build
cd ..
```

4. Start the backend and frontend development server:
5. Start the application:
```bash
python main.py
```

## Usage

1. Access the application at `http://localhost:8000`
1. Access the application at `http://localhost:3000`

2. Login with default credentials:
- Username: `admin`
- Password: `admin`
- Password: `codesignal`

3. Create new snippets:
- Enter a title
Expand All @@ -82,20 +96,39 @@ python main.py
- Use the generated URL (format: `/snippet/:id`)
- Edit and save changes as needed

## Development

### Running in Development Mode
```bash
# Ensure virtual environment is activated
source venv/bin/activate # On Windows: venv\Scripts\activate

# Run backend (will also serve frontend)
python main.py
```

The application runs on port 3000 by default.

### Troubleshooting

If you encounter issues:

1. **Python version issues**: Ensure you're using Python 3.11. Python 3.13 has compatibility issues with current SQLAlchemy versions.
2. **Installing Python 3.11**:
- macOS: `brew install python@3.11`
- Ubuntu: `sudo apt install python3.11 python3.11-venv`
- Windows: Download from python.org
3. **Module not found errors**: Make sure virtual environment is activated and dependencies are installed
4. **Port already in use**: The app will try to use port 3000
5. **Database issues**: Delete `database.sqlite` file and restart

## API Endpoints

- `POST /api/auth/login` - User authentication
- `POST /api/auth/register` - User registration
- `POST /api/snippets` - Create/update snippets
- `GET /api/snippets/:id` - Retrieve a specific snippet

## Development

Both backend and frontend run on port 8000:
```bash
python main.py
```

## Contributing

This is a demo application for educational purposes. If you find any bugs or want to suggest improvements, please open an issue or submit a pull request.
This is a demo application for educational purposes. If you find any bugs or want to suggest improvements, please open an issue or submit a pull request.
Binary file added backend/__pycache__/config.cpython-311.pyc
Binary file not shown.
Binary file added backend/__pycache__/database.cpython-311.pyc
Binary file not shown.
Binary file added backend/__pycache__/database.cpython-313.pyc
Binary file not shown.
Binary file added backend/__pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file added backend/__pycache__/main.cpython-313.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ async def startup_event():
engine = get_engine()
await create_tables(engine)

# Create default admin user
# Create default test user
async with async_session() as session:
from sqlalchemy import select
result = await session.execute(select(User).where(User.username == 'admin'))
existing_admin = result.scalar_one_or_none()
existing_user = result.scalar_one_or_none()

if not existing_admin:
hashed_password = bcrypt.hashpw(b'admin', bcrypt.gensalt()).decode('utf-8')
admin = User(username='admin', password=hashed_password, role=Role.ADMIN)
session.add(admin)
if not existing_user:
hashed_password = bcrypt.hashpw(b'codesignal', bcrypt.gensalt()).decode('utf-8')
test_user = User(username='admin', password=hashed_password, role=Role.ADMIN)
session.add(test_user)
await session.commit()

# Include routers
Expand Down
Binary file added backend/models/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added backend/models/__pycache__/user.cpython-311.pyc
Binary file not shown.
Binary file added backend/routes/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file added backend/routes/__pycache__/auth.cpython-311.pyc
Binary file not shown.
Binary file not shown.
92 changes: 0 additions & 92 deletions frontend/dist/assets/index-CXmrNYyX.js

This file was deleted.

13 changes: 0 additions & 13 deletions frontend/dist/index.html

This file was deleted.

1 change: 0 additions & 1 deletion frontend/dist/vite.svg

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Code Snippet Tool</title>
<title>CodeSignal Learn Pastebin</title>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function App() {
<div style={styles.container}>
<header style={styles.header}>
<div style={{ width: '100%', textAlign: 'center' }}>
<h1>Python Code Snippet Tool</h1>
<h1>CodeSignal Learn Pastebin</h1>
</div>
{user && (
<div style={styles.headerControls}>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Login({ onLogin }: LoginProps) {

return (
<div style={styles.loginContainer}>
<h2 style={styles.loginTitle}>Login to Python Code Snippet Tool</h2>
<h2 style={styles.loginTitle}>Login to CodeSignal Learn Pastebin</h2>
<form style={styles.loginForm} onSubmit={handleSubmit}>
<input
style={styles.input}
Expand Down
2 changes: 1 addition & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default defineConfig({
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:8000',
target: 'http://localhost:3000',
changeOrigin: true
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from backend.main import app

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
uvicorn.run(app, host="0.0.0.0", port=3000)
Loading