pypi-sdk-space 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pypi_sdk_space-0.1.0/.gitignore +13 -0
- pypi_sdk_space-0.1.0/LICENSE +201 -0
- pypi_sdk_space-0.1.0/PKG-INFO +93 -0
- pypi_sdk_space-0.1.0/README.md +59 -0
- pypi_sdk_space-0.1.0/config/monitor.yaml +12 -0
- pypi_sdk_space-0.1.0/pyproject.toml +68 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/__init__.py +4 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/cli.py +187 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/config.py +50 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/monitor.py +145 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/project.py +84 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/pypi_client.py +53 -0
- pypi_sdk_space-0.1.0/src/pypi_sdk_space/slack.py +77 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pypi-sdk-space
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: CLI and automation for pypi-sdk.space — build, publish, monitor, and Slack updates.
|
|
5
|
+
Project-URL: Homepage, https://github.com/thanabartbb/pypi-sdk.space
|
|
6
|
+
Project-URL: Repository, https://github.com/thanabartbb/pypi-sdk.space
|
|
7
|
+
Project-URL: Documentation, https://github.com/thanabartbb/pypi-sdk.space#readme
|
|
8
|
+
Project-URL: Publishing, https://pypi.org/manage/account/publishing/
|
|
9
|
+
Author: thanabartbb
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: monitoring,packaging,pypi,slack
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Requires-Dist: rich>=13.7
|
|
26
|
+
Requires-Dist: tomli>=2.0; python_version < '3.11'
|
|
27
|
+
Requires-Dist: typer>=0.12
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
32
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# pypi-sdk.space
|
|
36
|
+
|
|
37
|
+
เครื่องมือ CLI และ automation สำหรับ repo **[thanabartbb/pypi-sdk.space](https://github.com/thanabartbb/pypi-sdk.space)** — build, ตรวจสุขภาพก่อน publish ไป PyPI, ติดตามการเปลี่ยนแปลง และแจ้ง Slack
|
|
38
|
+
|
|
39
|
+
ลิงก์สำคัญสำหรับบัญชี PyPI ของคุณ (Trusted publishing /):
|
|
40
|
+
|
|
41
|
+
**https://pypi-sdk.space/**
|
|
42
|
+
|
|
43
|
+
## ติดตั้ง
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
make dev
|
|
47
|
+
pypi-space doctor
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## คำสั่งพื้นฐาน (CLI)
|
|
51
|
+
|
|
52
|
+
| คำสั่ง | ใช้เมื่อ |
|
|
53
|
+
|--------|----------|
|
|
54
|
+
| `pypi-space doctor` | ตรวจ Python, twine, webhook, config |
|
|
55
|
+
| `pypi-space version show` | ดูเวอร์ชันใน `pyproject.toml` |
|
|
56
|
+
| `pypi-space version bump patch --write` | bump semver แล้วเขียนไฟล์ |
|
|
57
|
+
| `pypi-space build` | สร้าง wheel + sdist ใน `dist/` |
|
|
58
|
+
| `pypi-space check-dist` | `twine check` บน artifact |
|
|
59
|
+
| `pypi-space pypi info <name>` | อ่านเวอร์ชันล่าสุดจาก PyPI |
|
|
60
|
+
| `pypi-space publishing` | checklist + ลิงก์ publishing errors |
|
|
61
|
+
| `pypi-space monitor run --json` | สแกนการเปลี่ยนแปลง (local vs PyPI) |
|
|
62
|
+
| `pypi-space monitor slack` | ส่งสรุปไป Slack ผ่าน `SLACK_WEBHOOK_URL` |
|
|
63
|
+
|
|
64
|
+
Makefile shortcuts: `make test`, `make monitor`, `make monitor-slack`
|
|
65
|
+
|
|
66
|
+
## Cursor commands (ใน IDE)
|
|
67
|
+
|
|
68
|
+
พิมพ์ `/` แล้วเลือก:
|
|
69
|
+
|
|
70
|
+
- `/pypi-status` — สรุปสุขภาพ repo + PyPI
|
|
71
|
+
- `/pypi-publish-check` — เช็คก่อน release / publish
|
|
72
|
+
- `/pypi-slack-update` — รัน monitor แล้วโพสต์ Slack (MCP)
|
|
73
|
+
- `/pypi-watch` — ตั้ง timer ให้ agent ติดตามและแจ้งเป็นระยะ
|
|
74
|
+
|
|
75
|
+
## Slack & GitHub Actions
|
|
76
|
+
|
|
77
|
+
1. สร้าง **Incoming Webhook** ใน Slack workspace
|
|
78
|
+
2. ใส่ secret ใน GitHub repo: `SLACK_WEBHOOK_URL`
|
|
79
|
+
3. Workflow `monitor-and-notify.yml` จะรันตาม schedule และเมื่อ push ที่ `main`
|
|
80
|
+
|
|
81
|
+
Channel เริ่มต้นใน `config/monitor.yaml` ชี้ไป `#general` — แก้ `slack.channel_id` ได้
|
|
82
|
+
|
|
83
|
+
## Publish ไป PyPI
|
|
84
|
+
|
|
85
|
+
ใช้ [Trusted publishing](https://docs.pypi.org/trusted-publishers/) จาก GitHub Actions (`publish.yml`) หลัง tag release
|
|
86
|
+
|
|
87
|
+
หาก publish ล้มเหลว เปิดหน้า errors ของบัญชี PyPI:
|
|
88
|
+
|
|
89
|
+
https://pypi.org/manage/account/publishing/#errors
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# pypi-sdk.space
|
|
2
|
+
|
|
3
|
+
เครื่องมือ CLI และ automation สำหรับ repo **[thanabartbb/pypi-sdk.space](https://github.com/thanabartbb/pypi-sdk.space)** — build, ตรวจสุขภาพก่อน publish ไป PyPI, ติดตามการเปลี่ยนแปลง และแจ้ง Slack
|
|
4
|
+
|
|
5
|
+
ลิงก์สำคัญสำหรับบัญชี PyPI ของคุณ (Trusted publishing /):
|
|
6
|
+
|
|
7
|
+
**https://pypi-sdk.space/**
|
|
8
|
+
|
|
9
|
+
## ติดตั้ง
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
make dev
|
|
13
|
+
pypi-space doctor
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## คำสั่งพื้นฐาน (CLI)
|
|
17
|
+
|
|
18
|
+
| คำสั่ง | ใช้เมื่อ |
|
|
19
|
+
|--------|----------|
|
|
20
|
+
| `pypi-space doctor` | ตรวจ Python, twine, webhook, config |
|
|
21
|
+
| `pypi-space version show` | ดูเวอร์ชันใน `pyproject.toml` |
|
|
22
|
+
| `pypi-space version bump patch --write` | bump semver แล้วเขียนไฟล์ |
|
|
23
|
+
| `pypi-space build` | สร้าง wheel + sdist ใน `dist/` |
|
|
24
|
+
| `pypi-space check-dist` | `twine check` บน artifact |
|
|
25
|
+
| `pypi-space pypi info <name>` | อ่านเวอร์ชันล่าสุดจาก PyPI |
|
|
26
|
+
| `pypi-space publishing` | checklist + ลิงก์ publishing errors |
|
|
27
|
+
| `pypi-space monitor run --json` | สแกนการเปลี่ยนแปลง (local vs PyPI) |
|
|
28
|
+
| `pypi-space monitor slack` | ส่งสรุปไป Slack ผ่าน `SLACK_WEBHOOK_URL` |
|
|
29
|
+
|
|
30
|
+
Makefile shortcuts: `make test`, `make monitor`, `make monitor-slack`
|
|
31
|
+
|
|
32
|
+
## Cursor commands (ใน IDE)
|
|
33
|
+
|
|
34
|
+
พิมพ์ `/` แล้วเลือก:
|
|
35
|
+
|
|
36
|
+
- `/pypi-status` — สรุปสุขภาพ repo + PyPI
|
|
37
|
+
- `/pypi-publish-check` — เช็คก่อน release / publish
|
|
38
|
+
- `/pypi-slack-update` — รัน monitor แล้วโพสต์ Slack (MCP)
|
|
39
|
+
- `/pypi-watch` — ตั้ง timer ให้ agent ติดตามและแจ้งเป็นระยะ
|
|
40
|
+
|
|
41
|
+
## Slack & GitHub Actions
|
|
42
|
+
|
|
43
|
+
1. สร้าง **Incoming Webhook** ใน Slack workspace
|
|
44
|
+
2. ใส่ secret ใน GitHub repo: `SLACK_WEBHOOK_URL`
|
|
45
|
+
3. Workflow `monitor-and-notify.yml` จะรันตาม schedule และเมื่อ push ที่ `main`
|
|
46
|
+
|
|
47
|
+
Channel เริ่มต้นใน `config/monitor.yaml` ชี้ไป `#general` — แก้ `slack.channel_id` ได้
|
|
48
|
+
|
|
49
|
+
## Publish ไป PyPI
|
|
50
|
+
|
|
51
|
+
ใช้ [Trusted publishing](https://docs.pypi.org/trusted-publishers/) จาก GitHub Actions (`publish.yml`) หลัง tag release
|
|
52
|
+
|
|
53
|
+
หาก publish ล้มเหลว เปิดหน้า errors ของบัญชี PyPI:
|
|
54
|
+
|
|
55
|
+
https://pypi.org/manage/account/publishing/#errors
|
|
56
|
+
|
|
57
|
+
## License
|
|
58
|
+
|
|
59
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Monitor + Slack settings for thanabartbb/pypi-sdk.space
|
|
2
|
+
repo: thanabartbb/pypi-sdk.space
|
|
3
|
+
pypi_package: pypi-sdk-space
|
|
4
|
+
github_default_branch: main
|
|
5
|
+
state_file: .pypi-monitor/state.json
|
|
6
|
+
pypi_publishing_errors_url: https://pypi.org/manage/account/publishing/#errors
|
|
7
|
+
|
|
8
|
+
slack:
|
|
9
|
+
# Incoming webhook: set SLACK_WEBHOOK_URL in GitHub Actions / local env.
|
|
10
|
+
# Cursor agent commands can also post via Slack MCP to this channel:
|
|
11
|
+
channel_id: C0BKYMAQHN1
|
|
12
|
+
channel_name: "#general"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pypi-sdk-space"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "CLI and automation for pypi-sdk.space — build, publish, monitor, and Slack updates."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "Apache-2.0" }
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [{ name = "thanabartbb" }]
|
|
13
|
+
keywords = ["pypi", "packaging", "slack", "monitoring"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: Apache Software License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Software Development :: Build Tools",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.27",
|
|
27
|
+
"pyyaml>=6.0",
|
|
28
|
+
"rich>=13.7",
|
|
29
|
+
"tomli>=2.0; python_version < '3.11'",
|
|
30
|
+
"typer>=0.12",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"build>=1.2",
|
|
36
|
+
"pytest>=8.0",
|
|
37
|
+
"ruff>=0.6",
|
|
38
|
+
"twine>=5.0",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
pypi-space = "pypi_sdk_space.cli:app"
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
Homepage = "https://github.com/thanabartbb/pypi-sdk.space"
|
|
46
|
+
Repository = "https://github.com/thanabartbb/pypi-sdk.space"
|
|
47
|
+
Documentation = "https://github.com/thanabartbb/pypi-sdk.space#readme"
|
|
48
|
+
Publishing = "https://pypi.org/manage/account/publishing/"
|
|
49
|
+
|
|
50
|
+
[tool.hatch.build.targets.wheel]
|
|
51
|
+
packages = ["src/pypi_sdk_space"]
|
|
52
|
+
|
|
53
|
+
[tool.hatch.build.targets.wheel.sources]
|
|
54
|
+
"src" = ""
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.sdist]
|
|
57
|
+
include = ["/src", "/config", "/README.md", "/LICENSE"]
|
|
58
|
+
|
|
59
|
+
[tool.ruff]
|
|
60
|
+
line-length = 100
|
|
61
|
+
target-version = "py311"
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
select = ["E", "F", "I", "UP"]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
testpaths = ["tests"]
|
|
68
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import shutil
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from enum import StrEnum
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Annotated
|
|
10
|
+
|
|
11
|
+
import typer
|
|
12
|
+
from rich.console import Console
|
|
13
|
+
from rich.table import Table
|
|
14
|
+
|
|
15
|
+
from pypi_sdk_space import PYPI_PUBLISHING_ERRORS_URL, __version__
|
|
16
|
+
from pypi_sdk_space.config import load_monitor_config
|
|
17
|
+
from pypi_sdk_space.monitor import run_monitor
|
|
18
|
+
from pypi_sdk_space.project import bump_version, load_project_meta, write_project_version
|
|
19
|
+
from pypi_sdk_space.pypi_client import fetch_release_info
|
|
20
|
+
from pypi_sdk_space.slack import format_update_message, post_webhook, slack_webhook_configured
|
|
21
|
+
|
|
22
|
+
app = typer.Typer(
|
|
23
|
+
no_args_is_help=True,
|
|
24
|
+
help="PyPI + repo tooling for pypi-sdk.space (build, publish, monitor, Slack).",
|
|
25
|
+
)
|
|
26
|
+
console = Console()
|
|
27
|
+
version_app = typer.Typer(help="Show or bump the project version in pyproject.toml.")
|
|
28
|
+
pypi_app = typer.Typer(help="Read package metadata from PyPI.")
|
|
29
|
+
monitor_app = typer.Typer(help="Detect changes and notify Slack.")
|
|
30
|
+
app.add_typer(version_app, name="version")
|
|
31
|
+
app.add_typer(pypi_app, name="pypi")
|
|
32
|
+
app.add_typer(monitor_app, name="monitor")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class BumpPart(StrEnum):
|
|
36
|
+
patch = "patch"
|
|
37
|
+
minor = "minor"
|
|
38
|
+
major = "major"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@app.callback()
|
|
42
|
+
def main() -> None:
|
|
43
|
+
"""pypi-space CLI entrypoint."""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@app.command("doctor")
|
|
47
|
+
def doctor_cmd() -> None:
|
|
48
|
+
"""Check local tools and configuration for publishing and monitoring."""
|
|
49
|
+
table = Table(title="pypi-space doctor")
|
|
50
|
+
table.add_column("Check")
|
|
51
|
+
table.add_column("Status")
|
|
52
|
+
|
|
53
|
+
def row(name: str, ok: bool, detail: str = "") -> None:
|
|
54
|
+
if ok:
|
|
55
|
+
status = f"[green]OK[/green] {detail}".strip()
|
|
56
|
+
else:
|
|
57
|
+
status = f"[red]MISSING[/red] {detail}".strip()
|
|
58
|
+
table.add_row(name, status)
|
|
59
|
+
|
|
60
|
+
row("python", True, sys.version.split()[0])
|
|
61
|
+
row("git", shutil.which("git") is not None)
|
|
62
|
+
row("build", shutil.which("python") is not None, "(module: python -m build)")
|
|
63
|
+
row("twine", shutil.which("twine") is not None)
|
|
64
|
+
row("SLACK_WEBHOOK_URL", slack_webhook_configured())
|
|
65
|
+
row("config/monitor.yaml", Path("config/monitor.yaml").is_file())
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
meta = load_project_meta()
|
|
69
|
+
row("pyproject.toml", True, f"{meta.name} @ {meta.version}")
|
|
70
|
+
except Exception as exc: # noqa: BLE001
|
|
71
|
+
row("pyproject.toml", False, str(exc))
|
|
72
|
+
|
|
73
|
+
cfg = load_monitor_config()
|
|
74
|
+
table.add_row("repo", cfg.repo)
|
|
75
|
+
table.add_row("PyPI errors URL", cfg.pypi_publishing_errors_url)
|
|
76
|
+
console.print(table)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@version_app.command("show")
|
|
80
|
+
def version_show() -> None:
|
|
81
|
+
meta = load_project_meta()
|
|
82
|
+
console.print(f"{meta.name} {meta.version}")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@version_app.command("bump")
|
|
86
|
+
def version_bump(
|
|
87
|
+
part: Annotated[BumpPart, typer.Argument(help="Semver part to increment.")],
|
|
88
|
+
write: Annotated[
|
|
89
|
+
bool, typer.Option("--write/--dry-run", help="Update pyproject.toml.")
|
|
90
|
+
] = False,
|
|
91
|
+
) -> None:
|
|
92
|
+
meta = load_project_meta()
|
|
93
|
+
new_version = bump_version(meta.version, part.value)
|
|
94
|
+
if write:
|
|
95
|
+
write_project_version(meta.pyproject_path, new_version)
|
|
96
|
+
console.print(
|
|
97
|
+
f"Bumped {meta.version} → [bold]{new_version}[/bold] in {meta.pyproject_path}"
|
|
98
|
+
)
|
|
99
|
+
else:
|
|
100
|
+
console.print(
|
|
101
|
+
f"Would bump {meta.version} → [bold]{new_version}[/bold] (pass --write to apply)"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@pypi_app.command("info")
|
|
106
|
+
def pypi_info(name: Annotated[str, typer.Argument(help="PyPI project name.")]) -> None:
|
|
107
|
+
info = fetch_release_info(name)
|
|
108
|
+
if not info.exists:
|
|
109
|
+
console.print(f"[yellow]{name}[/yellow] is not on PyPI yet.")
|
|
110
|
+
raise typer.Exit(code=1)
|
|
111
|
+
console.print(f"{info.name} latest: [bold]{info.latest_version}[/bold]")
|
|
112
|
+
if info.uploaded_at:
|
|
113
|
+
console.print(f"Uploaded: {info.uploaded_at}")
|
|
114
|
+
console.print(f"URL: {info.project_url}")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@app.command("build")
|
|
118
|
+
def build_cmd(
|
|
119
|
+
outdir: Annotated[str, typer.Option("--outdir", "-o")] = "dist",
|
|
120
|
+
) -> None:
|
|
121
|
+
"""Build wheel and sdist via python -m build."""
|
|
122
|
+
Path(outdir).mkdir(parents=True, exist_ok=True)
|
|
123
|
+
subprocess.run([sys.executable, "-m", "build", "--outdir", outdir], check=True)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
@app.command("check-dist")
|
|
127
|
+
def check_dist_cmd(dist_dir: Annotated[str, typer.Argument()] = "dist") -> None:
|
|
128
|
+
"""Run twine check on built artifacts."""
|
|
129
|
+
subprocess.run(["twine", "check", f"{dist_dir}/*"], check=True)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@app.command("publishing")
|
|
133
|
+
def publishing_cmd() -> None:
|
|
134
|
+
"""Print trusted publishing checklist and the PyPI errors dashboard link."""
|
|
135
|
+
cfg = load_monitor_config()
|
|
136
|
+
meta = load_project_meta()
|
|
137
|
+
console.print("[bold]Trusted publishing checklist[/bold]")
|
|
138
|
+
console.print(f"1. GitHub repo: https://github.com/{cfg.repo}")
|
|
139
|
+
console.print("2. Configure trusted publisher on PyPI for this repo + workflow.")
|
|
140
|
+
console.print("3. GitHub secret: SLACK_WEBHOOK_URL (for monitor notifications).")
|
|
141
|
+
console.print(f"4. Package name on PyPI: [cyan]{meta.name}[/cyan]")
|
|
142
|
+
console.print(f"5. Publishing errors dashboard: {cfg.pypi_publishing_errors_url}")
|
|
143
|
+
console.print(f" (same as {PYPI_PUBLISHING_ERRORS_URL})")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@monitor_app.command("run")
|
|
147
|
+
def monitor_run_cmd(
|
|
148
|
+
json_out: Annotated[bool, typer.Option("--json", help="Print JSON report.")] = False,
|
|
149
|
+
force: Annotated[bool, typer.Option("--force", help="Mark report as notify-worthy.")] = False,
|
|
150
|
+
no_state: Annotated[bool, typer.Option("--no-state", help="Do not write state file.")] = False,
|
|
151
|
+
) -> None:
|
|
152
|
+
report = run_monitor(persist_state=not no_state, force_notify=force)
|
|
153
|
+
if json_out:
|
|
154
|
+
console.print_json(json.dumps(report))
|
|
155
|
+
else:
|
|
156
|
+
console.print(format_update_message(report))
|
|
157
|
+
if report.get("should_notify"):
|
|
158
|
+
console.print("[yellow]Material changes detected (see changes in report).[/yellow]")
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@monitor_app.command("slack")
|
|
162
|
+
def monitor_slack_cmd(
|
|
163
|
+
force: Annotated[
|
|
164
|
+
bool, typer.Option("--force", help="Send even if no material change.")
|
|
165
|
+
] = False,
|
|
166
|
+
dry_run: Annotated[bool, typer.Option("--dry-run", help="Print message only.")] = False,
|
|
167
|
+
) -> None:
|
|
168
|
+
report = run_monitor(persist_state=True, force_notify=force)
|
|
169
|
+
message = format_update_message(report)
|
|
170
|
+
if dry_run:
|
|
171
|
+
console.print(message)
|
|
172
|
+
return
|
|
173
|
+
if not report.get("should_notify") and not force:
|
|
174
|
+
console.print("[dim]No material changes; use --force to send anyway.[/dim]")
|
|
175
|
+
raise typer.Exit(code=0)
|
|
176
|
+
post_webhook(text=message)
|
|
177
|
+
console.print("[green]Sent Slack webhook notification.[/green]")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
@app.command("version-cli")
|
|
181
|
+
def version_cli_cmd() -> None:
|
|
182
|
+
"""Print CLI version."""
|
|
183
|
+
console.print(__version__)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
if __name__ == "__main__":
|
|
187
|
+
app()
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from pypi_sdk_space import DEFAULT_REPO, PYPI_PUBLISHING_ERRORS_URL
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class MonitorConfig:
|
|
14
|
+
repo: str
|
|
15
|
+
pypi_package: str
|
|
16
|
+
state_file: Path
|
|
17
|
+
slack_channel_id: str | None
|
|
18
|
+
pypi_publishing_errors_url: str
|
|
19
|
+
github_default_branch: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def default_config_path() -> Path:
|
|
23
|
+
return Path("config/monitor.yaml")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def load_monitor_config(path: Path | None = None) -> MonitorConfig:
|
|
27
|
+
cfg_path = path or default_config_path()
|
|
28
|
+
if not cfg_path.is_file():
|
|
29
|
+
return MonitorConfig(
|
|
30
|
+
repo=DEFAULT_REPO,
|
|
31
|
+
pypi_package="pypi-sdk-space",
|
|
32
|
+
state_file=Path(".pypi-monitor/state.json"),
|
|
33
|
+
slack_channel_id=None,
|
|
34
|
+
pypi_publishing_errors_url=PYPI_PUBLISHING_ERRORS_URL,
|
|
35
|
+
github_default_branch="main",
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
raw: dict[str, Any] = yaml.safe_load(cfg_path.read_text(encoding="utf-8")) or {}
|
|
39
|
+
slack = raw.get("slack") or {}
|
|
40
|
+
channel_id = slack.get("channel_id")
|
|
41
|
+
return MonitorConfig(
|
|
42
|
+
repo=str(raw.get("repo") or DEFAULT_REPO),
|
|
43
|
+
pypi_package=str(raw.get("pypi_package") or "pypi-sdk-space"),
|
|
44
|
+
state_file=Path(str(raw.get("state_file") or ".pypi-monitor/state.json")),
|
|
45
|
+
slack_channel_id=str(channel_id) if channel_id else None,
|
|
46
|
+
pypi_publishing_errors_url=str(
|
|
47
|
+
raw.get("pypi_publishing_errors_url") or PYPI_PUBLISHING_ERRORS_URL
|
|
48
|
+
),
|
|
49
|
+
github_default_branch=str(raw.get("github_default_branch") or "main"),
|
|
50
|
+
)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
from dataclasses import asdict, dataclass
|
|
6
|
+
from datetime import UTC, datetime
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from pypi_sdk_space.config import MonitorConfig, load_monitor_config
|
|
11
|
+
from pypi_sdk_space.project import load_project_meta
|
|
12
|
+
from pypi_sdk_space.pypi_client import fetch_release_info
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class MonitorState:
|
|
17
|
+
local_version: str | None = None
|
|
18
|
+
pypi_version: str | None = None
|
|
19
|
+
pypi_uploaded_at: str | None = None
|
|
20
|
+
last_notified_at: str | None = None
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _now_iso() -> str:
|
|
24
|
+
return datetime.now(tz=UTC).replace(microsecond=0).isoformat()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def load_state(path: Path) -> MonitorState:
|
|
28
|
+
if not path.is_file():
|
|
29
|
+
return MonitorState()
|
|
30
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
31
|
+
return MonitorState(
|
|
32
|
+
local_version=data.get("local_version"),
|
|
33
|
+
pypi_version=data.get("pypi_version"),
|
|
34
|
+
pypi_uploaded_at=data.get("pypi_uploaded_at"),
|
|
35
|
+
last_notified_at=data.get("last_notified_at"),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def save_state(path: Path, state: MonitorState) -> None:
|
|
40
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
41
|
+
path.write_text(json.dumps(asdict(state), indent=2) + "\n", encoding="utf-8")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def git_head_sha() -> str | None:
|
|
45
|
+
try:
|
|
46
|
+
result = subprocess.run(
|
|
47
|
+
["git", "rev-parse", "HEAD"],
|
|
48
|
+
check=True,
|
|
49
|
+
capture_output=True,
|
|
50
|
+
text=True,
|
|
51
|
+
)
|
|
52
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
53
|
+
return None
|
|
54
|
+
return result.stdout.strip() or None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def git_latest_tag() -> str | None:
|
|
58
|
+
try:
|
|
59
|
+
result = subprocess.run(
|
|
60
|
+
["git", "describe", "--tags", "--abbrev=0"],
|
|
61
|
+
check=True,
|
|
62
|
+
capture_output=True,
|
|
63
|
+
text=True,
|
|
64
|
+
)
|
|
65
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
66
|
+
return None
|
|
67
|
+
return result.stdout.strip() or None
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def run_monitor(
|
|
71
|
+
*,
|
|
72
|
+
config: MonitorConfig | None = None,
|
|
73
|
+
persist_state: bool = True,
|
|
74
|
+
force_notify: bool = False,
|
|
75
|
+
) -> dict[str, Any]:
|
|
76
|
+
cfg = config or load_monitor_config()
|
|
77
|
+
meta = load_project_meta()
|
|
78
|
+
release = fetch_release_info(cfg.pypi_package)
|
|
79
|
+
previous = load_state(cfg.state_file)
|
|
80
|
+
|
|
81
|
+
changes: list[str] = []
|
|
82
|
+
if previous.local_version and previous.local_version != meta.version:
|
|
83
|
+
changes.append(f"Local version changed: {previous.local_version} → {meta.version}")
|
|
84
|
+
if previous.pypi_version != release.latest_version:
|
|
85
|
+
prev = previous.pypi_version or "(none)"
|
|
86
|
+
curr = release.latest_version or "(none)"
|
|
87
|
+
changes.append(f"PyPI latest version changed: {prev} → {curr}")
|
|
88
|
+
if previous.pypi_uploaded_at != release.uploaded_at and release.uploaded_at:
|
|
89
|
+
changes.append(f"PyPI upload timestamp updated: {release.uploaded_at}")
|
|
90
|
+
|
|
91
|
+
publish_gap = meta.version != (release.latest_version or "")
|
|
92
|
+
if publish_gap and release.exists:
|
|
93
|
+
changes.append(
|
|
94
|
+
f"Local {meta.version} is ahead of PyPI {release.latest_version} — publish when ready"
|
|
95
|
+
)
|
|
96
|
+
if not release.exists:
|
|
97
|
+
changes.append("Package not found on PyPI yet — first publish pending")
|
|
98
|
+
|
|
99
|
+
head = git_head_sha()
|
|
100
|
+
tag = git_latest_tag()
|
|
101
|
+
|
|
102
|
+
is_baseline = previous.local_version is None and previous.pypi_version is None
|
|
103
|
+
material_change = (
|
|
104
|
+
not is_baseline
|
|
105
|
+
and (
|
|
106
|
+
previous.pypi_version != release.latest_version
|
|
107
|
+
or previous.local_version != meta.version
|
|
108
|
+
or previous.pypi_uploaded_at != release.uploaded_at
|
|
109
|
+
or (not release.exists and previous.pypi_version is not None)
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
should_notify = force_notify or material_change
|
|
113
|
+
|
|
114
|
+
report: dict[str, Any] = {
|
|
115
|
+
"checked_at": _now_iso(),
|
|
116
|
+
"repo": cfg.repo,
|
|
117
|
+
"package": cfg.pypi_package,
|
|
118
|
+
"local_version": meta.version,
|
|
119
|
+
"pypi_version": release.latest_version,
|
|
120
|
+
"pypi_uploaded_at": release.uploaded_at,
|
|
121
|
+
"pypi_exists": release.exists,
|
|
122
|
+
"publish_gap": publish_gap,
|
|
123
|
+
"git_head": head,
|
|
124
|
+
"git_latest_tag": tag,
|
|
125
|
+
"changes": changes,
|
|
126
|
+
"should_notify": should_notify,
|
|
127
|
+
"summary": "changes detected" if changes else "no material changes",
|
|
128
|
+
"links": {
|
|
129
|
+
"GitHub repo": f"https://github.com/{cfg.repo}",
|
|
130
|
+
"PyPI project": release.project_url,
|
|
131
|
+
"PyPI publishing errors": cfg.pypi_publishing_errors_url,
|
|
132
|
+
"Trusted publishing docs": "https://docs.pypi.org/trusted-publishers/",
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if persist_state:
|
|
137
|
+
new_state = MonitorState(
|
|
138
|
+
local_version=meta.version,
|
|
139
|
+
pypi_version=release.latest_version,
|
|
140
|
+
pypi_uploaded_at=release.uploaded_at,
|
|
141
|
+
last_notified_at=_now_iso() if should_notify else previous.last_notified_at,
|
|
142
|
+
)
|
|
143
|
+
save_state(cfg.state_file, new_state)
|
|
144
|
+
|
|
145
|
+
return report
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import tomllib
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class ProjectMeta:
|
|
11
|
+
name: str
|
|
12
|
+
version: str
|
|
13
|
+
pyproject_path: Path
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def find_pyproject(start: Path | None = None) -> Path:
|
|
17
|
+
current = (start or Path.cwd()).resolve()
|
|
18
|
+
for candidate in [current, *current.parents]:
|
|
19
|
+
path = candidate / "pyproject.toml"
|
|
20
|
+
if path.is_file():
|
|
21
|
+
return path
|
|
22
|
+
raise FileNotFoundError("pyproject.toml not found in current directory or parents")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def load_project_meta(pyproject_path: Path | None = None) -> ProjectMeta:
|
|
26
|
+
path = pyproject_path or find_pyproject()
|
|
27
|
+
data = tomllib.loads(path.read_text(encoding="utf-8"))
|
|
28
|
+
project = data.get("project")
|
|
29
|
+
if not isinstance(project, dict):
|
|
30
|
+
raise ValueError(f"Missing [project] table in {path}")
|
|
31
|
+
name = project.get("name")
|
|
32
|
+
version = project.get("version")
|
|
33
|
+
if not isinstance(name, str) or not name.strip():
|
|
34
|
+
raise ValueError(f"Missing project.name in {path}")
|
|
35
|
+
if not isinstance(version, str) or not version.strip():
|
|
36
|
+
raise ValueError(f"Missing project.version in {path}")
|
|
37
|
+
return ProjectMeta(name=name.strip(), version=version.strip(), pyproject_path=path)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_SEMVER = re.compile(
|
|
41
|
+
r"^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)"
|
|
42
|
+
r"(?P<rest>(?:[a-zA-Z0-9.-]+)?)$"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def bump_version(version: str, part: str) -> str:
|
|
47
|
+
match = _SEMVER.match(version)
|
|
48
|
+
if not match:
|
|
49
|
+
raise ValueError(f"Unsupported version format: {version!r} (expected semver like 1.2.3)")
|
|
50
|
+
major, minor, patch = (
|
|
51
|
+
int(match.group("major")),
|
|
52
|
+
int(match.group("minor")),
|
|
53
|
+
int(match.group("patch")),
|
|
54
|
+
)
|
|
55
|
+
rest = match.group("rest") or ""
|
|
56
|
+
if rest and not rest.startswith(("-", ".")):
|
|
57
|
+
raise ValueError(f"Cannot auto-bump version with suffix: {version!r}")
|
|
58
|
+
|
|
59
|
+
if part == "major":
|
|
60
|
+
major += 1
|
|
61
|
+
minor = 0
|
|
62
|
+
patch = 0
|
|
63
|
+
elif part == "minor":
|
|
64
|
+
minor += 1
|
|
65
|
+
patch = 0
|
|
66
|
+
elif part == "patch":
|
|
67
|
+
patch += 1
|
|
68
|
+
else:
|
|
69
|
+
raise ValueError(f"Unknown bump part: {part!r}")
|
|
70
|
+
|
|
71
|
+
return f"{major}.{minor}.{patch}{rest}"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def write_project_version(pyproject_path: Path, new_version: str) -> None:
|
|
75
|
+
text = pyproject_path.read_text(encoding="utf-8")
|
|
76
|
+
updated, count = re.subn(
|
|
77
|
+
r'(?m)^(\s*version\s*=\s*")[^"]+(")',
|
|
78
|
+
rf'\g<1>{new_version}\2',
|
|
79
|
+
text,
|
|
80
|
+
count=1,
|
|
81
|
+
)
|
|
82
|
+
if count != 1:
|
|
83
|
+
raise ValueError(f"Could not update version in {pyproject_path}")
|
|
84
|
+
pyproject_path.write_text(updated, encoding="utf-8")
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
PYPI_JSON = "https://pypi.org/pypi/{name}/json"
|
|
9
|
+
PYPI_PROJECT = "https://pypi.org/project/{name}/"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class ReleaseInfo:
|
|
14
|
+
name: str
|
|
15
|
+
latest_version: str | None
|
|
16
|
+
uploaded_at: str | None
|
|
17
|
+
project_url: str
|
|
18
|
+
exists: bool
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def fetch_release_info(package_name: str, *, timeout: float = 30.0) -> ReleaseInfo:
|
|
22
|
+
url = PYPI_JSON.format(name=package_name)
|
|
23
|
+
with httpx.Client(timeout=timeout, follow_redirects=True) as client:
|
|
24
|
+
response = client.get(url)
|
|
25
|
+
if response.status_code == 404:
|
|
26
|
+
return ReleaseInfo(
|
|
27
|
+
name=package_name,
|
|
28
|
+
latest_version=None,
|
|
29
|
+
uploaded_at=None,
|
|
30
|
+
project_url=PYPI_PROJECT.format(name=package_name),
|
|
31
|
+
exists=False,
|
|
32
|
+
)
|
|
33
|
+
response.raise_for_status()
|
|
34
|
+
payload: dict[str, Any] = response.json()
|
|
35
|
+
|
|
36
|
+
info = payload.get("info") or {}
|
|
37
|
+
latest = info.get("version")
|
|
38
|
+
releases = payload.get("releases") or {}
|
|
39
|
+
uploaded_at: str | None = None
|
|
40
|
+
if isinstance(latest, str) and latest in releases and releases[latest]:
|
|
41
|
+
files = releases[latest]
|
|
42
|
+
if isinstance(files, list) and files:
|
|
43
|
+
first = files[0]
|
|
44
|
+
if isinstance(first, dict):
|
|
45
|
+
uploaded_at = first.get("upload_time") or first.get("upload_time_iso8601")
|
|
46
|
+
|
|
47
|
+
return ReleaseInfo(
|
|
48
|
+
name=package_name,
|
|
49
|
+
latest_version=latest if isinstance(latest, str) else None,
|
|
50
|
+
uploaded_at=uploaded_at if isinstance(uploaded_at, str) else None,
|
|
51
|
+
project_url=PYPI_PROJECT.format(name=package_name),
|
|
52
|
+
exists=True,
|
|
53
|
+
)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SlackNotifyError(RuntimeError):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def slack_webhook_configured() -> bool:
|
|
15
|
+
return bool(os.environ.get("SLACK_WEBHOOK_URL", "").strip())
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def post_webhook(
|
|
19
|
+
*,
|
|
20
|
+
text: str,
|
|
21
|
+
blocks: list[dict[str, Any]] | None = None,
|
|
22
|
+
timeout: float = 30.0,
|
|
23
|
+
) -> None:
|
|
24
|
+
webhook = os.environ.get("SLACK_WEBHOOK_URL", "").strip()
|
|
25
|
+
if not webhook:
|
|
26
|
+
raise SlackNotifyError(
|
|
27
|
+
"SLACK_WEBHOOK_URL is not set. Add an incoming webhook URL in GitHub Actions secrets "
|
|
28
|
+
"or export it locally before running monitor slack."
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
body: dict[str, Any] = {"text": text}
|
|
32
|
+
if blocks:
|
|
33
|
+
body["blocks"] = blocks
|
|
34
|
+
|
|
35
|
+
with httpx.Client(timeout=timeout) as client:
|
|
36
|
+
response = client.post(
|
|
37
|
+
webhook,
|
|
38
|
+
content=json.dumps(body),
|
|
39
|
+
headers={"Content-Type": "application/json"},
|
|
40
|
+
)
|
|
41
|
+
if response.status_code >= 400:
|
|
42
|
+
raise SlackNotifyError(
|
|
43
|
+
f"Slack webhook returned HTTP {response.status_code}: {response.text[:500]}"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def format_update_message(report: dict[str, Any]) -> str:
|
|
48
|
+
lines = [
|
|
49
|
+
f"*pypi-sdk.space monitor* — {report.get('summary', 'update')}",
|
|
50
|
+
"",
|
|
51
|
+
]
|
|
52
|
+
repo = report.get("repo")
|
|
53
|
+
if repo:
|
|
54
|
+
lines.append(f"Repo: `{repo}`")
|
|
55
|
+
package = report.get("package")
|
|
56
|
+
if package:
|
|
57
|
+
lines.append(f"PyPI package: `{package}`")
|
|
58
|
+
|
|
59
|
+
local = report.get("local_version")
|
|
60
|
+
remote = report.get("pypi_version")
|
|
61
|
+
if local is not None or remote is not None:
|
|
62
|
+
lines.append(f"Version local/PyPI: `{local}` / `{remote or 'not published yet'}`")
|
|
63
|
+
|
|
64
|
+
changes = report.get("changes") or []
|
|
65
|
+
if changes:
|
|
66
|
+
lines.append("")
|
|
67
|
+
lines.append("*Changes detected:*")
|
|
68
|
+
for item in changes:
|
|
69
|
+
lines.append(f"• {item}")
|
|
70
|
+
|
|
71
|
+
links = report.get("links") or {}
|
|
72
|
+
if links:
|
|
73
|
+
lines.append("")
|
|
74
|
+
for label, url in links.items():
|
|
75
|
+
lines.append(f"• {label}: {url}")
|
|
76
|
+
|
|
77
|
+
return "\n".join(lines)
|