Skip to content

Commit f8b8875

Browse files
Merge pull request #1 from CodeSignal/issue_fix
fixed the issues
2 parents 20c8d7f + 2f34f61 commit f8b8875

File tree

1,947 files changed

+115
-703706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,947 files changed

+115
-703706
lines changed

.gitignore

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
*.so
5+
.Python
6+
build/
7+
develop-eggs/
8+
dist/
9+
downloads/
10+
eggs/
11+
.eggs/
12+
lib/
13+
lib64/
14+
parts/
15+
sdist/
16+
var/
17+
wheels/
18+
*.egg-info/
19+
.installed.cfg
20+
*.egg
21+
22+
database.sqlite
23+
pastebin.db
24+
25+
.env
26+
.venv
27+
env/
28+
venv/
29+
ENV/
30+
131
frontend/node_modules/
32+
frontend/dist/
33+
34+
.vscode/
35+
.idea/
36+
*.swp
37+
*.swo
38+
*~
39+
40+
.DS_Store
41+
Thumbs.db
42+
43+
*.log
44+
logs/

Dockerfile

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,38 @@
1-
# Use Python as base image
1+
# Use Python 3.11 specifically
22
FROM python:3.11-slim
33

4-
# Install system dependencies for database
4+
# Install system dependencies
55
RUN apt-get update && apt-get install -y \
66
gcc \
77
g++ \
8+
curl \
89
&& rm -rf /var/lib/apt/lists/*
910

11+
# Install Node.js
12+
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
13+
&& apt-get install -y nodejs
14+
1015
# Set working directory
1116
WORKDIR /app
1217

1318
# Copy requirements
1419
COPY requirements.txt ./
1520

16-
# Install dependencies
21+
# Install Python dependencies
1722
RUN pip install --no-cache-dir -r requirements.txt
1823

1924
# Copy source code
2025
COPY . .
2126

22-
# Build the frontend
27+
# Build frontend
2328
WORKDIR /app/frontend
24-
RUN npm install
25-
RUN npm run build
29+
RUN npm install && npm run build
2630

31+
# Go back to app directory
2732
WORKDIR /app
2833

29-
# Copy built frontend
30-
RUN mkdir -p static && cp -r frontend/dist/* static/
31-
32-
# Initialize database
33-
RUN python -c "
34-
import asyncio
35-
from backend.database import create_tables, get_engine
36-
from backend.models.user import User
37-
from sqlalchemy.ext.asyncio import AsyncSession
38-
import bcrypt
39-
40-
async def init():
41-
engine = get_engine()
42-
await create_tables(engine)
43-
async with AsyncSession(engine) as session:
44-
admin = User(username='admin', password=bcrypt.hashpw(b'admin', bcrypt.gensalt()).decode(), role='admin')
45-
session.add(admin)
46-
await session.commit()
47-
48-
asyncio.run(init())
49-
"
50-
5134
# Expose port
52-
EXPOSE 8000
35+
EXPOSE 3000
5336

5437
# Start the server
5538
CMD ["python", "main.py"]

README.md

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,56 @@ DO NOT USE THIS IN PRODUCTION!
3030

3131
## Prerequisites
3232

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

3737
## Installation
3838

3939
1. Clone the repository:
4040
```bash
4141
git clone [repository-url]
42-
cd python-pastebin
42+
cd python-learn_pastebin
4343
```
4444

45-
2. Install Python dependencies:
45+
2. Create and activate virtual environment:
4646
```bash
47+
# Create virtual environment
48+
python3.11 -m venv venv
49+
50+
# Activate virtual environment
51+
# On macOS/Linux:
52+
source venv/bin/activate
53+
# On Windows:
54+
venv\Scripts\activate
55+
```
56+
57+
3. Install Python dependencies:
58+
```bash
59+
pip install --upgrade pip
4760
pip install -r requirements.txt
4861
```
4962

50-
3. Install frontend dependencies:
63+
4. Install frontend dependencies and build:
5164
```bash
5265
cd frontend
5366
npm install
67+
npm run build
5468
cd ..
5569
```
5670

57-
4. Start the backend and frontend development server:
71+
5. Start the application:
5872
```bash
5973
python main.py
6074
```
6175

6276
## Usage
6377

64-
1. Access the application at `http://localhost:8000`
78+
1. Access the application at `http://localhost:3000`
6579

6680
2. Login with default credentials:
6781
- Username: `admin`
68-
- Password: `admin`
82+
- Password: `codesignal`
6983

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

99+
## Development
100+
101+
### Running in Development Mode
102+
```bash
103+
# Ensure virtual environment is activated
104+
source venv/bin/activate # On Windows: venv\Scripts\activate
105+
106+
# Run backend (will also serve frontend)
107+
python main.py
108+
```
109+
110+
The application runs on port 3000 by default.
111+
112+
### Troubleshooting
113+
114+
If you encounter issues:
115+
116+
1. **Python version issues**: Ensure you're using Python 3.11. Python 3.13 has compatibility issues with current SQLAlchemy versions.
117+
2. **Installing Python 3.11**:
118+
- macOS: `brew install python@3.11`
119+
- Ubuntu: `sudo apt install python3.11 python3.11-venv`
120+
- Windows: Download from python.org
121+
3. **Module not found errors**: Make sure virtual environment is activated and dependencies are installed
122+
4. **Port already in use**: The app will try to use port 3000
123+
5. **Database issues**: Delete `database.sqlite` file and restart
124+
85125
## API Endpoints
86126

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

92-
## Development
93-
94-
Both backend and frontend run on port 8000:
95-
```bash
96-
python main.py
97-
```
98-
99132
## Contributing
100133

101-
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.
134+
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.
810 Bytes
Binary file not shown.
2.05 KB
Binary file not shown.
1.73 KB
Binary file not shown.
3.93 KB
Binary file not shown.
3.42 KB
Binary file not shown.

backend/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ async def startup_event():
2828
engine = get_engine()
2929
await create_tables(engine)
3030

31-
# Create default admin user
31+
# Create default test user
3232
async with async_session() as session:
3333
from sqlalchemy import select
3434
result = await session.execute(select(User).where(User.username == 'admin'))
35-
existing_admin = result.scalar_one_or_none()
35+
existing_user = result.scalar_one_or_none()
3636

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

4343
# Include routers
323 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)