From 94bf68ac7974f8539c8dc5d19aced1af8eb32cde Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Sun, 29 Sep 2024 16:01:51 +0900 Subject: [PATCH 01/22] =?UTF-8?q?chore(BE):=20.flake8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/.flake8 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 app/backend/.flake8 diff --git a/app/backend/.flake8 b/app/backend/.flake8 new file mode 100644 index 0000000..805b0d6 --- /dev/null +++ b/app/backend/.flake8 @@ -0,0 +1,22 @@ +[flake8] +show-source = true +extend-ignore = E203, E266, E501, W503, F403, F401, E402, E711, F405, F811, F841, W291, W293, B008, B907, B904, B950 +exclude = + # No need to traverse our git directory + .git, + # There's no value in checking cache directories + __pycache__, + # The conf file is mostly autogenerated, ignore it + docs/source/conf.py, + # The old directory contains Flake8 2.0 + old, + # This contains our built documentation + build, + # This contains builds of flake8 that we don't want to check + dist +max-complexity = 18 +max-line-length = 88 +select = B,C,E,F,W,T4,B9 +per-file-ignores = + __init__.py:F401 + app/utils/prompts.py:W291,W293 \ No newline at end of file From bd45ed46e225ec4992e1b9b33d687c1325b618c4 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Sun, 29 Sep 2024 16:02:47 +0900 Subject: [PATCH 02/22] =?UTF-8?q?chore(BE):=20black=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/pyproject.toml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/app/backend/pyproject.toml b/app/backend/pyproject.toml index 74e00ea..d42163f 100644 --- a/app/backend/pyproject.toml +++ b/app/backend/pyproject.toml @@ -31,4 +31,25 @@ pre-commit = "^3.4.0" [build-system] requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" \ No newline at end of file +build-backend = "poetry.core.masonry.api" + +[tool.black] +line-length = 88 +target-version = ['py37', 'py38'] +include = '\.pyi?$' +extend-exclude = ''' +/( + # The following are specific to Black, you probably don't want those. + \.eggs + | \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | build + | dist + | blib2to3 + | tests/data + | profiling +)/ +''' \ No newline at end of file From 9ccb9f8f1919844071fe9eee53542ad87a23e5f7 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 08:50:11 +0900 Subject: [PATCH 03/22] =?UTF-8?q?chore(BE):=20Dockerfile=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 파이썬 버전 변경 - workdir 변경 - libpq-dev: PostgreSQL 데이터베이스의 클라이언트 라이브러리 개발 파일을 포함하는 패키지 --- app/backend/Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/backend/Dockerfile b/app/backend/Dockerfile index 8617dc0..f0c7f3c 100644 --- a/app/backend/Dockerfile +++ b/app/backend/Dockerfile @@ -1,11 +1,12 @@ # 개발 및 프로덕션 환경을 위한 Dockerfile -FROM python:3.9-slim +FROM python:3.10-slim -WORKDIR /app +WORKDIR /app/backend # 시스템 의존성 설치 RUN apt-get update && apt-get install -y \ build-essential \ + libpq-dev \ && rm -rf /var/lib/apt/lists/* # 파이썬 의존성 파일 복사 및 설치 From 6960a1d07622ed75cfe2518233a53f6e5e05b633 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 08:51:26 +0900 Subject: [PATCH 04/22] =?UTF-8?q?chore(BE):=20.gitignore=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .env 위치 변경 --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3d299e9..6d94d3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # 개발 환경 -.env +app/backend/.env .env.* !.env.example @@ -89,7 +89,7 @@ celerybeat.pid *.sage.py # dotenv -.env +app/backend/.env # virtualenv .venv From f1007a4be03be597f4d0d16c891d3889a12f5d6b Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 08:54:27 +0900 Subject: [PATCH 05/22] =?UTF-8?q?chore(BE):=20docker-compose.yml=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - volumes 경로 변경 - context 경로 변경 --- app/backend/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/backend/docker-compose.yml b/app/backend/docker-compose.yml index 7df1f48..9a91bff 100644 --- a/app/backend/docker-compose.yml +++ b/app/backend/docker-compose.yml @@ -3,14 +3,14 @@ version: '3.8' services: backend: build: - context: ./backend + context: . dockerfile: Dockerfile ports: - "8000:8000" environment: - DATABASE_URL=postgresql://user:password@db:5432/neonadeuli volumes: - - ./backend:/app + - .:/app/backend depends_on: - db From 6aa41aa3340c9f1cf496b2e04f263f31040f9ef7 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 08:59:35 +0900 Subject: [PATCH 06/22] =?UTF-8?q?refactor(BE):=20main.py=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 아직 정의되지 않은 setting에 해당하는 부분 주석 처리 --- app/backend/main.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/backend/main.py b/app/backend/main.py index bca0a91..0717b48 100644 --- a/app/backend/main.py +++ b/app/backend/main.py @@ -35,29 +35,29 @@ def create_application() -> FastAPI: # docs_url= None, # redoc_url= None, title = settings.PROJECT_NAME, - openapi_url=f"{settings.API_V1_STR}/openapi.json", + # openapi_url=f"{settings.API_V1_STR}/openapi.json", generate_unique_id_function=custom_generate_unique_id ) app.add_exception_handler(BaseCustomException, custom_exception_handler) - app.add_middleware(SessionMiddleware, secret_key=settings.BACKEND_SESSION_SECRET_KEY) + # app.add_middleware(SessionMiddleware, secret_key=settings.BACKEND_SESSION_SECRET_KEY) app.middleware("http")(auth_middleware) # Base.metadata.create_all(bind=engine) # Set All CORS enabled origins - if settings.BACKEND_CORS_ORIGINS: - app.add_middleware( - CORSMiddleware, - allow_origins=[ - str(origin).strip("/") for origin in settings.BACKEND_CORS_ORIGINS - ], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"] - ) + # if settings.BACKEND_CORS_ORIGINS: + # app.add_middleware( + # CORSMiddleware, + # allow_origins=[ + # str(origin).strip("/") for origin in settings.BACKEND_CORS_ORIGINS + # ], + # allow_credentials=True, + # allow_methods=["*"], + # allow_headers=["*"] + # ) - app.include_router(api_router, prefix=settings.API_V1_STR) + # app.include_router(api_router, prefix=settings.API_V1_STR) return app From 8cbcf3447ac159482b509e2111ee6f6b07689208 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 09:04:34 +0900 Subject: [PATCH 07/22] =?UTF-8?q?chore(BE):=20requirements.txt=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - flake8, black: linter, formatter 관련 패키지 추가 - itsdangerous, pydantic-settings: docker 빌드 시 no module 에러가 나타나 설치 --- app/backend/requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/backend/requirements.txt b/app/backend/requirements.txt index 48be4b7..a9def85 100644 --- a/app/backend/requirements.txt +++ b/app/backend/requirements.txt @@ -1,21 +1,21 @@ fastapi uvicorn sqlalchemy[asyncio]>=2.0.0 -pymysql==1.1.1 pydantic passlib bcrypt -aiomysql greenlet python-dotenv alembic pytest cryptography -mysqlclient -alembic aiohttp python-jose boto3 haversine aiofiles -asyncpg \ No newline at end of file +asyncpg +flake8 +black +itsdangerous +pydantic-settings \ No newline at end of file From 44ca1c7ef5ceaa542572511ab38b633ed51d246f Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 09:07:21 +0900 Subject: [PATCH 08/22] =?UTF-8?q?chore(BE):=20config=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 현재 설정되어 있지 않은 부분 주석 처리 --- app/backend/src/main/core/config.py | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/app/backend/src/main/core/config.py b/app/backend/src/main/core/config.py index fe53e54..56d7797 100644 --- a/app/backend/src/main/core/config.py +++ b/app/backend/src/main/core/config.py @@ -30,16 +30,16 @@ class Settings(BaseSettings): env_file=".env", env_ignore_empty=True, extra="ignore" ) - API_V1_STR: str - - BACKEND_CORS_ORIGINS: Annotated[ - list[AnyUrl] | str, BeforeValidator(parse_cors) - ] - BACKEND_SESSION_SECRET_KEY : str + # API_V1_STR: str + # + # BACKEND_CORS_ORIGINS: Annotated[ + # list[AnyUrl] | str, BeforeValidator(parse_cors) + # ] + # BACKEND_SESSION_SECRET_KEY : str PROJECT_NAME : str - DATABASE_URL : str + # DATABASE_URL : str # PostgreSQL 설정 POSTGRES_USER: str @@ -49,32 +49,32 @@ class Settings(BaseSettings): POSTGRES_DB: str # 클로바 스튜디오 API - CLOVA_API_KEY : str - CLOVA_API_KEY_PRIMARY_VAL : str - CLOVA_SLIDING_API_HOST : str - CLOVA_COMPLETION_API_HOST : str - MAX_TOKEN : int + # CLOVA_API_KEY : str + # CLOVA_API_KEY_PRIMARY_VAL : str + # CLOVA_SLIDING_API_HOST : str + # CLOVA_COMPLETION_API_HOST : str + # MAX_TOKEN : int # 네이버 클라우드 클로바 보이스 API - CLOVA_VOICE_URL : str - CLOVA_VOICE_CLIENT_ID : str - CLOVA_VOICE_CLIENT_SECRET : str + # CLOVA_VOICE_URL : str + # CLOVA_VOICE_CLIENT_ID : str + # CLOVA_VOICE_CLIENT_SECRET : str # 네이버 클라우드 서버 및 이미지 - NCP_ACCESS_KEY : str - NCP_SECRET_KEY : str - NCP_REGION : str - NCP_ENDPOINT : str - BUCKET_NAME : str - CDN_DOMAIN : str + # NCP_ACCESS_KEY : str + # NCP_SECRET_KEY : str + # NCP_REGION : str + # NCP_ENDPOINT : str + # BUCKET_NAME : str + # CDN_DOMAIN : str # 로그인 보안 관리 - SECRET_KEY : str - ALGORITHM : str - ACCESS_TOKEN_EXPIRE_MINUTES : int + # SECRET_KEY : str + # ALGORITHM : str + # ACCESS_TOKEN_EXPIRE_MINUTES : int # 기본 이미지 URL - DEFAULT_IMAGE_URL : str + # DEFAULT_IMAGE_URL : str @computed_field @property From 52adc4df2b9776a2126f27a70349c897c5158005 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 09:13:34 +0900 Subject: [PATCH 09/22] =?UTF-8?q?fix(BE):=20config=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - / 제거 --- app/backend/src/main/core/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/backend/src/main/core/config.py b/app/backend/src/main/core/config.py index 56d7797..971f5b3 100644 --- a/app/backend/src/main/core/config.py +++ b/app/backend/src/main/core/config.py @@ -85,7 +85,7 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn: password=self.POSTGRES_PASSWORD, host=self.POSTGRES_SERVER, port=self.POSTGRES_PORT, - path=f"/{self.POSTGRES_DB}", + path=f"{self.POSTGRES_DB}", ) settings = Settings() \ No newline at end of file From 9258e86b023e261670dfc642e337265c9a686686 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 09:15:27 +0900 Subject: [PATCH 10/22] =?UTF-8?q?chore(BE):=20create=20user=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=A3=BC=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/src/main/domains/user/repositories.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/backend/src/main/domains/user/repositories.py b/app/backend/src/main/domains/user/repositories.py index 020ebfb..7e20401 100644 --- a/app/backend/src/main/domains/user/repositories.py +++ b/app/backend/src/main/domains/user/repositories.py @@ -5,9 +5,9 @@ class UserRepository: def get_user(self, db: Session, user_id: int): return db.query(models.User).filter(models.User.id == user_id).first() - def create_user(self, db: Session, user: schemas.UserCreate): - db_user = models.User(email=user.email, hashed_password=user.password) # 실제로는 비밀번호를 해시화해야 합니다 - db.add(db_user) - db.commit() - db.refresh(db_user) - return db_user \ No newline at end of file + # def create_user(self, db: Session, user: schemas.UserCreate): + # db_user = models.User(email=user.email, hashed_password=user.password) # 실제로는 비밀번호를 해시화해야 합니다 + # db.add(db_user) + # db.commit() + # db.refresh(db_user) + # return db_user \ No newline at end of file From 9f94965521e6da06427a702dfb60920c929c2ba9 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 22:29:27 +0900 Subject: [PATCH 11/22] =?UTF-8?q?chore(BE):=20gitignore=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sonarqube 스캔 시 생기는 파일 경로 gitignore 처리 --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6d94d3c..eb861ed 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ app/backend/.env .env.* !.env.example +#sonarqube +app/backend/.scannerwork + # 의존성 /node_modules /.pnp From 83fee48e4fd3fbdfa7222869201b2475c1331f41 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 22:44:36 +0900 Subject: [PATCH 12/22] =?UTF-8?q?chore(BE):=20pre-commit=20=EC=84=B8?= =?UTF-8?q?=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/.pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/backend/.pre-commit-config.yaml diff --git a/app/backend/.pre-commit-config.yaml b/app/backend/.pre-commit-config.yaml new file mode 100644 index 0000000..6f6db7c --- /dev/null +++ b/app/backend/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/psf/black + rev: 24.8.0 + hooks: + - id: black + language_version: python3.10 +- repo: https://github.com/pycqa/flake8 + rev: 7.1.1 + hooks: + - id: flake8 From 15ef2dec71b01e4389d7fcdd956c7158f5d7024e Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 23:07:01 +0900 Subject: [PATCH 13/22] =?UTF-8?q?chore(BE):=20pre-commit=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/.pre-commit-config.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/backend/.pre-commit-config.yaml b/app/backend/.pre-commit-config.yaml index 6f6db7c..dac6ae4 100644 --- a/app/backend/.pre-commit-config.yaml +++ b/app/backend/.pre-commit-config.yaml @@ -17,3 +17,10 @@ repos: rev: 7.1.1 hooks: - id: flake8 + args: [ + "--max-line-length=88", + "--extend-ignore=E203,E266,E501,W503,F403,F401,E402,E711,F405,F811,F841,W291,W293,B950,B008,B904,B907", + "--max-complexity=18", + "--select=B,C,E,F,W,T4,B9", + "--exclude=.git,__pycache__,docs/source/conf.py,old,build,dist" + ] From 5a5e143e9e2ff711f7dd44f65a62b67bf4d33d89 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 23:07:24 +0900 Subject: [PATCH 14/22] =?UTF-8?q?chore(BE):=20pre-commit=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/backend/main.py b/app/backend/main.py index 0717b48..d6dfa4b 100644 --- a/app/backend/main.py +++ b/app/backend/main.py @@ -12,11 +12,13 @@ from src.main.core.exceptions import BaseCustomException, custom_exception_handler from src.main.middleware.auth import auth_middleware + def custom_generate_unique_id(route: APIRoute) -> str: if route.tags: return f"{route.tags[0]}-{route.name}" return route.name + @asynccontextmanager async def app_lifespan(app: FastAPI): # 애플리케이션 시작 시 실행될 로직 @@ -28,15 +30,16 @@ async def app_lifespan(app: FastAPI): yield # 애플리케이션 종료 시 실행될 로직 (필요한 경우) + def create_application() -> FastAPI: app = FastAPI( - lifespan= app_lifespan, + lifespan=app_lifespan, # 배포 시 swagger UI, Redoc 비활성화 # docs_url= None, # redoc_url= None, - title = settings.PROJECT_NAME, + title=settings.PROJECT_NAME, # openapi_url=f"{settings.API_V1_STR}/openapi.json", - generate_unique_id_function=custom_generate_unique_id + generate_unique_id_function=custom_generate_unique_id, ) app.add_exception_handler(BaseCustomException, custom_exception_handler) @@ -61,4 +64,5 @@ def create_application() -> FastAPI: return app -app = create_application() \ No newline at end of file + +app = create_application() From f2add2228f576d19ac0cd23137c09f8da5d6e11a Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 23:10:32 +0900 Subject: [PATCH 15/22] =?UTF-8?q?chore(BE):=20docker-compose=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sonarqube 로컬 연동 --- app/backend/docker-compose.yml | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/backend/docker-compose.yml b/app/backend/docker-compose.yml index 9a91bff..0bbfb2f 100644 --- a/app/backend/docker-compose.yml +++ b/app/backend/docker-compose.yml @@ -14,6 +14,7 @@ services: depends_on: - db + db: image: postgres:13 environment: @@ -23,5 +24,33 @@ services: volumes: - postgres_data:/var/lib/postgresql/data + sonarqube: + image: sonarqube:latest + ports: + - "9000:9000" + environment: + - SONAR_JDBC_URL=jdbc:postgresql://sonarqube_db:5432/sonar + - SONAR_JDBC_USERNAME=sonar + - SONAR_JDBC_PASSWORD=sonar + volumes: + - sonarqube_data:/opt/sonarqube/data + - sonarqube_extensions:/opt/sonarqube/extensions + - sonarqube_logs:/opt/sonarqube/logs + depends_on: + - sonarqube_db + + sonarqube_db: + image: postgres:13 + environment: + - POSTGRES_DB=sonar + - POSTGRES_USER=sonar + - POSTGRES_PASSWORD=sonar + volumes: + - sonarqube_db_data:/var/lib/postgresql/data + volumes: - postgres_data: \ No newline at end of file + postgres_data: + sonarqube_data: + sonarqube_extensions: + sonarqube_logs: + sonarqube_db_data: From 7481ff0273229b3d2ef01a081d71363ab3733369 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Mon, 30 Sep 2024 23:14:54 +0900 Subject: [PATCH 16/22] =?UTF-8?q?chore(BE):=20requirements.txt=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pre commit 패키지 추가 closed #5 --- app/backend/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/backend/requirements.txt b/app/backend/requirements.txt index a9def85..67ad382 100644 --- a/app/backend/requirements.txt +++ b/app/backend/requirements.txt @@ -18,4 +18,5 @@ asyncpg flake8 black itsdangerous -pydantic-settings \ No newline at end of file +pydantic-settings +pre-commit From 5d6df75b97aad9bcecc58f0842a948fa2faea0f1 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Tue, 1 Oct 2024 21:07:14 +0900 Subject: [PATCH 17/22] =?UTF-8?q?chore(BE):=20.pre-commit-config=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - flake8 중복 설정 부분 제거 - flake8-bugbear, comprehensions, pytest-style 추가 --- app/backend/.pre-commit-config.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/backend/.pre-commit-config.yaml b/app/backend/.pre-commit-config.yaml index dac6ae4..5c698d8 100644 --- a/app/backend/.pre-commit-config.yaml +++ b/app/backend/.pre-commit-config.yaml @@ -17,10 +17,4 @@ repos: rev: 7.1.1 hooks: - id: flake8 - args: [ - "--max-line-length=88", - "--extend-ignore=E203,E266,E501,W503,F403,F401,E402,E711,F405,F811,F841,W291,W293,B950,B008,B904,B907", - "--max-complexity=18", - "--select=B,C,E,F,W,T4,B9", - "--exclude=.git,__pycache__,docs/source/conf.py,old,build,dist" - ] + additional_dependencies: [flake8-bugbear, flake8-comprehensions, flake8-pytest-style] From aaca196113959a5d3efb2dc3922914ecff996413 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Tue, 1 Oct 2024 21:08:18 +0900 Subject: [PATCH 18/22] =?UTF-8?q?chore(BE):=20requirements.txt=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - flake8-bugbear, comprehensions, pytest-style 추가 - isort 추가 - mypy 추가 --- app/backend/requirements.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/backend/requirements.txt b/app/backend/requirements.txt index 67ad382..309fd58 100644 --- a/app/backend/requirements.txt +++ b/app/backend/requirements.txt @@ -20,3 +20,8 @@ black itsdangerous pydantic-settings pre-commit +flake8-bugbear +flake8-comprehensions +flake8-pytest-style +isort +mypy From 664256a281c2944d9a611255cb6abac116a6427a Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Tue, 1 Oct 2024 21:10:27 +0900 Subject: [PATCH 19/22] =?UTF-8?q?chore(BE):=20pyproject.toml=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - black: max-length 통일 - isort 추가 - mypy 추가 --- app/backend/pyproject.toml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/backend/pyproject.toml b/app/backend/pyproject.toml index d42163f..715ad90 100644 --- a/app/backend/pyproject.toml +++ b/app/backend/pyproject.toml @@ -34,7 +34,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.black] -line-length = 88 +line-length = 120 target-version = ['py37', 'py38'] include = '\.pyi?$' extend-exclude = ''' @@ -52,4 +52,12 @@ extend-exclude = ''' | tests/data | profiling )/ -''' \ No newline at end of file +''' + +[tool.isort] +line_length = 120 +skip_glob = ["*/migrations/*"] + +[tool.mypy] +no_namespace_packages = true +no_strict_optional = true From a9d2cc9457080ed45f7dadf190a9d70b88de528a Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Tue, 1 Oct 2024 21:14:01 +0900 Subject: [PATCH 20/22] =?UTF-8?q?chore(BE):=20flake8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ignore: 기본적인 것들만 남겨두고 나머지 삭제. 추후 필요 시 추가 예정 - bug bear, comprehensions, pytest 추가 --- app/backend/.flake8 | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/backend/.flake8 b/app/backend/.flake8 index 805b0d6..3ce149d 100644 --- a/app/backend/.flake8 +++ b/app/backend/.flake8 @@ -1,6 +1,6 @@ [flake8] show-source = true -extend-ignore = E203, E266, E501, W503, F403, F401, E402, E711, F405, F811, F841, W291, W293, B008, B907, B904, B950 +extend-ignore = E203, E266, E501, W503 exclude = # No need to traverse our git directory .git, @@ -13,10 +13,20 @@ exclude = # This contains our built documentation build, # This contains builds of flake8 that we don't want to check - dist -max-complexity = 18 -max-line-length = 88 -select = B,C,E,F,W,T4,B9 + dist, + .gitignore, + */migrations/* +max-complexity = 10 +max-line-length = 120 +select = B,C,E,F,W,T4,B9,PT +# B : bugbear +# C : comprehensions +# PT : pytest style +#bugbear, comprehensions +extend-select = B950, C4 +#pytest style +pytest-fixture-no-parentheses = True +pytest-mark-no-parentheses = True per-file-ignores = __init__.py:F401 - app/utils/prompts.py:W291,W293 \ No newline at end of file + app/utils/prompts.py:W291,W293 From 575427876b487ea742525ed7a53b0c91ce6fbea4 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Tue, 1 Oct 2024 21:16:01 +0900 Subject: [PATCH 21/22] =?UTF-8?q?chore(BE):=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=ED=92=88=EC=A7=88=20CI=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CI 단계에서 자동 포맷팅 수행 작업 close #5 --- .../code-quality-check-integration.yml | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/code-quality-check-integration.yml diff --git a/.github/workflows/code-quality-check-integration.yml b/.github/workflows/code-quality-check-integration.yml new file mode 100644 index 0000000..0d0bc21 --- /dev/null +++ b/.github/workflows/code-quality-check-integration.yml @@ -0,0 +1,78 @@ +name: Backend Code Quality CI + +on: + push: + branches: [ develop, release ] + paths: + - 'app/backend/**' + pull_request: + paths: + - 'app/backend/**' + +jobs: + lint-and-test: + # Ubuntu 최신 환경에서 실행 + runs-on: ubuntu-latest + + steps: + # Github Repository 체크아웃 + - name: Checkout code + uses: actions/checkout@v4 + + # python 환경 설정 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + # python 버전 표시 + - name : Display Python version + run : python --version + + # Python 패키지 설치 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r app/backend/requirements.txt + + # 코드 포맷팅 Pre-commit 실행 + - name: Run pre-commit + run: pre-commit run --files app/backend/**/*.py + + # 변경사항 확인 + - name: Check for changes + id: git-check + run: | + git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT + + # 변경사항 커밋 & 푸시 + - name: Commit and push changes + if: steps.git-check.outputs.changes == 'true' && github.event_name == 'pull_request' + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add . + git commit -m "Apply automatic formatting changes" + git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.head_ref }} + + + # PR에 코멘트 추가 + - name: Comment PR + if: steps.git-check.outputs.changes == 'true' && github.event_name == 'pull_request' + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.name, + body: '✨ Code has been automatically formatted. Please review the changes.' + }) + + # 남은 문제 확인 + - name: Check for remaining issues + if: failure() + run: | + echo "There are still some issues that couldn't be automatically fixed. Please address them manually." + exit 1 From 5f5a27ee68d90173321d88287ce9f9501d653c11 Mon Sep 17 00:00:00 2001 From: keem-hyun Date: Tue, 1 Oct 2024 21:25:44 +0900 Subject: [PATCH 22/22] =?UTF-8?q?chore(BE):=20CI=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 프로젝트 경로 위치 수정 --- .github/workflows/code-quality-check-integration.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-quality-check-integration.yml b/.github/workflows/code-quality-check-integration.yml index 0d0bc21..7232276 100644 --- a/.github/workflows/code-quality-check-integration.yml +++ b/.github/workflows/code-quality-check-integration.yml @@ -37,12 +37,15 @@ jobs: # 코드 포맷팅 Pre-commit 실행 - name: Run pre-commit - run: pre-commit run --files app/backend/**/*.py + run: | + cd app/backend + pre-commit run --files **/*.py # 변경사항 확인 - name: Check for changes id: git-check run: | + cd app/backend git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT # 변경사항 커밋 & 푸시 @@ -51,7 +54,7 @@ jobs: run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" - git add . + git add app/backend git commit -m "Apply automatic formatting changes" git push https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git HEAD:${{ github.head_ref }}