본문 바로가기
카테고리 없음

poetry, mypy,장고 stub

by redeyes 2022. 2. 15.
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
 

파워쉘에서 설치후 poetry --version 으로 설치 와 버전 확인

 

이후 파이참터미널 (power shell) 에서 가상환경을 켜줘야하는데 

poetry 로 프로젝트 생성후 해당경로의 env를 잘 찾으면 

 

C:\Users\MSI\AppData\Local\pypoetry\Cache\virtualenvs\pythonproject1-pCAf4jDc-py3.10\Scripts

scripts폴더를 찾아보고 해당 폴더에 activate가 있다면

터미널에서 해당경로로 이동후 activate를 실행해서 가상환경을 실행해보자 

윈도우의 경우 스크립트 오류라던가 혹은 등등의 권한오류가 뜬다면 해결 파워셀을 관리자 모드로 실행후

Set-ExecutionPolicy Unrestricted 

y 로 대응하자.

이후 가상환경에서 activate

 

(Set-ExecutionPolicy Restricted  불안해서 다시 막고 싶다면 y)

 

후에 장고 는 > poetry add django==4.0 django-ninja==0.16.1 로 설치했다 중요한 포인트는;; 다시 원래 경로로 돌아와서 설치 해야한다.

 

poetry add black==21.12b0 (포메팅 툴이라는)

 

poetry run black .   (실행 구문) (홀따옴표를 쌍따옴으로 바꿔준다던가 긴 글은 알아서 개행처리해준다던가 .)

 

[tool.black]
line-length = 120
#black 사용할때 다음줄로 넘어가는 길이 설정 pyproject.toml 혹은 설정에 에디터에 코드스타일 수정

 

장고 stub, mypy 설치

poetry add django-stubs==1.9.0 mypy==0.931

 

#mypy stubs
[tool.mypy]
plugins = ["mypy_django_plugin.main"]
python_version = 3.9
strict = true

[[tool.mypy.overrides]]
module = "*.migrations.*"
ignore_errors = true #mypy 검사를 하지 않겠다.

[[tool.mypy.overrides]]
module = "manage"
ignore_errors = true  #mypy 검사를 하지 않겠다.

[tool.django-stubs]
django_settings_module = "sparta.settings"

이후 run mypy .

이경로에서 실행하지 말고

(UnicodeDecodeError: 'cp949' codec can't decode byte 0xec in position 409: illegal multibyte sequence 이런에러가 뜬다.)

앱이 깔린 경로에서 실행

 

setting 에러 뜨면 

setting.py 에서

보라색 줄 추가 후

 

poetry run mypy 실행해서 오류난 부분을 하나씩 잡아가면 된다.