Skip to content

Commit

Permalink
Merge pull request #82 from kd-it/main
Browse files Browse the repository at this point in the history
merge code
  • Loading branch information
densuke authored Sep 26, 2024
2 parents 76696e7 + 97781f7 commit 2194d0e
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 94 deletions.
71 changes: 46 additions & 25 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/base:jammy",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python環境",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
"version": "latest"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.black-formatter",
"esbenp.prettier-vscode",
"oderwat.indent-rainbow"
],
"settings": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"editor.formatOnSave": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}

}
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
26 changes: 26 additions & 0 deletions .github/workflows/lesson01.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
paths: "lesson01/*.py"
branches:
- main
workflow_dispatch:

jobs:
# code check
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python(3.12)
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install black formatter
run: pip install black

# コードをフォーマットするが、結果は別の場所に保存する
- name: check formatting
run: black lesson01/ --check --diff
30 changes: 30 additions & 0 deletions .github/workflows/lesson02.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
paths: "lesson02/*.py"
branches:
- main
workflow_dispatch:

jobs:
# code check
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python(3.12)
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: code check in lesson02
run: |
cd lesson02
python typecheck01.py
- name: code check in lesson02(is_int_list)
if: always()
run: |
cd lesson02
python typecheck02.py
30 changes: 30 additions & 0 deletions .github/workflows/lesson03.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
on:
push:
paths: "lesson03/*.py"
branches:
- main
workflow_dispatch:

jobs:
# code check
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python(3.12)
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: code check in lesson03(01)
run: |
cd lesson03
python test_01.py
- name: code check in lesson03(02)
if: always()
run: |
cd lesson03
python test_02.py
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__pycache__/
**/__pycache__/
.vscode/settings.json
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
# GitHubセミナー 2024年度版
# Python セミナー その 2 2024 年度版

## 何をするの?

GitHubの使い方についての簡単なセミナーです。
ざっくり以下のことを行う予定です。
Python を通して、各言語における比較的共通性のある話題を意識し直してもらいます。

- GitHubの使い方、見方(サイト上)
- GitHubコマンド(`gh`)
- GitHubでのリポジトリ操作
- 自力編
- チーム編
- コンフリクト編
- プルリクエスト編
- おまけ機能紹介(時間のある範囲で)
- GitHub Actions
- GitHub Pages
## 主な議題

## 使い方
- コードを少しきれいに書く
- 型の制約で安心感を少しあげる
- テストを書く
- ドキュメントを書く

このリポジトリは直接クローンせず、必ずフォーク(fork)してからそちらをクローンしてください。
詳細はセミナーで説明します。

(forkしたリポジトリから)ローカルに構築できたら、DevContainerを起動してください。
おまけはいくつかあるかな
4 changes: 4 additions & 0 deletions lesson01/black-check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# このファイルは意図的に空っぽにしています
# ちょっときたな目にコードを書いて保存してみましょう
# 例: x=42
#
14 changes: 14 additions & 0 deletions lesson02/missmatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 型のミスマッチが起こすバグの例


def add_one():
pass


def is_int_list():
pass


if __name__ == "__main__":
pass # ここに上記関数を使うコードを書いてみる
#
10 changes: 10 additions & 0 deletions lesson02/typecheck01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3
# 注意: このファイルはいじらないでください

import typing
from missmatch import add_one

assert typing.get_type_hints(add_one)["x"] == int, "引数xの型ヒントがintではありません"
assert (
typing.get_type_hints(add_one)["return"] == int
), "戻り値の型ヒントがintではありません"
14 changes: 14 additions & 0 deletions lesson02/typecheck02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
# 注意: このファイルはいじらないでください

import typing
from missmatch import is_int_list

# is_int_list()の型ヒントを確認する
assert (
typing.get_type_hints(is_int_list)["lst"] == list[any]
), "引数lstの型ヒントがlist[any]ではありません"
# is_int_list()の戻り値がboolであることを確認する
assert (
typing.get_type_hints(is_int_list)["return"] == bool
), "戻り値の型ヒントがboolではありません"
11 changes: 11 additions & 0 deletions lesson03/test_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# assertを使ったテストコードの例


# 引数で渡された値が奇数であるかどうかを返す関数
# 型ヒントにより 整数→bool となるようにしましょう
def is_odd():
pass


# 直接実行時に、上記関数が正常に機能するかをassert文で書いてみましょう
# 全てが正常に機能したら"All tests passed!"と表示しましょう
29 changes: 29 additions & 0 deletions lesson03/test_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# doctestの練習(テストケース)
# 関数is_leap_yearを考えてみましょう
# この関数は、引数で受け取った年がうるう年かどうかを判定する関数です
# うるう年の条件は以下の通りです
# 1. 西暦が4で割り切れる年はうるう年
# 2. ただし、西暦が100で割り切れる年はうるう年ではない
# 3. ただし、西暦が400で割り切れる年はうるう年


def is_leap_year(year: int) -> bool:
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
return True
return False


# いわゆるFizzBuzz問題
# 指定された数値までの数値の結果をリストで返しましょう
# ルール: 3の倍数は'fuzz'、5の倍数は'buzz'、3と5の倍数は'fizzbuzz'とする
# それ以外の値は数値を文字列にして返す(list[str]となる)
# fb_list(5) -> ['1', '2', 'fizz', '4', 'buzz']


def fb_list():
pass
3 changes: 3 additions & 0 deletions lesson03/use_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from test_01 import is_odd

# 実際に1〜10に対するis_oddの結果を出すように書いてみましょう
10 changes: 0 additions & 10 deletions python/main.py

This file was deleted.

24 changes: 0 additions & 24 deletions python/python-test.yml

This file was deleted.

16 changes: 0 additions & 16 deletions python/testcase.py

This file was deleted.

0 comments on commit 2194d0e

Please sign in to comment.