728x90

빌드 프로세스를 자동화하는 것은 개발자들에게 매우 유용함

이를 효율적으로 수행하기 위해 Makefile을 사용하는 것은 일반적인 방법 중 하나

makefile이란?

Makefile은 소프트웨어 빌드 프로세스를 자동화하기 위한 텍스트 파일

가장 많이 사용하는 반복적인 작업 표준화하거나, 여러 작업을 한꺼번에 실행하는 표준화된 방법을 제공함

여러 명령어를 포함할 수 있으며, 변수, 조건문, 반복문 등을 사용하여 복잡한 빌드 프로세스를 자동화할 수 있음

makefile 기본 구조

target: dependencies
    command
  • target : 생성하고자 하는 파일의 이름이나 작업의 이름
  • dependencies : 해당 작업을 수행하는 데 필요한 파일이나 작업
  • command : 해당 작업을 수행하는 명령어

makefile을 이용한 빌드 자동화 구현 예시 (python)

# 작업디렉토리 구조
src
 ㄴ __init__.py
 ㄴ point_location.py
tests
 ㄴ test_point_location.py
Makefile
# src/point_location.py
from dataclasses import dataclass

@dataclass
class Point:
    x: int
    y: int

def location(p: Point) -> str:
    """맵에서 좌표에 해당하는 객체를 검색"""
    return f'{p.x, p.y}'
# tests/test_point_location.py
from src.point_location import Point, location

def test_location():
    # 포인트 객체 생성
    p = Point(1, 2)
    
    # 좌표를 검색하고 결과를 확인
    result = location(p)
    assert result == "(1, 2)"
# Makefile
# .PHONY는 make 명령어를 실행할 때 해당 명령어를 실행하도록 하는 것
.PHONY: typehint
typehint:
    mypy --ignore-missing-imports src/

.PHONY: test
test:
    pytest tests/

.PHONY: lint
lint:
    pylint src/

.PHONY: checklist
checklist: typehint test lint

.PHONY: black
black:
    black -l 79 *.py

.PHONY: clean
clean:
    find . -type f -name "*.pyc" | xargs rm -fr
    find . -type d -name "__pycache__" | xargs rm -fr
더보기

# 실행 명령어

export PYTHONPATH="${PYTHONPATH}:$(pwd)"

make checklist mypy --ignore-missing-imports src/

 

# 실행결과

Success: no issues found in 2 source files

pytest tests/ ============================================ test session starts =============================================

platform darwin -- Python 3.8.10, pytest-8.1.1, pluggy-1.4.0

rootdir: /Users/stone/Desktop/pythonworkspace

collected 1 item

 

tests/test_point_location.py . [100%]

 

============================================= 1 passed in 0.02s ==============================================

pylint src/

************* Module src.point_location

src/makefile_test.py:1:0: C0114: Missing module docstring (missing-module-docstring)

src/makefile_test.py:4:0: C0115: Missing class docstring (missing-class-docstring)

 

----------------------------------- Your code has been rated at 6.67/10

make: *** [lint] Error 16

728x90

'AI > ML ops' 카테고리의 다른 글

DVC 기초 및 사용법  (0) 2022.11.02
대용량 데이터 버전관리 오픈소스 LFS vs DVC  (0) 2022.10.28

+ Recent posts