From 68b766779e483c89953dbca6aeb155769f0f0f70 Mon Sep 17 00:00:00 2001 From: Janghoo Lee <46595649+ProtossDragoon@users.noreply.github.com> Date: Sat, 11 May 2024 18:26:59 +0900 Subject: [PATCH] Initial commit --- .github/workflows/ci-discord-noti.yml | 32 ++++ .gitignore | 215 ++++++++++++++++++++++++++ .vscode/settings.json | 8 + Makefile | 29 ++++ README.md | 50 ++++++ myproject/__init__.py | 0 myproject/subpackage/__init__.py | 0 myproject/subpackage/hello.py | 9 ++ myproject/subpackage/test_hello.py | 18 +++ pyproject.toml | 41 +++++ 10 files changed, 402 insertions(+) create mode 100644 .github/workflows/ci-discord-noti.yml create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 README.md create mode 100644 myproject/__init__.py create mode 100644 myproject/subpackage/__init__.py create mode 100644 myproject/subpackage/hello.py create mode 100644 myproject/subpackage/test_hello.py create mode 100644 pyproject.toml diff --git a/.github/workflows/ci-discord-noti.yml b/.github/workflows/ci-discord-noti.yml new file mode 100644 index 0000000..83c89a9 --- /dev/null +++ b/.github/workflows/ci-discord-noti.yml @@ -0,0 +1,32 @@ +name: CI - 디스코드 알림 + +# NOTE: 브랜치 지정 방법 +# https://stackoverflow.com/questions/57699839/github-actions-how-to-target-all-branches-except-master +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + +# NOTE: github 컨텍스트 변수와 디스코드 액션 사용법 +# https://github.com/rjstone/discord-webhook-notify +# https://docs.github.com/ko/actions/learn-github-actions/contexts +jobs: + discord_notify: + runs-on: ubuntu-latest + steps: + - name: Send Notification to Discord + uses: rjstone/discord-webhook-notify@v1.0.4 + with: + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_URL }} + username: ${{ github.event.repository.name }} + severity: info + avatarUrl: https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png + text: | + **${{ github.ref_name }}** 브랜치에 **${{ github.actor }}**님의 새로운 **${{ github.event_name }}**가 있어요! + description: | + ${{ github.event.head_commit.message }} + footer: | + ${{ github.ref_name }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..16ad632 --- /dev/null +++ b/.gitignore @@ -0,0 +1,215 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +Pipfile.lock +Pipfile + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1689ab5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "[python]": { + "editor.formatOnSaveMode": "file", + "editor.formatOnSave": true, + "editor.defaultFormatter": "eeyore.yapf", + "editor.formatOnType": false + } +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..37ba1cc --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +PROJECT = myproject + +all: install lint test format + +install: + python3 -m pip install --upgrade pip + python3 -m pip install --require-virtualenv -e .[dev] + +install-without-venv: + python3 -m pip install --upgrade pip + python3 -m pip install -e .[dev] + +uninstall: + python3 -m pip install --upgrade pip + python3 -m pip uninstall ${PROJECT} + # NOTE: 이 패키지로 인해 설치된 의존성은 가상환경을 삭제하는 방식으로 제거되어야 합니다. + +lint: + python3 -m pylint --rcfile=pylintrc ./${PROJECT} + +format: + python3 -m yapf -ir . + +test: + python3 -m unittest discover -s ./${PROJECT} -p "*_test.py" -v + python3 -m unittest discover -s ./${PROJECT} -p "test_*.py" -v + +publish: + python3 -m flit publish diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cbf0fb --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# vscode-py-template + +환경은 MacOS, Linux 를 기준으로 합니다. + +## 셋업 + +1. 프로젝트의 이름을 정해 `myproject`(가명) 디렉토리의 이름을 변경합니다 + - 이때 `myproject` 는 파이썬에서 임포트가능한 이름이어야 합니다. (e.g. `tensorflow`, `torch`, `Flask`) + - 소문자만으로 이루어진 단일단어로 구성하세요. *'_' 같은 것이 덕지덕지 붙으면 멋이 없어요.* + - `Makefile`의 `PROJECT` 변수값을 동일하게 변경합니다. + - `pyproject.yaml` 의 `name` 변수값을 동일하게 변경합니다. +2. 가상환경을 준비하고 활성화한 다음 `make install` 명령을 실행합니다. + - `make install` 은 개발 모드로 패키지를 설치합니다. + - 개발 모드로 설치하는 것이기 때문에, 가상환경의 `site-package` 디렉토리에 소프트 링크를 거는 방식으로 작동합니다. + - 동일한 가상환경을 사용하는 프로젝트에서 이 `myproject`(가명) 을 임포트해 사용할 수 있습니다. 이때, 현재 프로젝트 폴더 내에서 파일을 수정하면, 링크가 걸려 있기 때문에 `myproject` 를 사용하는 다른 프로젝트에서도 별도의 업데이트 없이 곧바로 수정내용이 반영됩니다. 물론, 이미 특정 모듈을 불러왔다면 파이썬을 닫았다가 다시 켜야 합니다. +3. 디스코드를 사용하는 경우, 깃허브 액션 secret 변수 `DISCORD_WEBHOOK_URL` 을 지정합니다. + - 알림을 보내고 싶은 디스코드 채널의 웹훅 URL을 값으로 등록합니다. + - 관련 액션은 [ci-discord-noti.yml](.github/workflows/ci-discord-noti.yml) 입니다. + +## `Makefile` + +`Makefile`은 다음과 같은 기능들을 가지고 있습니다. + +### `make lint` + +- `.vscode` 설정을 사용하려면 `pylint` 익스텐션을 설치하세요. +- 린터의 기본 세팅에 `pyproject.toml` 파일에 명시된 옵션을 오버라이딩해 코드를 린팅합니다. + +### `make format` + +- 포매터는 google의 `yapf`를 사용합니다. +- `yapf` 포매터의 기본 세팅에 `pyproject.toml` 파일에 명시된 옵션을 오버라이딩해 코드를 포매팅합니다. +- `.vscode` 설정을 사용하려면 `yapf` 익스텐션을 설치하세요. + +### `make test` + +- 테스트는 `unittest`를 사용합니다. +- `test_*.py` 와 `*_test.py` 패턴을 모두 지원합니다. +- 테스트 파일이 존재하는 위치까지 `__init__.py` 로 연결되어 있어야 합니다. + +### `make publish` + +- `~/.pypirc` 파일을 아래와 같이 작성하세요. + ``` + [pypi] + username = __token__ + password = pypi-어쩌고저쩌고 # 개인 API 토큰을 발급받아 작성하세요. + ``` +- 이 명령을 실행하면 `flit` 을 사용하여 PyPI 공개 레지스트리에 패키지를 푸시합니다. +- 앞서 이름으로 지정한 `myproject`(가명)이 업로드되어, 전세계 누구나 `python3 -m pip install myproject`로 패키지를 설치해 사용할 수 있게 됩니다. diff --git a/myproject/__init__.py b/myproject/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/subpackage/__init__.py b/myproject/subpackage/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/myproject/subpackage/hello.py b/myproject/subpackage/hello.py new file mode 100644 index 0000000..33f85eb --- /dev/null +++ b/myproject/subpackage/hello.py @@ -0,0 +1,9 @@ +print(__file__) + + +def hello_world(): + print('hello world!') + + +if __name__ == '__main__': + print('hello!') diff --git a/myproject/subpackage/test_hello.py b/myproject/subpackage/test_hello.py new file mode 100644 index 0000000..e63d3f1 --- /dev/null +++ b/myproject/subpackage/test_hello.py @@ -0,0 +1,18 @@ +import unittest + + +class Testing(unittest.TestCase): + + def test_string(self): + a = 'some' + b = 'some' + self.assertEqual(a, b) + + def test_boolean(self): + a = True + b = True + self.assertEqual(a, b) + + +if __name__ == '__main__': + unittest.main() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8874c31 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,41 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "myproject" +version = "0.1.0" +description = "" +authors = [ + {name = "Janghoo Lee", email = "dlwkdgn1@naver.com"} +] +readme = "README.md" +classifiers = [ + "License :: OSI Approved :: MIT License", +] +requires-python = ">=3.8" +dependencies = [ + "PyYAML", +] + +[project.optional-dependencies] +dev = [ + "flit", + "pylint", + "yapf", +] + +# pyproject.toml is a new configuration file defined in PEP 518. +# It is design to store build system requirements, but it can also store any +# tool configuration for your Python project, possibly replacing the need for +# setup.cfg or other tool-specific files. +# https://github.com/carlosperate/awesome-pyproject + +[tool.yapf] +indent_width = 4 +based_on_style = 'google' +COLUMN_LIMIT = 100 +DEDENT_CLOSING_BRACKETS = true + +[tool.pylint.FORMAT] +max-line-length = 100