Skip to content

setup.pyからpyproject.tomlへ移行し、Python 3.12~3.14とDjango 5.2をサポート#31

Merged
kashewnuts merged 6 commits intomasterfrom
py314
Feb 10, 2026
Merged

setup.pyからpyproject.tomlへ移行し、Python 3.12~3.14とDjango 5.2をサポート#31
kashewnuts merged 6 commits intomasterfrom
py314

Conversation

@kashewnuts
Copy link
Contributor

@kashewnuts kashewnuts commented Feb 6, 2026

何を達成したいのか、なぜその変更をしたか

  • bpcommonsがPython3.12以降に対応していないため、これを期に新しいPythonやDjangoのアプデに追従したい

具体的な変更内容

  • setup.py/setup.cfg/requirements-docs.txtを削除し、pyproject.tomlへ移行
  • tox.iniをpyproject.tomlのlegacy_tox_iniへ移植
  • Python 3.12, 3.13, 3.14サポート追加
  • Django 5.2サポート追加
  • Python 3.8, 3.9サポート終了
  • Django 3.2, 4.1, 5.1サポート終了
  • namespace packageをpkg_resourcesから暗黙的namespace packageに変更
  • CI設定をPython/Djangoの新マトリクスに更新
  • ChangeLog.rst, checklist.rstを更新

実装時に確認したこと

  • toxが通ること
  • python -m build .twine check --strict dist/* が実行できること
    $ twine check --strict dist/*
    Checking dist/beproud_django_commons-0.43-py3-none-any.whl: PASSED
    Checking dist/beproud_django_commons-0.43.tar.gz: PASSED
    
  • pip install -e ".[doc]"docs/ja ディレクトリでの make html の両方が動作すること

特にレビューしてほしいこと

  • PRコメントで記述した変更内容が妥当そうか

- setup.py/setup.cfgを削除し、pyproject.tomlへ移行
- tox.iniをpyproject.tomlのlegacy_tox_iniへ移植
- Python 3.12, 3.13, 3.14サポート追加
- Django 5.2サポート追加
- Python 3.8, 3.9サポート終了
- Django 3.2, 4.1, 5.1サポート終了
- namespace packageをpkg_resourcesから暗黙的namespace packageに変更
- CI設定をPython/Djangoの新マトリクスに更新
- factory-boyのDeprecationWarning対応(skip_postgeneration_save)
- テストのassertEqualsをassertEqualに修正
- ChangeLog.rst, checklist.rstを更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
django-version: ['3.2', '4.1', '4.2']
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: Django4.2と5.2の対応状況からバージョン情報を更新

path: ${{ steps.pip-cache.outputs.dir }}
key:
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }}
${{ matrix.python-version }}-v1-${{ hashFiles('**/pyproject.toml') }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: pyproject.tomlに統合したので記述更新


steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: actionsのバージョンが古くなっていたので諸々更新


def assertStatus(self, response, status=200):
self.assertEquals(response.status_code, status)
self.assertEqual(response.status_code, status)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: Python3.12でのRemove many long-deprecated unittest features: のため諸々テストメソッドを修正
https://docs.python.org/3/whatsnew/3.12.html#id3

id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: どちらも steps.pip-cache.outputs.dir に pip のキャッシュディレクトリパスをセットする処理ですが、::set-output コマンドは 2022年10月にセキュリティ上の理由で非推奨になり、その後廃止されました。代わりに $GITHUB_OUTPUTを利用しています。
ref: https://github.blog/changelog/2022-10-10-github-actions-deprecating-save-state-and-set-output-commands/


* ``ChangeLog.rst`` next version
* ``bpcommons/beproud/django/commons/__init__.py`` next version
* ``beproud/django/commons/__init__.py`` next version
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: パスの情報が古かったので更新


1. check CI status testing result: https://github.com/beproud/bpcommons/actions
2. update release version/date in ``ChangeLog.rst``
3. run ``python setup.py release sdist bdist_wheel``
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: setup.pyは削除されたのでpyprojet.tomlバージョンに移行

