apdev 0.2.5__tar.gz → 0.2.7__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.
- {apdev-0.2.5 → apdev-0.2.7}/PKG-INFO +65 -5
- {apdev-0.2.5 → apdev-0.2.7}/README.md +64 -4
- {apdev-0.2.5 → apdev-0.2.7}/pyproject.toml +1 -1
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/__init__.py +1 -1
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/cli.py +25 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/release.sh +110 -10
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev.egg-info/PKG-INFO +65 -5
- {apdev-0.2.5 → apdev-0.2.7}/tests/test_cli.py +128 -1
- {apdev-0.2.5 → apdev-0.2.7}/setup.cfg +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/__main__.py +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/charsets/base.json +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/charsets/chinese.json +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/charsets/japanese.json +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/charsets/korean.json +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/check_chars.py +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/check_imports.py +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/config.py +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev/py.typed +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev.egg-info/SOURCES.txt +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev.egg-info/dependency_links.txt +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev.egg-info/entry_points.txt +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev.egg-info/requires.txt +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/src/apdev.egg-info/top_level.txt +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/tests/test_check_chars.py +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/tests/test_check_imports.py +0 -0
- {apdev-0.2.5 → apdev-0.2.7}/tests/test_config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apdev
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Shared development tools for Python projects - character validation, circular import detection, and more
|
|
5
5
|
Author-email: aiperceivable <tercel.yi@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -94,6 +94,14 @@ apdev release
|
|
|
94
94
|
|
|
95
95
|
# Or specify version explicitly
|
|
96
96
|
apdev release 0.2.0
|
|
97
|
+
|
|
98
|
+
# Upload to a named .pypirc section (default: [tool.apdev] pypi_repository, or "pypi")
|
|
99
|
+
apdev release --repository reachreel
|
|
100
|
+
apdev release -r testpypi 0.3.0
|
|
101
|
+
|
|
102
|
+
# Publish the GitHub release as another account (default: [tool.apdev] github_account, or gh's active account)
|
|
103
|
+
apdev release --account wilfred
|
|
104
|
+
apdev release -a tercel 0.3.0
|
|
97
105
|
```
|
|
98
106
|
|
|
99
107
|
The command provides an interactive menu with steps:
|
|
@@ -104,7 +112,56 @@ The command provides an interactive menu with steps:
|
|
|
104
112
|
5. Check package (`twine check`)
|
|
105
113
|
6. Create git tag and push
|
|
106
114
|
7. Create GitHub release (via `gh` CLI or API)
|
|
107
|
-
8. Upload to PyPI (`twine upload
|
|
115
|
+
8. Upload to PyPI (`twine upload -r <repository> dist/*`)
|
|
116
|
+
|
|
117
|
+
Which `~/.pypirc` section is used, in order of precedence:
|
|
118
|
+
|
|
119
|
+
1. `--repository NAME` / `-r NAME`
|
|
120
|
+
2. `PYPI_REPOSITORY` environment variable
|
|
121
|
+
3. `[tool.apdev] pypi_repository` in `pyproject.toml`
|
|
122
|
+
4. the default `[pypi]` section
|
|
123
|
+
|
|
124
|
+
The resolved section is printed in the header before anything is uploaded, so a
|
|
125
|
+
second PyPI account is never a guess:
|
|
126
|
+
|
|
127
|
+
```ini
|
|
128
|
+
# ~/.pypirc
|
|
129
|
+
[distutils]
|
|
130
|
+
index-servers =
|
|
131
|
+
pypi
|
|
132
|
+
reachreel
|
|
133
|
+
|
|
134
|
+
[pypi]
|
|
135
|
+
username = __token__
|
|
136
|
+
password = pypi-A... # account A
|
|
137
|
+
|
|
138
|
+
[reachreel]
|
|
139
|
+
repository = https://upload.pypi.org/legacy/
|
|
140
|
+
username = __token__
|
|
141
|
+
password = pypi-B... # account B
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Releasing with a second GitHub account
|
|
145
|
+
|
|
146
|
+
`git push` already follows the remote (for example an SSH alias per account),
|
|
147
|
+
but `gh` uses one active login. Log the second account in once — `gh` keeps
|
|
148
|
+
several accounts per host — and let the repository choose which one releases:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
gh auth login --git-protocol ssh # first account
|
|
152
|
+
gh auth login --git-protocol ssh # second account, same host
|
|
153
|
+
gh auth status # both logins listed, one active
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```toml
|
|
157
|
+
[tool.apdev]
|
|
158
|
+
github_account = "wilfred"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`apdev release` then resolves that account's token with
|
|
162
|
+
`gh auth token --user wilfred`, exports it as `GH_TOKEN`/`GITHUB_TOKEN` for the
|
|
163
|
+
run only, and prints `GitHub user: wilfred` in the header. The global active
|
|
164
|
+
account is never switched, so other repositories keep their own identity.
|
|
108
165
|
|
|
109
166
|
Override auto-detection with environment variables:
|
|
110
167
|
|
|
@@ -118,15 +175,18 @@ Add to your project's `pyproject.toml` so commands can run without CLI arguments
|
|
|
118
175
|
|
|
119
176
|
```toml
|
|
120
177
|
[tool.apdev]
|
|
121
|
-
base_package = "mypackage"
|
|
122
|
-
src_dir = "src"
|
|
178
|
+
base_package = "mypackage" # Required by check-imports
|
|
179
|
+
src_dir = "src" # Source directory (default: "src")
|
|
180
|
+
pypi_repository = "mypackage" # .pypirc section for `apdev release` (default: "pypi")
|
|
181
|
+
github_account = "wilfred" # gh login for the GitHub release (default: gh's active account)
|
|
123
182
|
```
|
|
124
183
|
|
|
125
|
-
With this config,
|
|
184
|
+
With this config, the commands work out of the box:
|
|
126
185
|
|
|
127
186
|
```bash
|
|
128
187
|
apdev check-chars # Checks default project directories and config files
|
|
129
188
|
apdev check-imports # Reads base_package / src_dir from pyproject.toml
|
|
189
|
+
apdev release # Reads pypi_repository, so the right PyPI account is used
|
|
130
190
|
```
|
|
131
191
|
|
|
132
192
|
## Pre-commit Integration
|
|
@@ -64,6 +64,14 @@ apdev release
|
|
|
64
64
|
|
|
65
65
|
# Or specify version explicitly
|
|
66
66
|
apdev release 0.2.0
|
|
67
|
+
|
|
68
|
+
# Upload to a named .pypirc section (default: [tool.apdev] pypi_repository, or "pypi")
|
|
69
|
+
apdev release --repository reachreel
|
|
70
|
+
apdev release -r testpypi 0.3.0
|
|
71
|
+
|
|
72
|
+
# Publish the GitHub release as another account (default: [tool.apdev] github_account, or gh's active account)
|
|
73
|
+
apdev release --account wilfred
|
|
74
|
+
apdev release -a tercel 0.3.0
|
|
67
75
|
```
|
|
68
76
|
|
|
69
77
|
The command provides an interactive menu with steps:
|
|
@@ -74,7 +82,56 @@ The command provides an interactive menu with steps:
|
|
|
74
82
|
5. Check package (`twine check`)
|
|
75
83
|
6. Create git tag and push
|
|
76
84
|
7. Create GitHub release (via `gh` CLI or API)
|
|
77
|
-
8. Upload to PyPI (`twine upload
|
|
85
|
+
8. Upload to PyPI (`twine upload -r <repository> dist/*`)
|
|
86
|
+
|
|
87
|
+
Which `~/.pypirc` section is used, in order of precedence:
|
|
88
|
+
|
|
89
|
+
1. `--repository NAME` / `-r NAME`
|
|
90
|
+
2. `PYPI_REPOSITORY` environment variable
|
|
91
|
+
3. `[tool.apdev] pypi_repository` in `pyproject.toml`
|
|
92
|
+
4. the default `[pypi]` section
|
|
93
|
+
|
|
94
|
+
The resolved section is printed in the header before anything is uploaded, so a
|
|
95
|
+
second PyPI account is never a guess:
|
|
96
|
+
|
|
97
|
+
```ini
|
|
98
|
+
# ~/.pypirc
|
|
99
|
+
[distutils]
|
|
100
|
+
index-servers =
|
|
101
|
+
pypi
|
|
102
|
+
reachreel
|
|
103
|
+
|
|
104
|
+
[pypi]
|
|
105
|
+
username = __token__
|
|
106
|
+
password = pypi-A... # account A
|
|
107
|
+
|
|
108
|
+
[reachreel]
|
|
109
|
+
repository = https://upload.pypi.org/legacy/
|
|
110
|
+
username = __token__
|
|
111
|
+
password = pypi-B... # account B
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Releasing with a second GitHub account
|
|
115
|
+
|
|
116
|
+
`git push` already follows the remote (for example an SSH alias per account),
|
|
117
|
+
but `gh` uses one active login. Log the second account in once — `gh` keeps
|
|
118
|
+
several accounts per host — and let the repository choose which one releases:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
gh auth login --git-protocol ssh # first account
|
|
122
|
+
gh auth login --git-protocol ssh # second account, same host
|
|
123
|
+
gh auth status # both logins listed, one active
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```toml
|
|
127
|
+
[tool.apdev]
|
|
128
|
+
github_account = "wilfred"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`apdev release` then resolves that account's token with
|
|
132
|
+
`gh auth token --user wilfred`, exports it as `GH_TOKEN`/`GITHUB_TOKEN` for the
|
|
133
|
+
run only, and prints `GitHub user: wilfred` in the header. The global active
|
|
134
|
+
account is never switched, so other repositories keep their own identity.
|
|
78
135
|
|
|
79
136
|
Override auto-detection with environment variables:
|
|
80
137
|
|
|
@@ -88,15 +145,18 @@ Add to your project's `pyproject.toml` so commands can run without CLI arguments
|
|
|
88
145
|
|
|
89
146
|
```toml
|
|
90
147
|
[tool.apdev]
|
|
91
|
-
base_package = "mypackage"
|
|
92
|
-
src_dir = "src"
|
|
148
|
+
base_package = "mypackage" # Required by check-imports
|
|
149
|
+
src_dir = "src" # Source directory (default: "src")
|
|
150
|
+
pypi_repository = "mypackage" # .pypirc section for `apdev release` (default: "pypi")
|
|
151
|
+
github_account = "wilfred" # gh login for the GitHub release (default: gh's active account)
|
|
93
152
|
```
|
|
94
153
|
|
|
95
|
-
With this config,
|
|
154
|
+
With this config, the commands work out of the box:
|
|
96
155
|
|
|
97
156
|
```bash
|
|
98
157
|
apdev check-chars # Checks default project directories and config files
|
|
99
158
|
apdev check-imports # Reads base_package / src_dir from pyproject.toml
|
|
159
|
+
apdev release # Reads pypi_repository, so the right PyPI account is used
|
|
100
160
|
```
|
|
101
161
|
|
|
102
162
|
## Pre-commit Integration
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "apdev"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.7"
|
|
8
8
|
description = "Shared development tools for Python projects - character validation, circular import detection, and more"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "Apache-2.0"}
|
|
@@ -85,6 +85,24 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
85
85
|
action="store_true",
|
|
86
86
|
help="Auto-accept all defaults (silent mode)",
|
|
87
87
|
)
|
|
88
|
+
release_parser.add_argument(
|
|
89
|
+
"--account",
|
|
90
|
+
"-a",
|
|
91
|
+
dest="account",
|
|
92
|
+
help=(
|
|
93
|
+
"GitHub account (gh login) used to publish the release "
|
|
94
|
+
"(default: [tool.apdev] github_account, or gh's active account)"
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
release_parser.add_argument(
|
|
98
|
+
"--repository",
|
|
99
|
+
"-r",
|
|
100
|
+
dest="repository",
|
|
101
|
+
help=(
|
|
102
|
+
"Named .pypirc section to upload to (default: [tool.apdev] "
|
|
103
|
+
"pypi_repository, or 'pypi')"
|
|
104
|
+
),
|
|
105
|
+
)
|
|
88
106
|
release_parser.add_argument(
|
|
89
107
|
"version",
|
|
90
108
|
nargs="?",
|
|
@@ -148,6 +166,13 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
148
166
|
cmd = ["bash", str(script)]
|
|
149
167
|
if args.yes:
|
|
150
168
|
cmd.append("--yes")
|
|
169
|
+
config = load_config()
|
|
170
|
+
repository = args.repository or config.get("pypi_repository")
|
|
171
|
+
if repository:
|
|
172
|
+
cmd.extend(["--repository", str(repository)])
|
|
173
|
+
account = args.account or config.get("github_account")
|
|
174
|
+
if account:
|
|
175
|
+
cmd.extend(["--account", str(account)])
|
|
151
176
|
if args.version:
|
|
152
177
|
cmd.append(args.version)
|
|
153
178
|
release_env = os.environ.copy()
|
|
@@ -6,19 +6,46 @@
|
|
|
6
6
|
# ./release.sh --yes 0.2.0 # silent mode with specific version
|
|
7
7
|
#
|
|
8
8
|
# Auto-detects project name from pyproject.toml and GitHub repo from git remote.
|
|
9
|
-
# Override with environment variables: PROJECT_NAME, PACKAGE_NAME, GITHUB_REPO
|
|
9
|
+
# Override with environment variables: PROJECT_NAME, PACKAGE_NAME, GITHUB_REPO,
|
|
10
|
+
# PYPI_REPOSITORY (named .pypirc section, default "pypi"), GITHUB_ACCOUNT
|
|
11
|
+
# (gh login to publish the GitHub release as; default: gh's active account).
|
|
10
12
|
|
|
11
13
|
# Note: set -e is disabled to allow step-by-step execution
|
|
12
14
|
# Individual steps will handle their own error handling
|
|
13
15
|
|
|
14
16
|
# Silent mode flag (--yes or -y to auto-accept all defaults)
|
|
15
17
|
SILENT=false
|
|
18
|
+
PYPI_REPOSITORY="${PYPI_REPOSITORY:-}"
|
|
19
|
+
GITHUB_ACCOUNT="${GITHUB_ACCOUNT:-}"
|
|
16
20
|
POSITIONAL_ARGS=()
|
|
17
|
-
|
|
18
|
-
case "$
|
|
21
|
+
while [ "$#" -gt 0 ]; do
|
|
22
|
+
case "$1" in
|
|
19
23
|
--yes|-y) SILENT=true ;;
|
|
20
|
-
|
|
24
|
+
--repository|-r)
|
|
25
|
+
if [ "$#" -lt 2 ] || [ -z "$2" ]; then
|
|
26
|
+
echo "Error: --repository needs a .pypirc section name" >&2
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
PYPI_REPOSITORY="$2"
|
|
30
|
+
shift
|
|
31
|
+
;;
|
|
32
|
+
--repository=*)
|
|
33
|
+
PYPI_REPOSITORY="${1#*=}"
|
|
34
|
+
;;
|
|
35
|
+
--account|-a)
|
|
36
|
+
if [ "$#" -lt 2 ] || [ -z "$2" ]; then
|
|
37
|
+
echo "Error: --account needs a GitHub login" >&2
|
|
38
|
+
exit 1
|
|
39
|
+
fi
|
|
40
|
+
GITHUB_ACCOUNT="$2"
|
|
41
|
+
shift
|
|
42
|
+
;;
|
|
43
|
+
--account=*)
|
|
44
|
+
GITHUB_ACCOUNT="${1#*=}"
|
|
45
|
+
;;
|
|
46
|
+
*) POSITIONAL_ARGS+=("$1") ;;
|
|
21
47
|
esac
|
|
48
|
+
shift
|
|
22
49
|
done
|
|
23
50
|
set -- "${POSITIONAL_ARGS[@]}"
|
|
24
51
|
|
|
@@ -49,8 +76,18 @@ fi
|
|
|
49
76
|
if [ -z "$GITHUB_REPO" ]; then
|
|
50
77
|
REMOTE_URL=$(git remote get-url origin 2>/dev/null)
|
|
51
78
|
if [ -n "$REMOTE_URL" ]; then
|
|
52
|
-
# Extract owner/repo from
|
|
53
|
-
|
|
79
|
+
# Extract owner/repo from any remote form, including per-account SSH
|
|
80
|
+
# aliases such as git@github-work:owner/repo.git, which earlier versions
|
|
81
|
+
# did not recognise (they only matched github.com).
|
|
82
|
+
GITHUB_REPO=$(echo "$REMOTE_URL" \
|
|
83
|
+
| sed -E 's|\.git$||; s|/+$||' \
|
|
84
|
+
| tr ':' '/' \
|
|
85
|
+
| awk -F/ '{ if (NF >= 2) print $(NF-1) "/" $NF }')
|
|
86
|
+
if ! echo "$GITHUB_REPO" | grep -Eq '^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$'; then
|
|
87
|
+
echo -e "${YELLOW}Warning: could not parse owner/repo from ${REMOTE_URL}${NC}"
|
|
88
|
+
echo -e "${YELLOW} Set GITHUB_REPO=owner/repo to create the GitHub release${NC}"
|
|
89
|
+
GITHUB_REPO=""
|
|
90
|
+
fi
|
|
54
91
|
fi
|
|
55
92
|
if [ -z "$GITHUB_REPO" ]; then
|
|
56
93
|
echo -e "${YELLOW}Warning: Could not detect GitHub repo from git remote${NC}"
|
|
@@ -58,6 +95,62 @@ if [ -z "$GITHUB_REPO" ]; then
|
|
|
58
95
|
fi
|
|
59
96
|
fi
|
|
60
97
|
|
|
98
|
+
# PyPI repository: --repository, then PYPI_REPOSITORY, then [tool.apdev]
|
|
99
|
+
# pypi_repository, then the default "pypi" section of ~/.pypirc.
|
|
100
|
+
#
|
|
101
|
+
# Parsed with awk instead of tomllib so the script works on any machine, even
|
|
102
|
+
# one whose `python3` is older than 3.11.
|
|
103
|
+
if [ -z "$PYPI_REPOSITORY" ] && [ -f pyproject.toml ]; then
|
|
104
|
+
PYPI_REPOSITORY=$(awk '
|
|
105
|
+
/^[[:space:]]*\[/ {
|
|
106
|
+
in_apdev = ($0 ~ /^[[:space:]]*\[tool\.apdev\][[:space:]]*$/)
|
|
107
|
+
next
|
|
108
|
+
}
|
|
109
|
+
in_apdev && /^[[:space:]]*pypi_repository[[:space:]]*=/ {
|
|
110
|
+
print
|
|
111
|
+
exit
|
|
112
|
+
}
|
|
113
|
+
' pyproject.toml | sed -E 's/^[^=]*=[[:space:]]*//; s/[[:space:]]+$//; s/^"//; s/"$//; s/^\x27//; s/\x27$//')
|
|
114
|
+
fi
|
|
115
|
+
PYPI_REPOSITORY="${PYPI_REPOSITORY:-pypi}"
|
|
116
|
+
|
|
117
|
+
# GitHub account: --account, then GITHUB_ACCOUNT, then [tool.apdev]
|
|
118
|
+
# github_account, then whatever `gh` has active. When set, its token is exported
|
|
119
|
+
# for this run only, so `gh` and the API fallback act as that user without
|
|
120
|
+
# touching the global `gh auth switch` state.
|
|
121
|
+
if [ -z "$GITHUB_ACCOUNT" ] && [ -f pyproject.toml ]; then
|
|
122
|
+
GITHUB_ACCOUNT=$(awk '
|
|
123
|
+
/^[[:space:]]*\[/ {
|
|
124
|
+
in_apdev = ($0 ~ /^[[:space:]]*\[tool\.apdev\][[:space:]]*$/)
|
|
125
|
+
next
|
|
126
|
+
}
|
|
127
|
+
in_apdev && /^[[:space:]]*github_account[[:space:]]*=/ {
|
|
128
|
+
print
|
|
129
|
+
exit
|
|
130
|
+
}
|
|
131
|
+
' pyproject.toml | sed -E 's/^[^=]*=[[:space:]]*//; s/[[:space:]]+$//; s/^"//; s/"$//; s/^\x27//; s/\x27$//')
|
|
132
|
+
fi
|
|
133
|
+
|
|
134
|
+
if [ -n "$GITHUB_ACCOUNT" ]; then
|
|
135
|
+
if ! command -v gh > /dev/null 2>&1; then
|
|
136
|
+
echo -e "${RED}Error: --account/GITHUB_ACCOUNT needs the GitHub CLI${NC}"
|
|
137
|
+
echo -e "${YELLOW}Install it (brew install gh) or unset the account to use GITHUB_TOKEN${NC}"
|
|
138
|
+
exit 1
|
|
139
|
+
fi
|
|
140
|
+
if ! GH_ACCOUNT_TOKEN=$(gh auth token --user "$GITHUB_ACCOUNT" 2>/dev/null) || [ -z "$GH_ACCOUNT_TOKEN" ]; then
|
|
141
|
+
echo -e "${RED}Error: GitHub account '${GITHUB_ACCOUNT}' is not logged in${NC}"
|
|
142
|
+
echo -e "${YELLOW}Add it once with: gh auth login --git-protocol ssh${NC}"
|
|
143
|
+
echo -e "${YELLOW}Then verify with: gh auth status${NC}"
|
|
144
|
+
exit 1
|
|
145
|
+
fi
|
|
146
|
+
if [ -n "$GITHUB_TOKEN" ] && [ "$GITHUB_TOKEN" != "$GH_ACCOUNT_TOKEN" ]; then
|
|
147
|
+
echo -e "${YELLOW}Note: GITHUB_TOKEN was set; using the token of '${GITHUB_ACCOUNT}' instead${NC}"
|
|
148
|
+
fi
|
|
149
|
+
GH_TOKEN="$GH_ACCOUNT_TOKEN"
|
|
150
|
+
GITHUB_TOKEN="$GH_ACCOUNT_TOKEN"
|
|
151
|
+
export GH_TOKEN GITHUB_TOKEN
|
|
152
|
+
fi
|
|
153
|
+
|
|
61
154
|
# Get version from argument or pyproject.toml
|
|
62
155
|
if [ -z "$1" ]; then
|
|
63
156
|
VERSION=$(grep -E '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
|
|
@@ -77,6 +170,8 @@ echo -e "${CYAN}║ ${PROJECT_NAME} Release Script v${VERSION}${NC}"
|
|
|
77
170
|
echo -e "${CYAN}╚══════════════════════════════════════════════════════════╝${NC}"
|
|
78
171
|
echo -e " Project: ${CYAN}${PROJECT_NAME}${NC}"
|
|
79
172
|
[ -n "$GITHUB_REPO" ] && echo -e " GitHub: ${CYAN}${GITHUB_REPO}${NC}"
|
|
173
|
+
echo -e " PyPI: ${CYAN}${PYPI_REPOSITORY}${NC}"
|
|
174
|
+
[ -n "$GITHUB_ACCOUNT" ] && echo -e " GitHub user: ${CYAN}${GITHUB_ACCOUNT}${NC}"
|
|
80
175
|
echo ""
|
|
81
176
|
|
|
82
177
|
# Function to check if step is already done
|
|
@@ -439,11 +534,16 @@ step6_git_tag() {
|
|
|
439
534
|
|
|
440
535
|
# Function to get GitHub token from various sources
|
|
441
536
|
get_github_token() {
|
|
442
|
-
# 1. Check environment variable
|
|
537
|
+
# 1. Check environment variable. GH_TOKEN comes first for the account
|
|
538
|
+
# selected by --account/GITHUB_ACCOUNT, which step 6.5 does not clear.
|
|
443
539
|
if [ -n "$GITHUB_TOKEN" ]; then
|
|
444
540
|
echo "$GITHUB_TOKEN"
|
|
445
541
|
return 0
|
|
446
542
|
fi
|
|
543
|
+
if [ -n "$GH_TOKEN" ]; then
|
|
544
|
+
echo "$GH_TOKEN"
|
|
545
|
+
return 0
|
|
546
|
+
fi
|
|
447
547
|
|
|
448
548
|
# 2. Check git config for token
|
|
449
549
|
local token=$(git config --global github.token 2>/dev/null || git config github.token 2>/dev/null)
|
|
@@ -754,15 +854,15 @@ step7_upload_pypi() {
|
|
|
754
854
|
fi
|
|
755
855
|
|
|
756
856
|
if ask_yn "Upload to PyPI?" "y"; then
|
|
757
|
-
echo -e "${YELLOW}Uploading to PyPI...${NC}"
|
|
758
|
-
if ! twine upload dist/*; then
|
|
857
|
+
echo -e "${YELLOW}Uploading to PyPI (${PYPI_REPOSITORY})...${NC}"
|
|
858
|
+
if ! twine upload -r "$PYPI_REPOSITORY" dist/*; then
|
|
759
859
|
echo -e "${RED}❌ Upload to PyPI failed${NC}"
|
|
760
860
|
return 1
|
|
761
861
|
fi
|
|
762
862
|
echo -e "${GREEN}✅ Successfully uploaded to PyPI!${NC}"
|
|
763
863
|
else
|
|
764
864
|
echo -e "${YELLOW}⚠️ Skipped PyPI upload${NC}"
|
|
765
|
-
echo -e "${CYAN} Upload manually with: twine upload dist/*${NC}"
|
|
865
|
+
echo -e "${CYAN} Upload manually with: twine upload -r ${PYPI_REPOSITORY} dist/*${NC}"
|
|
766
866
|
fi
|
|
767
867
|
else
|
|
768
868
|
echo -e "${YELLOW}⚠️ Skipped PyPI upload (version already exists)${NC}"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apdev
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Shared development tools for Python projects - character validation, circular import detection, and more
|
|
5
5
|
Author-email: aiperceivable <tercel.yi@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -94,6 +94,14 @@ apdev release
|
|
|
94
94
|
|
|
95
95
|
# Or specify version explicitly
|
|
96
96
|
apdev release 0.2.0
|
|
97
|
+
|
|
98
|
+
# Upload to a named .pypirc section (default: [tool.apdev] pypi_repository, or "pypi")
|
|
99
|
+
apdev release --repository reachreel
|
|
100
|
+
apdev release -r testpypi 0.3.0
|
|
101
|
+
|
|
102
|
+
# Publish the GitHub release as another account (default: [tool.apdev] github_account, or gh's active account)
|
|
103
|
+
apdev release --account wilfred
|
|
104
|
+
apdev release -a tercel 0.3.0
|
|
97
105
|
```
|
|
98
106
|
|
|
99
107
|
The command provides an interactive menu with steps:
|
|
@@ -104,7 +112,56 @@ The command provides an interactive menu with steps:
|
|
|
104
112
|
5. Check package (`twine check`)
|
|
105
113
|
6. Create git tag and push
|
|
106
114
|
7. Create GitHub release (via `gh` CLI or API)
|
|
107
|
-
8. Upload to PyPI (`twine upload
|
|
115
|
+
8. Upload to PyPI (`twine upload -r <repository> dist/*`)
|
|
116
|
+
|
|
117
|
+
Which `~/.pypirc` section is used, in order of precedence:
|
|
118
|
+
|
|
119
|
+
1. `--repository NAME` / `-r NAME`
|
|
120
|
+
2. `PYPI_REPOSITORY` environment variable
|
|
121
|
+
3. `[tool.apdev] pypi_repository` in `pyproject.toml`
|
|
122
|
+
4. the default `[pypi]` section
|
|
123
|
+
|
|
124
|
+
The resolved section is printed in the header before anything is uploaded, so a
|
|
125
|
+
second PyPI account is never a guess:
|
|
126
|
+
|
|
127
|
+
```ini
|
|
128
|
+
# ~/.pypirc
|
|
129
|
+
[distutils]
|
|
130
|
+
index-servers =
|
|
131
|
+
pypi
|
|
132
|
+
reachreel
|
|
133
|
+
|
|
134
|
+
[pypi]
|
|
135
|
+
username = __token__
|
|
136
|
+
password = pypi-A... # account A
|
|
137
|
+
|
|
138
|
+
[reachreel]
|
|
139
|
+
repository = https://upload.pypi.org/legacy/
|
|
140
|
+
username = __token__
|
|
141
|
+
password = pypi-B... # account B
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Releasing with a second GitHub account
|
|
145
|
+
|
|
146
|
+
`git push` already follows the remote (for example an SSH alias per account),
|
|
147
|
+
but `gh` uses one active login. Log the second account in once — `gh` keeps
|
|
148
|
+
several accounts per host — and let the repository choose which one releases:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
gh auth login --git-protocol ssh # first account
|
|
152
|
+
gh auth login --git-protocol ssh # second account, same host
|
|
153
|
+
gh auth status # both logins listed, one active
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
```toml
|
|
157
|
+
[tool.apdev]
|
|
158
|
+
github_account = "wilfred"
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`apdev release` then resolves that account's token with
|
|
162
|
+
`gh auth token --user wilfred`, exports it as `GH_TOKEN`/`GITHUB_TOKEN` for the
|
|
163
|
+
run only, and prints `GitHub user: wilfred` in the header. The global active
|
|
164
|
+
account is never switched, so other repositories keep their own identity.
|
|
108
165
|
|
|
109
166
|
Override auto-detection with environment variables:
|
|
110
167
|
|
|
@@ -118,15 +175,18 @@ Add to your project's `pyproject.toml` so commands can run without CLI arguments
|
|
|
118
175
|
|
|
119
176
|
```toml
|
|
120
177
|
[tool.apdev]
|
|
121
|
-
base_package = "mypackage"
|
|
122
|
-
src_dir = "src"
|
|
178
|
+
base_package = "mypackage" # Required by check-imports
|
|
179
|
+
src_dir = "src" # Source directory (default: "src")
|
|
180
|
+
pypi_repository = "mypackage" # .pypirc section for `apdev release` (default: "pypi")
|
|
181
|
+
github_account = "wilfred" # gh login for the GitHub release (default: gh's active account)
|
|
123
182
|
```
|
|
124
183
|
|
|
125
|
-
With this config,
|
|
184
|
+
With this config, the commands work out of the box:
|
|
126
185
|
|
|
127
186
|
```bash
|
|
128
187
|
apdev check-chars # Checks default project directories and config files
|
|
129
188
|
apdev check-imports # Reads base_package / src_dir from pyproject.toml
|
|
189
|
+
apdev release # Reads pypi_repository, so the right PyPI account is used
|
|
130
190
|
```
|
|
131
191
|
|
|
132
192
|
## Pre-commit Integration
|
|
@@ -70,7 +70,134 @@ def test_cli_release_selects_project_virtualenv(
|
|
|
70
70
|
else:
|
|
71
71
|
assert env["PATH"] == original_path
|
|
72
72
|
assert env.get("VIRTUAL_ENV") == os.environ.get("VIRTUAL_ENV")
|
|
73
|
-
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_cli_release_forwards_repository_flag(
|
|
76
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
77
|
+
) -> None:
|
|
78
|
+
"""--repository is passed through to release.sh before the version."""
|
|
79
|
+
monkeypatch.chdir(tmp_path)
|
|
80
|
+
run = Mock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
|
81
|
+
monkeypatch.setattr(cli.subprocess, "run", run)
|
|
82
|
+
|
|
83
|
+
assert cli.main(["release", "--repository", "reachreel", "0.1.0"]) == 0
|
|
84
|
+
|
|
85
|
+
args = run.call_args.args[0]
|
|
86
|
+
assert args[0] == "bash"
|
|
87
|
+
assert args[2:] == ["--repository", "reachreel", "0.1.0"]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_cli_release_reads_repository_from_config(
|
|
91
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
92
|
+
) -> None:
|
|
93
|
+
"""[tool.apdev] pypi_repository selects the section without a flag."""
|
|
94
|
+
monkeypatch.chdir(tmp_path)
|
|
95
|
+
Path("pyproject.toml").write_text(
|
|
96
|
+
textwrap.dedent(
|
|
97
|
+
"""
|
|
98
|
+
[project]
|
|
99
|
+
name = "demo"
|
|
100
|
+
version = "0.1.0"
|
|
101
|
+
|
|
102
|
+
[tool.apdev]
|
|
103
|
+
pypi_repository = "reachreel"
|
|
104
|
+
"""
|
|
105
|
+
),
|
|
106
|
+
encoding="utf-8",
|
|
107
|
+
)
|
|
108
|
+
run = Mock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
|
109
|
+
monkeypatch.setattr(cli.subprocess, "run", run)
|
|
110
|
+
|
|
111
|
+
assert cli.main(["release", "--yes"]) == 0
|
|
112
|
+
|
|
113
|
+
args = run.call_args.args[0]
|
|
114
|
+
assert args[2:] == ["--yes", "--repository", "reachreel"]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_cli_release_flag_beats_config(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
118
|
+
"""An explicit --repository wins over [tool.apdev]."""
|
|
119
|
+
monkeypatch.chdir(tmp_path)
|
|
120
|
+
Path("pyproject.toml").write_text(
|
|
121
|
+
textwrap.dedent(
|
|
122
|
+
"""
|
|
123
|
+
[project]
|
|
124
|
+
name = "demo"
|
|
125
|
+
version = "0.1.0"
|
|
126
|
+
|
|
127
|
+
[tool.apdev]
|
|
128
|
+
pypi_repository = "reachreel"
|
|
129
|
+
"""
|
|
130
|
+
),
|
|
131
|
+
encoding="utf-8",
|
|
132
|
+
)
|
|
133
|
+
run = Mock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
|
134
|
+
monkeypatch.setattr(cli.subprocess, "run", run)
|
|
135
|
+
|
|
136
|
+
assert cli.main(["release", "--repository", "testpypi"]) == 0
|
|
137
|
+
|
|
138
|
+
args = run.call_args.args[0]
|
|
139
|
+
assert args[2:] == ["--repository", "testpypi"]
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_cli_release_forwards_account_from_config(
|
|
143
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
144
|
+
) -> None:
|
|
145
|
+
"""[tool.apdev] github_account selects the gh login for the release."""
|
|
146
|
+
monkeypatch.chdir(tmp_path)
|
|
147
|
+
Path("pyproject.toml").write_text(
|
|
148
|
+
textwrap.dedent(
|
|
149
|
+
"""
|
|
150
|
+
[project]
|
|
151
|
+
name = "demo"
|
|
152
|
+
version = "0.1.0"
|
|
153
|
+
|
|
154
|
+
[tool.apdev]
|
|
155
|
+
github_account = "wilfred"
|
|
156
|
+
"""
|
|
157
|
+
),
|
|
158
|
+
encoding="utf-8",
|
|
159
|
+
)
|
|
160
|
+
run = Mock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
|
161
|
+
monkeypatch.setattr(cli.subprocess, "run", run)
|
|
162
|
+
|
|
163
|
+
assert cli.main(["release", "--yes"]) == 0
|
|
164
|
+
|
|
165
|
+
args = run.call_args.args[0]
|
|
166
|
+
assert args[2:] == ["--yes", "--account", "wilfred"]
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_cli_release_account_flag_beats_config(
|
|
170
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
171
|
+
) -> None:
|
|
172
|
+
"""--account wins over [tool.apdev], and both flags are forwarded."""
|
|
173
|
+
monkeypatch.chdir(tmp_path)
|
|
174
|
+
Path("pyproject.toml").write_text(
|
|
175
|
+
textwrap.dedent(
|
|
176
|
+
"""
|
|
177
|
+
[project]
|
|
178
|
+
name = "demo"
|
|
179
|
+
version = "0.1.0"
|
|
180
|
+
|
|
181
|
+
[tool.apdev]
|
|
182
|
+
github_account = "wilfred"
|
|
183
|
+
pypi_repository = "reachreel"
|
|
184
|
+
"""
|
|
185
|
+
),
|
|
186
|
+
encoding="utf-8",
|
|
187
|
+
)
|
|
188
|
+
run = Mock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
|
189
|
+
monkeypatch.setattr(cli.subprocess, "run", run)
|
|
190
|
+
|
|
191
|
+
assert cli.main(["release", "--account", "tercel", "0.2.0"]) == 0
|
|
192
|
+
|
|
193
|
+
args = run.call_args.args[0]
|
|
194
|
+
assert args[2:] == [
|
|
195
|
+
"--repository",
|
|
196
|
+
"reachreel",
|
|
197
|
+
"--account",
|
|
198
|
+
"tercel",
|
|
199
|
+
"0.2.0",
|
|
200
|
+
]
|
|
74
201
|
|
|
75
202
|
|
|
76
203
|
def test_cli_check_chars_clean(tmp_path: Path) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|