Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/mdlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Deploy to Server

on:
push:
pull_request:

jobs:
markdownlint:
name: markdownlint-cli2-action
runs-on: ubuntu-latest
steps:
# 1. リポジトリのコードをチェックアウト
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0

# 2. markdownlint を実行し、ファイルを自動修正
- name: Run markdownlint and fix
uses: DavidAnson/markdownlint-cli2-action@992badcdf24e3b8eb7e87ff9287fe931bcb00c6e # v20.0.0
with:
globs: |
source/organize/**/*.md
source/textbook/**/*.md
fix: true
config: '.markdownlint-cli2.jsonc'

# 3. 変更されたファイルをコミット&プッシュ
- name: Commit and push changes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions経由でのgit pushだとmdlint.ymlでパーミッションの変更の設定が必要になってしまうので、たぶんこの内容だとgit pushでエラーになります。
stefanzweifel/git-auto-commit-actionのドキュメントによると、以下の設定を書いているようです。

    permissions:
      # Give the default GITHUB_TOKEN write permission to commit and push the
      # added or changed files to the repository.
      contents: write

ただ、ちゃんと動くか動作確認が大変そうなので、このmdlint.ymlの中では自動修正まではやらないで、ルール違反のmarkdownがあったらエラー扱いする程度でいいかと思いますー。

自動修正をやりたいなら、pre-commitを使ってローカルでgit commitするときにmarkdownlint-cli2を実行させるようにようにする手があるかと思います。
設定例: https://github.com/DavidAnson/markdownlint-cli2#pre-commit

Copy link
Contributor Author

@m-tsuru m-tsuru Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit を設定するとなると,ローカルの環境で markdownlint-cli2 をインストールすることをさせなければなりませんが,なんとなくこっちの都合でそれに付き合わせるのも変な感じですので,エラーを吐かせるぐらいがちょうど良さそうですね.方針をその方向に変更します. え,待って,そうである必要がない?

uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5.2.0
with:
# コミットメッセージ
commit_message: "style: Apply markdownlint changes [skip ci]"
# コミットするユーザー名
commit_user_name: "github-actions[bot]"
# コミットするメールアドレス
commit_user_email: "github-actions[bot]@users.noreply.github.com"
7 changes: 7 additions & 0 deletions .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"config": {
"MD013": false,
"MD024": false,
"MD041": false
}
}
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ $ rm -rf ~/.cache/matplotlib

### コンテナ環境を利用したビルド環境準備
- この手順は必須ではありません
- コンテナ環境を利用して、貢献者同士の開発環境を統一することができる
- コンテナ環境を利用して、貢献者同士の開発環境を統一することができる
設定ファイルは [.devcontainer/devcontainer.json](.devcontainer/devcontainer.json)

- Visual Studio Codeの拡張機能を利用する場合 (ローカル環境)
- Visual Studio Codeの拡張機能を利用する場合 (ローカル環境)
[Visual Studio Code を使用して Docker コンテナーを開発環境として使用する - Training | Microsoft Learn](https://learn.microsoft.com/ja-jp/training/modules/use-docker-container-dev-env-vs-code/)

- GitHub Codespacesを使用する場合 (リモート環境)
- GitHub Codespacesを使用する場合 (リモート環境)
[GitHub Codespacesのクイックスタート](https://docs.github.com/ja/codespaces/getting-started/quickstart)

## How to build(macOSまたはLinux)
Expand Down Expand Up @@ -72,3 +72,9 @@ $ .\env\Scripts\Activate.ps1
ERROR: Could not find a version that satisfies the requirement Sphinx==8.2.3 (from versions: 0.1.61611, 0.1.61798, 0.1.61843, ・・・・・省略
ERROR: No matching distribution found for Sphinx==8.2.3


# Markdownlint について

Markdown ファイルを Lint するために、Pull Requests の発行時に Markdownlint が実行されるようになっています。

サプライチェーン攻撃を防ぐために、バージョンはコミットハッシュで固定されています。
1 change: 0 additions & 1 deletion source/textbook/1_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ Python 3.13.7

WindowsでPythonを利用する場合は、Pythonの公式サイトで配布されているWindowsインストーラーを利用します。


OSのアーキテクチャによって以下のいずれかのインストーラーをダウンロードし、ウィザードに従ってインストールします。

- 64ビット版 (AMD64): [Windows installer (64-bit)](https://www.python.org/ftp/python/3.13.7/python-3.13.7-amd64.exe)
Expand Down
3 changes: 2 additions & 1 deletion source/textbook/2_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ FizzBuzzとは、複数の人が集まって行うゲームです。

FizzBuzzは簡単な問題ですが、実装する言語の制御文(繰り返し、条件分岐)を使いこなす必要があり、言語入門の第一歩としてちょうどよい題材です

% FizzBuzz Question/Test について書くかどうか http://blog.codinghorror.com/why-cant-programmers-program/_
% FizzBuzz Question/Test について書くかどうか <http://blog.codinghorror.com/why-cant-programmers-program/>_

### Pythonファイル

Expand Down Expand Up @@ -524,6 +524,7 @@ True
>>> isinstance(l1, collections.abc.Sequence)
True
```

:::

## まとめ
Expand Down
2 changes: 1 addition & 1 deletion source/textbook/4_collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ snake
```{index} tuple single: Collection; tuple
```


## 辞書(dict)

辞書はリストと同じコレクションです。
Expand Down Expand Up @@ -509,6 +508,7 @@ True

```{index} dict single: Collection; dict
```

## 集合(set)

集合型(set)はコレクション型の1つです。
Expand Down
2 changes: 1 addition & 1 deletion source/textbook/5_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Hello Python
こんにちはPython
```


```{index} read() single: File; read()
```

Expand Down Expand Up @@ -187,6 +186,7 @@ with文でのファイルオープン
Hello Python
こんにちはPython
```

:::

```{index} append mode single: File; append mode
Expand Down
1 change: 1 addition & 0 deletions source/textbook/6_venv.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ $ source activate env # 環境の有効化
(env) $ conda install requests # パッケージのインストール
(env) $ source deactivate # 環境の無効化
```

:::

### venv環境の作成
Expand Down
39 changes: 19 additions & 20 deletions source/textbook/7_scraping.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ $ source env/bin/activate

### Requests


* URL: <https://requests.readthedocs.io/>

Requests について簡単に紹介します。
Expand All @@ -68,7 +67,7 @@ Pythonの標準ライブラリ [html.parser](https://docs.python.org/ja/3/librar

Web APIの例として、[SWAPI.INFO](https://swapi.info)の「Star Wars API」で映画『スター・ウォーズ』シリーズに関する情報を入手してみましょう。

- [Star Wars API](https://swapi.info/api/)
* [Star Wars API](https://swapi.info/api/)

下記のコードを `films.py` という名前で、先ほど作成したscrapingフォルダ内に保存します({numref}`films-py`)。

Expand Down Expand Up @@ -99,43 +98,43 @@ Episode 3: Revenge of the Sith (2005-05-19)

上記のコードがどういった内容なのかを解説します。

- Web APIを実行するために `requests` をインポートします
* Web APIを実行するために `requests` をインポートします

```{literalinclude} films.py
:caption: モジュールのインポート
:lines: 1
```

- メインとなる処理を `main` 関数として定義しています。 なお、関数の名前に特に決まりはなく、必ずしも `main` である必要はありません。
* メインとなる処理を `main` 関数として定義しています。 なお、関数の名前に特に決まりはなく、必ずしも `main` である必要はありません。

```{literalinclude} films.py
:caption: main()関数の定義
:lines: 4
```

- APIのエンドポイントとなるURLを設定します。映画以外にも登場人物や乗り物、惑星などの情報を取得できるので、興味がある方はドキュメントを読んで試してみてください。
* APIのエンドポイントとなるURLを設定します。映画以外にも登場人物や乗り物、惑星などの情報を取得できるので、興味がある方はドキュメントを読んで試してみてください。

```{literalinclude} films.py
:caption: APIのエンドポイントURLの設定
:lines: 5
```

- `requests.get()` にURLとパラメーターを指定して結果を取得します。
- 結果はJSON形式で返ってくるので、 `.json()` メソッドでPythonのデータ型(辞書、リスト等)に変換します。
* `requests.get()` にURLとパラメーターを指定して結果を取得します。
* 結果はJSON形式で返ってくるので、 `.json()` メソッドでPythonのデータ型(辞書、リスト等)に変換します。

```{literalinclude} films.py
:caption: Web APIを実行して結果を取得
:lines: 7-8
```

- Pythonデータ型の映画に関する情報から、エピソード番号、タイトル、公開日付を取得して出力します。
* Pythonデータ型の映画に関する情報から、エピソード番号、タイトル、公開日付を取得して出力します。

```{literalinclude} films.py
:caption: エピソード番号、タイトル、公開日付の出力
:lines: 10-19
```

- 最後に、このスクリプトが実行された時に、 `main()` 関数を実行するように指定します。
* 最後に、このスクリプトが実行された時に、 `main()` 関数を実行するように指定します。

```{literalinclude} films.py
:caption: main()関数を実行
Expand Down Expand Up @@ -231,36 +230,36 @@ pycodestyleは `pip install pycodestyle` でインストールして使用しま

上記のコードがどういった内容なのかを解説します。

- 以下のコードはRequestsとBeautiful Soup 4をimportして利用できるようにしています。
* 以下のコードはRequestsとBeautiful Soup 4をimportして利用できるようにしています。

```{literalinclude} funcs.py
:caption: モジュールのimport
:lines: 1-2
```

- メインとなる処理を `main` 関数として定義しています。
* メインとなる処理を `main` 関数として定義しています。
なお、関数の名前に特に決まりはなく、必ずしも `main` である必要はありません。

```{literalinclude} funcs.py
:caption: main()関数の定義
:lines: 5
```

- Requestsを使用して、Webページの内容(HTML)を取得します。res.contentにHTMLの中身が文字列データとして入っています。
* Requestsを使用して、Webページの内容(HTML)を取得します。res.contentにHTMLの中身が文字列データとして入っています。

```{literalinclude} funcs.py
:caption: ページの内容を取得
:lines: 6-8
```

- 次にHTMLをBeautiful Soup 4に渡して解析します。HTMLの解析についてはもう少し詳しく説明します。
* 次にHTMLをBeautiful Soup 4に渡して解析します。HTMLの解析についてはもう少し詳しく説明します。

```{literalinclude} funcs.py
:caption: WebページをBeautiful Soup 4で解析
:lines: 9-20
```

- 最後に、このスクリプトが実行された時に、main()関数を実行するように指定します。
* 最後に、このスクリプトが実行された時に、main()関数を実行するように指定します。

```{literalinclude} funcs.py
:caption: main()関数を実行
Expand Down Expand Up @@ -298,8 +297,8 @@ Beautiful Soup 4でHTMLを解析して、値が取り出せましたが、どの

このHTMLを見ると、関数の名前とURLは以下のようにして取得できそうです。

- テーブル`<table class="docutils">`を見つける
- 見つけたテーブル内の全ての`<a class="reference internal">`要素を見つける
* テーブル`<table class="docutils">`を見つける
* 見つけたテーブル内の全ての`<a class="reference internal">`要素を見つける

HTMLの構造がわかったところで、もう一度HTMLを解析しているコードを見てみます。

Expand Down Expand Up @@ -430,7 +429,7 @@ RequestsとBeautiful Soup 4を使いこなすことにより、さまざまな

Pythonでのスクレイピングについてもいくつか書籍が出ています。

- [PythonによるWebスクレイピング](https://www.oreilly.co.jp/books/9784873117614/)
- [Pythonクローリング&スクレイピング ―データ収集・解析のための実践開発ガイド](https://gihyo.jp/book/2017/978-4-7741-8367-1)
- [Pythonによるスクレイピング&機械学習 開発テクニックBeautifulSoup、scikit-learn、TensorFlowを使ってみよう](https://www.socym.co.jp/book/1079)
- [Pythonエンジニア ファーストブック](https://gihyo.jp/book/2017/978-4-7741-9222-2) (第4章 PythonによるWebスクレイピング)
* [PythonによるWebスクレイピング](https://www.oreilly.co.jp/books/9784873117614/)
* [Pythonクローリング&スクレイピング ―データ収集・解析のための実践開発ガイド](https://gihyo.jp/book/2017/978-4-7741-8367-1)
* [Pythonによるスクレイピング&機械学習 開発テクニックBeautifulSoup、scikit-learn、TensorFlowを使ってみよう](https://www.socym.co.jp/book/1079)
* [Pythonエンジニア ファーストブック](https://gihyo.jp/book/2017/978-4-7741-9222-2) (第4章 PythonによるWebスクレイピング)
4 changes: 2 additions & 2 deletions source/textbook/8_nextstep.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ Pythonやプログラムの学習におすすめの書籍をいくつか紹介
* - ![独学プログラマー](images/book-dokugaku.jpg)
- [独学プログラマー](https://bookplus.nikkei.com/atcl/catalog/18/C92270/)
- Pythonを使って「プログラミング全般」の知識を紹介。
Pythonのインストール方法についてはほとんど触れず、心構えから始まる。
Pythonの文法の他、Git, Bash, 正規表現, データ構造、アルゴリズム、仕事の仕方、といった全般の知識を広く浅く紹介する、独学者のための地図。
Pythonのインストール方法についてはほとんど触れず、心構えから始まる。
Pythonの文法の他、Git, Bash, 正規表現, データ構造、アルゴリズム、仕事の仕方、といった全般の知識を広く浅く紹介する、独学者のための地図。
* - ![Pythonスタートブック[増補改訂版]](images/book-startbook.jpg)
- [Pythonスタートブック[増補改訂版]](https://gihyo.jp/book/2018/978-4-7741-9643-5)
- Python入門を超分かりやすい言葉と絵で丁寧に解説。
Expand Down