@@ -0,0 +1,70 @@
[build-system]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setup.py/tox.iniにあったものをpyprojet.tomlに統合
ref: https://packaging.python.org/ja/latest/guides/writing-pyproject-toml/

@@ -1,7 +0,0 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MEMO: これは beproud.django.commons のようなドット区切りのパッケージを、複数の配布パッケージに分割するための旧式の仕組みです。setup.py の namespace_packages=['beproud', 'beproud.django'] とセットで機能していました。

pyproject.toml への移行にあたり、PEP 420 の暗黙的 namespace package 方式に切り替えました。この方式では:

  • __init__.py に宣言コードが不要(空でよい)
  • setup.py の namespace_packages 指定も不要
  • pkg_resources への依存がなくなる

pkg_resources 方式は現在非推奨で、起動時のインポートが遅い問題もあります。空の __init__.py を残しているのは、beproud/django/commons/init.pyを通常パッケージとして正しく動作させるためです。

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO: 空の init.py が残っていると、暗黙的名前空間パッケージにならないと思います。また、他 beproud 名前空間ライブラリも同時に修正しないと、インストール順序によっては競合が発生してしまうと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ae35bp 8bab1b4 でnamespace packageを暗黙的方式(PEP 420)に変更しました。合わせてbpnotifyも対応が必要なので beproud/bpnotify#18 で対応しています。

@@ -1,7 +0,0 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
Copy link
Contributor Author

Choose a reason for hiding this comment

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

同上

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO: 同上

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the project's packaging configuration from setup.py/setup.cfg to the modern pyproject.toml format, while also updating supported Python and Django versions. The migration aims to modernize the project infrastructure and expand version support.

Changes:

  • Migrated packaging configuration from setup.py/setup.cfg to pyproject.toml with embedded tox configuration
  • Updated version support to add Python 3.12, 3.13, 3.14 and Django 5.2 while dropping Python 3.8, 3.9 and Django 3.2, 4.1, 5.1
  • Converted from pkg_resources namespace packages to implicit PEP 420 namespace packages
  • Updated CI/CD configuration with new Python/Django test matrix and newer GitHub Actions versions
  • Fixed deprecated assertEquals method calls to assertEqual
  • Added skip_postgeneration_save configuration to factory-boy factories with ManyToMany fields
  • Updated documentation (README, ChangeLog, checklist) to reflect version changes and new build process

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
pyproject.toml New packaging configuration with project metadata, dependencies, and embedded tox configuration for Python 3.10-3.14 and Django 4.2/5.2
setup.py Removed old setup.py packaging file
setup.cfg Removed old setup.cfg configuration file
tox.ini Removed standalone tox configuration (migrated to pyproject.toml)
beproud/init.py Converted to empty file for implicit namespace package support
beproud/django/init.py Converted to empty file for implicit namespace package support
beproud/django/commons/test/simple.py Fixed deprecated assertEquals calls to use assertEqual
tests/test_models_fields.py Added skip_postgeneration_save to factory for compatibility with newer factory-boy
.github/workflows/ci.yml Updated CI matrix for new Python/Django versions and updated action versions
README.rst Updated supported Python and Django version documentation
ChangeLog.rst Added release notes for version 0.43 changes
checklist.rst Updated release procedure for pyproject.toml-based builds

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [
"Django>=4.2", "six",
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The "six" library is a Python 2/3 compatibility library that is largely unnecessary for projects supporting only Python 3.10+. Since this project drops Python 3.8 and 3.9 support and requires Python 3.10+, consider removing the dependency on "six" and updating the code to use native Python 3 features instead (e.g., replace 'six.text_type' with 'str', 'six.string_types' with 'str', 'six.iteritems()' with '.items()', and 'six.with_metaclass()' with direct class inheritance using 'class Name(Base, metaclass=MetaClass)'). This would modernize the codebase and remove an unnecessary dependency.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

指摘のとおりではあるが、現在このbpcommonsを利用してるプロジェクトの依存(ex: python-dateutil)でもsixが残っておりモチベーションが薄いのと、他の変更も多いので対応しない。

@kashewnuts kashewnuts marked this pull request as ready for review February 6, 2026 06:41
@kashewnuts kashewnuts marked this pull request as draft February 6, 2026 06:42
- バージョンを__init__.pyから動的取得に変更(single source of truth)
- requires-python >= 3.10 を追加
- license = BSD を追加
- zip-safe = false を追加(setup.pyからの移行漏れ)
- packages.findにnamespaces/includeを明示
- checklist.rstからpyproject.tomlのバージョン更新手順を削除

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pip install -e ".[doc]" でSphinxドキュメントビルド環境を構築可能にした。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
]

