Django command naming convention

구경회·2024년 1월 15일
0
post-thumbnail

대부분 underscore(_)로 구별하는 것을 권장하지만, 일관성있게 지키지는 않는 것으로 보인다. 장고 공식 문서에서도 underscore를 권장하는 내용은 없다.

https://docs.djangoproject.com/en/5.0/howto/custom-management-commands/

공식 문서에서 커스텀 커맨드를 만드는데에서 네이밍 관련한 예시는 찾아볼 수 없고 커뮤니티에서 관련한 논의를 몇 개 찾을 수 있었다. 하지만 실제 Django command에서는 그냥 편한대로 쓰는 거 같다.

find . -type d -name "management" | grep -v "/tests/" | while read -r dir; do
    commands_path="$dir/commands"
    if [ -d "$commands_path" ]; then
                                           
        for command_file in "$commands_path"/*.py; do
            if [ -f "$command_file" ] && [ "$(basename "$command_file")" != "__init__.py" ]; then
                command_name=$(basename "$command_file" .py)
                echo "- $command_name"
            fi
        done
    fi  
done

위 스크립트를 이용해서 장고의 공식 커맨드 이름들을 살피면 아래와 같다.

- check
- compilemessages
- createcachetable
- dbshell
- diffsettings
- dumpdata
- flush
- inspectdb
- loaddata
- makemessages
- makemigrations
- migrate
- optimizemigration
- runserver
- sendtestemail
- shell
- showmigrations
- sqlflush
- sqlmigrate
- sqlsequencereset
- squashmigrations
- startapp
- startproject
- test
- testserver
- changepassword
- createsuperuser
- collectstatic
- findstatic
- runserver
- clearsessions
- remove_stale_contenttypes
- inspectdb
- ogrinspect

오히려 undescore를 사용하지 않는 걸 권장하는게 아닌가 싶을 정도이다. remove_stale_contenttypes 정도를 제외하면 모두 underscore를 사용하지는 않았다.

Django에서 공식적으로 지원하는 건 아니지만 Django Rest Framework의 커맨드를 살펴보면 다음과 같다.

- drf_create_token
- generateschema

이쪽도 역시 네이밍 컨벤션이라고 부를만한게 존재하지 않는 것처럼 보인다.

profile
즐기는 거야

0개의 댓글