[project.optional-dependencies]
doc = ["sphinx"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

requirements-docs.txtから移植しました。

Copy link
Member

Choose a reason for hiding this comment

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

MAY: 別途、readthedocsの方も対応しないといけなそうですね

この変更でRTDのビルドは影響を受けるだろうか、と確認したら、だいぶ前からビルドが失敗していたようです。
https://app.readthedocs.org/projects/bpcommons/

優先度は高くないと思うので、別途対応でよさそうです。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ひとまずIssuesだけ作成しました #32

@kashewnuts kashewnuts marked this pull request as ready for review February 6, 2026 07:32
Python 3.12以降で発生するSyntaxWarningを解消。
- IP_ADDRESS_REをraw stringに変更
- docstring内の\sを\\sにエスケープ

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

# See: http://www.regular-expressions.info/regexbuddy/ipaccurate.html
IP_ADDRESS_RE = '(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
IP_ADDRESS_RE = r'(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Python 3.12以降で発生するSyntaxWarningを解消しました

Copy link
Contributor

@ae35bp ae35bp left a comment

Choose a reason for hiding this comment

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

IMOかえしますー

@@ -1,7 +0,0 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO: 空の init.py が残っていると、暗黙的名前空間パッケージにならないと思います。また、他 beproud 名前空間ライブラリも同時に修正しないと、インストール順序によっては競合が発生してしまうと思います。

@@ -1,7 +0,0 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO: 同上

pyproject.toml Outdated

[tool.setuptools.packages.find]
where = ["."]
namespaces = false
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO: namespaces = false だと、init.py を残さなければ名前空間パッケージとして認識されなくなるため、暗黙的名前空間パッケージ対応と相反してしまっていると思います

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ae35bp 8bab1b4 でnamespace packageを暗黙的方式(PEP 420)に変更しました。合わせてbpnotifyも対応が必要なので beproud/bpnotify#18 で対応しています。

kashewnuts and others added 2 commits February 9, 2026 15:19
pkg_resourcesはsetuptools>=81で削除されたため、
pkgutil.extend_pathのみでnamespace packageを実現する。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bpnotifyとの共存時にファイル競合が構造的に発生しない暗黙的namespace
package方式に変更。beproud/__init__.pyとbeproud/django/__init__.pyを
削除し、pyproject.tomlのincludeをbeproud.django.commons*に限定。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@shimizukawa shimizukawa left a comment

Choose a reason for hiding this comment

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

LGTM!
メンテありがとうございます。

名前空間パッケージについてのコメントが進行中ですが、他のパッケージも合わせる方向で進んでいるようなので、私からはApproveとしておきます。

1点、RTDについてコメントしましたが、このPRとは別で良いと思います。

]

[project.optional-dependencies]
doc = ["sphinx"]
Copy link
Member

Choose a reason for hiding this comment

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

MAY: 別途、readthedocsの方も対応しないといけなそうですね

この変更でRTDのビルドは影響を受けるだろうか、と確認したら、だいぶ前からビルドが失敗していたようです。
https://app.readthedocs.org/projects/bpcommons/

優先度は高くないと思うので、別途対応でよさそうです。

Copy link
Contributor

@ae35bp ae35bp left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@kashewnuts kashewnuts merged commit d85bd7d into master Feb 10, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants