apdev 0.2.3__tar.gz → 0.2.6__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.3 → apdev-0.2.6}/PKG-INFO +46 -11
- {apdev-0.2.3 → apdev-0.2.6}/README.md +40 -5
- {apdev-0.2.3 → apdev-0.2.6}/pyproject.toml +6 -6
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/__init__.py +1 -1
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/cli.py +25 -1
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/release.sh +41 -7
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev.egg-info/PKG-INFO +46 -11
- {apdev-0.2.3 → apdev-0.2.6}/tests/test_cli.py +113 -0
- {apdev-0.2.3 → apdev-0.2.6}/setup.cfg +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/__main__.py +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/charsets/base.json +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/charsets/chinese.json +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/charsets/japanese.json +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/charsets/korean.json +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/check_chars.py +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/check_imports.py +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/config.py +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev/py.typed +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev.egg-info/SOURCES.txt +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev.egg-info/dependency_links.txt +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev.egg-info/entry_points.txt +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev.egg-info/requires.txt +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/src/apdev.egg-info/top_level.txt +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/tests/test_check_chars.py +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/tests/test_check_imports.py +0 -0
- {apdev-0.2.3 → apdev-0.2.6}/tests/test_config.py +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apdev
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Shared development tools for Python projects - character validation, circular import detection, and more
|
|
5
|
-
Author-email:
|
|
5
|
+
Author-email: aiperceivable <tercel.yi@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
7
|
-
Project-URL: Homepage, https://
|
|
8
|
-
Project-URL: Documentation, https://github.com/
|
|
9
|
-
Project-URL: Repository, https://github.com/
|
|
10
|
-
Project-URL: Issues, https://github.com/
|
|
7
|
+
Project-URL: Homepage, https://aiperceivable.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/aiperceivable/apdev
|
|
9
|
+
Project-URL: Repository, https://github.com/aiperceivable/apdev
|
|
10
|
+
Project-URL: Issues, https://github.com/aiperceivable/apdev/issues
|
|
11
11
|
Keywords: development-tools,quality-assurance,linting,static-analysis,character-validation,circular-imports,release-automation,unicode-checker,trojan-source-detection
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -86,12 +86,18 @@ apdev check-imports
|
|
|
86
86
|
|
|
87
87
|
Interactive release automation for publishing Python packages to PyPI and GitHub. Auto-detects project name from `pyproject.toml` and GitHub repo from git remote.
|
|
88
88
|
|
|
89
|
+
From the project root, `apdev release` uses the project's `.venv` automatically when no virtual environment is active. Install `build`, `pip`, and `twine` in the environment used for release.
|
|
90
|
+
|
|
89
91
|
```bash
|
|
90
92
|
# Run with auto-detected version from pyproject.toml
|
|
91
93
|
apdev release
|
|
92
94
|
|
|
93
95
|
# Or specify version explicitly
|
|
94
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
|
|
95
101
|
```
|
|
96
102
|
|
|
97
103
|
The command provides an interactive menu with steps:
|
|
@@ -102,7 +108,34 @@ The command provides an interactive menu with steps:
|
|
|
102
108
|
5. Check package (`twine check`)
|
|
103
109
|
6. Create git tag and push
|
|
104
110
|
7. Create GitHub release (via `gh` CLI or API)
|
|
105
|
-
8. Upload to PyPI (`twine upload
|
|
111
|
+
8. Upload to PyPI (`twine upload -r <repository> dist/*`)
|
|
112
|
+
|
|
113
|
+
Which `~/.pypirc` section is used, in order of precedence:
|
|
114
|
+
|
|
115
|
+
1. `--repository NAME` / `-r NAME`
|
|
116
|
+
2. `PYPI_REPOSITORY` environment variable
|
|
117
|
+
3. `[tool.apdev] pypi_repository` in `pyproject.toml`
|
|
118
|
+
4. the default `[pypi]` section
|
|
119
|
+
|
|
120
|
+
The resolved section is printed in the header before anything is uploaded, so a
|
|
121
|
+
second PyPI account is never a guess:
|
|
122
|
+
|
|
123
|
+
```ini
|
|
124
|
+
# ~/.pypirc
|
|
125
|
+
[distutils]
|
|
126
|
+
index-servers =
|
|
127
|
+
pypi
|
|
128
|
+
reachreel
|
|
129
|
+
|
|
130
|
+
[pypi]
|
|
131
|
+
username = __token__
|
|
132
|
+
password = pypi-A... # account A
|
|
133
|
+
|
|
134
|
+
[reachreel]
|
|
135
|
+
repository = https://upload.pypi.org/legacy/
|
|
136
|
+
username = __token__
|
|
137
|
+
password = pypi-B... # account B
|
|
138
|
+
```
|
|
106
139
|
|
|
107
140
|
Override auto-detection with environment variables:
|
|
108
141
|
|
|
@@ -116,22 +149,24 @@ Add to your project's `pyproject.toml` so commands can run without CLI arguments
|
|
|
116
149
|
|
|
117
150
|
```toml
|
|
118
151
|
[tool.apdev]
|
|
119
|
-
base_package = "mypackage"
|
|
120
|
-
src_dir = "src"
|
|
152
|
+
base_package = "mypackage" # Required by check-imports
|
|
153
|
+
src_dir = "src" # Source directory (default: "src")
|
|
154
|
+
pypi_repository = "mypackage" # .pypirc section for `apdev release` (default: "pypi")
|
|
121
155
|
```
|
|
122
156
|
|
|
123
|
-
With this config,
|
|
157
|
+
With this config, the commands work out of the box:
|
|
124
158
|
|
|
125
159
|
```bash
|
|
126
160
|
apdev check-chars # Checks default project directories and config files
|
|
127
161
|
apdev check-imports # Reads base_package / src_dir from pyproject.toml
|
|
162
|
+
apdev release # Reads pypi_repository, so the right PyPI account is used
|
|
128
163
|
```
|
|
129
164
|
|
|
130
165
|
## Pre-commit Integration
|
|
131
166
|
|
|
132
167
|
```yaml
|
|
133
168
|
repos:
|
|
134
|
-
- repo: https://github.com/
|
|
169
|
+
- repo: https://github.com/aiperceivable/apdev
|
|
135
170
|
rev: python/v0.1.0
|
|
136
171
|
hooks:
|
|
137
172
|
- id: check-chars
|
|
@@ -56,12 +56,18 @@ apdev check-imports
|
|
|
56
56
|
|
|
57
57
|
Interactive release automation for publishing Python packages to PyPI and GitHub. Auto-detects project name from `pyproject.toml` and GitHub repo from git remote.
|
|
58
58
|
|
|
59
|
+
From the project root, `apdev release` uses the project's `.venv` automatically when no virtual environment is active. Install `build`, `pip`, and `twine` in the environment used for release.
|
|
60
|
+
|
|
59
61
|
```bash
|
|
60
62
|
# Run with auto-detected version from pyproject.toml
|
|
61
63
|
apdev release
|
|
62
64
|
|
|
63
65
|
# Or specify version explicitly
|
|
64
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
|
|
65
71
|
```
|
|
66
72
|
|
|
67
73
|
The command provides an interactive menu with steps:
|
|
@@ -72,7 +78,34 @@ The command provides an interactive menu with steps:
|
|
|
72
78
|
5. Check package (`twine check`)
|
|
73
79
|
6. Create git tag and push
|
|
74
80
|
7. Create GitHub release (via `gh` CLI or API)
|
|
75
|
-
8. Upload to PyPI (`twine upload
|
|
81
|
+
8. Upload to PyPI (`twine upload -r <repository> dist/*`)
|
|
82
|
+
|
|
83
|
+
Which `~/.pypirc` section is used, in order of precedence:
|
|
84
|
+
|
|
85
|
+
1. `--repository NAME` / `-r NAME`
|
|
86
|
+
2. `PYPI_REPOSITORY` environment variable
|
|
87
|
+
3. `[tool.apdev] pypi_repository` in `pyproject.toml`
|
|
88
|
+
4. the default `[pypi]` section
|
|
89
|
+
|
|
90
|
+
The resolved section is printed in the header before anything is uploaded, so a
|
|
91
|
+
second PyPI account is never a guess:
|
|
92
|
+
|
|
93
|
+
```ini
|
|
94
|
+
# ~/.pypirc
|
|
95
|
+
[distutils]
|
|
96
|
+
index-servers =
|
|
97
|
+
pypi
|
|
98
|
+
reachreel
|
|
99
|
+
|
|
100
|
+
[pypi]
|
|
101
|
+
username = __token__
|
|
102
|
+
password = pypi-A... # account A
|
|
103
|
+
|
|
104
|
+
[reachreel]
|
|
105
|
+
repository = https://upload.pypi.org/legacy/
|
|
106
|
+
username = __token__
|
|
107
|
+
password = pypi-B... # account B
|
|
108
|
+
```
|
|
76
109
|
|
|
77
110
|
Override auto-detection with environment variables:
|
|
78
111
|
|
|
@@ -86,22 +119,24 @@ Add to your project's `pyproject.toml` so commands can run without CLI arguments
|
|
|
86
119
|
|
|
87
120
|
```toml
|
|
88
121
|
[tool.apdev]
|
|
89
|
-
base_package = "mypackage"
|
|
90
|
-
src_dir = "src"
|
|
122
|
+
base_package = "mypackage" # Required by check-imports
|
|
123
|
+
src_dir = "src" # Source directory (default: "src")
|
|
124
|
+
pypi_repository = "mypackage" # .pypirc section for `apdev release` (default: "pypi")
|
|
91
125
|
```
|
|
92
126
|
|
|
93
|
-
With this config,
|
|
127
|
+
With this config, the commands work out of the box:
|
|
94
128
|
|
|
95
129
|
```bash
|
|
96
130
|
apdev check-chars # Checks default project directories and config files
|
|
97
131
|
apdev check-imports # Reads base_package / src_dir from pyproject.toml
|
|
132
|
+
apdev release # Reads pypi_repository, so the right PyPI account is used
|
|
98
133
|
```
|
|
99
134
|
|
|
100
135
|
## Pre-commit Integration
|
|
101
136
|
|
|
102
137
|
```yaml
|
|
103
138
|
repos:
|
|
104
|
-
- repo: https://github.com/
|
|
139
|
+
- repo: https://github.com/aiperceivable/apdev
|
|
105
140
|
rev: python/v0.1.0
|
|
106
141
|
hooks:
|
|
107
142
|
- id: check-chars
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "apdev"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.6"
|
|
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"}
|
|
11
11
|
requires-python = ">=3.10"
|
|
12
12
|
authors = [
|
|
13
|
-
{name = "
|
|
13
|
+
{name = "aiperceivable", email = "tercel.yi@gmail.com"}
|
|
14
14
|
]
|
|
15
15
|
keywords = [
|
|
16
16
|
"development-tools",
|
|
@@ -67,7 +67,7 @@ line-length = 100
|
|
|
67
67
|
select = ["E", "F", "I", "W"]
|
|
68
68
|
|
|
69
69
|
[project.urls]
|
|
70
|
-
Homepage = "https://
|
|
71
|
-
Documentation = "https://github.com/
|
|
72
|
-
Repository = "https://github.com/
|
|
73
|
-
Issues = "https://github.com/
|
|
70
|
+
Homepage = "https://aiperceivable.com"
|
|
71
|
+
Documentation = "https://github.com/aiperceivable/apdev"
|
|
72
|
+
Repository = "https://github.com/aiperceivable/apdev"
|
|
73
|
+
Issues = "https://github.com/aiperceivable/apdev/issues"
|
|
@@ -85,6 +85,15 @@ 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
|
+
"--repository",
|
|
90
|
+
"-r",
|
|
91
|
+
dest="repository",
|
|
92
|
+
help=(
|
|
93
|
+
"Named .pypirc section to upload to (default: [tool.apdev] "
|
|
94
|
+
"pypi_repository, or 'pypi')"
|
|
95
|
+
),
|
|
96
|
+
)
|
|
88
97
|
release_parser.add_argument(
|
|
89
98
|
"version",
|
|
90
99
|
nargs="?",
|
|
@@ -148,9 +157,24 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
148
157
|
cmd = ["bash", str(script)]
|
|
149
158
|
if args.yes:
|
|
150
159
|
cmd.append("--yes")
|
|
160
|
+
repository = args.repository or load_config().get("pypi_repository")
|
|
161
|
+
if repository:
|
|
162
|
+
cmd.extend(["--repository", str(repository)])
|
|
151
163
|
if args.version:
|
|
152
164
|
cmd.append(args.version)
|
|
153
|
-
|
|
165
|
+
release_env = os.environ.copy()
|
|
166
|
+
project_venv = Path.cwd() / ".venv"
|
|
167
|
+
venv_bin = project_venv / "bin"
|
|
168
|
+
if (
|
|
169
|
+
not release_env.get("VIRTUAL_ENV")
|
|
170
|
+
and (project_venv / "pyvenv.cfg").is_file()
|
|
171
|
+
and os.access(venv_bin / "python", os.X_OK)
|
|
172
|
+
):
|
|
173
|
+
release_env["VIRTUAL_ENV"] = str(project_venv)
|
|
174
|
+
release_env["PATH"] = os.pathsep.join(
|
|
175
|
+
(str(venv_bin), release_env.get("PATH") or os.defpath)
|
|
176
|
+
)
|
|
177
|
+
result = subprocess.run(cmd, env=release_env)
|
|
154
178
|
return result.returncode
|
|
155
179
|
|
|
156
180
|
return 0
|
|
@@ -6,19 +6,33 @@
|
|
|
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").
|
|
10
11
|
|
|
11
12
|
# Note: set -e is disabled to allow step-by-step execution
|
|
12
13
|
# Individual steps will handle their own error handling
|
|
13
14
|
|
|
14
15
|
# Silent mode flag (--yes or -y to auto-accept all defaults)
|
|
15
16
|
SILENT=false
|
|
17
|
+
PYPI_REPOSITORY="${PYPI_REPOSITORY:-}"
|
|
16
18
|
POSITIONAL_ARGS=()
|
|
17
|
-
|
|
18
|
-
case "$
|
|
19
|
+
while [ "$#" -gt 0 ]; do
|
|
20
|
+
case "$1" in
|
|
19
21
|
--yes|-y) SILENT=true ;;
|
|
20
|
-
|
|
22
|
+
--repository|-r)
|
|
23
|
+
if [ "$#" -lt 2 ] || [ -z "$2" ]; then
|
|
24
|
+
echo "Error: --repository needs a .pypirc section name" >&2
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
PYPI_REPOSITORY="$2"
|
|
28
|
+
shift
|
|
29
|
+
;;
|
|
30
|
+
--repository=*)
|
|
31
|
+
PYPI_REPOSITORY="${1#*=}"
|
|
32
|
+
;;
|
|
33
|
+
*) POSITIONAL_ARGS+=("$1") ;;
|
|
21
34
|
esac
|
|
35
|
+
shift
|
|
22
36
|
done
|
|
23
37
|
set -- "${POSITIONAL_ARGS[@]}"
|
|
24
38
|
|
|
@@ -58,6 +72,25 @@ if [ -z "$GITHUB_REPO" ]; then
|
|
|
58
72
|
fi
|
|
59
73
|
fi
|
|
60
74
|
|
|
75
|
+
# PyPI repository: --repository, then PYPI_REPOSITORY, then [tool.apdev]
|
|
76
|
+
# pypi_repository, then the default "pypi" section of ~/.pypirc.
|
|
77
|
+
#
|
|
78
|
+
# Parsed with awk instead of tomllib so the script works on any machine, even
|
|
79
|
+
# one whose `python3` is older than 3.11.
|
|
80
|
+
if [ -z "$PYPI_REPOSITORY" ] && [ -f pyproject.toml ]; then
|
|
81
|
+
PYPI_REPOSITORY=$(awk '
|
|
82
|
+
/^[[:space:]]*\[/ {
|
|
83
|
+
in_apdev = ($0 ~ /^[[:space:]]*\[tool\.apdev\][[:space:]]*$/)
|
|
84
|
+
next
|
|
85
|
+
}
|
|
86
|
+
in_apdev && /^[[:space:]]*pypi_repository[[:space:]]*=/ {
|
|
87
|
+
print
|
|
88
|
+
exit
|
|
89
|
+
}
|
|
90
|
+
' pyproject.toml | sed -E 's/^[^=]*=[[:space:]]*//; s/[[:space:]]+$//; s/^"//; s/"$//; s/^\x27//; s/\x27$//')
|
|
91
|
+
fi
|
|
92
|
+
PYPI_REPOSITORY="${PYPI_REPOSITORY:-pypi}"
|
|
93
|
+
|
|
61
94
|
# Get version from argument or pyproject.toml
|
|
62
95
|
if [ -z "$1" ]; then
|
|
63
96
|
VERSION=$(grep -E '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/')
|
|
@@ -77,6 +110,7 @@ echo -e "${CYAN}║ ${PROJECT_NAME} Release Script v${VERSION}${NC}"
|
|
|
77
110
|
echo -e "${CYAN}╚══════════════════════════════════════════════════════════╝${NC}"
|
|
78
111
|
echo -e " Project: ${CYAN}${PROJECT_NAME}${NC}"
|
|
79
112
|
[ -n "$GITHUB_REPO" ] && echo -e " GitHub: ${CYAN}${GITHUB_REPO}${NC}"
|
|
113
|
+
echo -e " PyPI: ${CYAN}${PYPI_REPOSITORY}${NC}"
|
|
80
114
|
echo ""
|
|
81
115
|
|
|
82
116
|
# Function to check if step is already done
|
|
@@ -754,15 +788,15 @@ step7_upload_pypi() {
|
|
|
754
788
|
fi
|
|
755
789
|
|
|
756
790
|
if ask_yn "Upload to PyPI?" "y"; then
|
|
757
|
-
echo -e "${YELLOW}Uploading to PyPI...${NC}"
|
|
758
|
-
if ! twine upload dist/*; then
|
|
791
|
+
echo -e "${YELLOW}Uploading to PyPI (${PYPI_REPOSITORY})...${NC}"
|
|
792
|
+
if ! twine upload -r "$PYPI_REPOSITORY" dist/*; then
|
|
759
793
|
echo -e "${RED}❌ Upload to PyPI failed${NC}"
|
|
760
794
|
return 1
|
|
761
795
|
fi
|
|
762
796
|
echo -e "${GREEN}✅ Successfully uploaded to PyPI!${NC}"
|
|
763
797
|
else
|
|
764
798
|
echo -e "${YELLOW}⚠️ Skipped PyPI upload${NC}"
|
|
765
|
-
echo -e "${CYAN} Upload manually with: twine upload dist/*${NC}"
|
|
799
|
+
echo -e "${CYAN} Upload manually with: twine upload -r ${PYPI_REPOSITORY} dist/*${NC}"
|
|
766
800
|
fi
|
|
767
801
|
else
|
|
768
802
|
echo -e "${YELLOW}⚠️ Skipped PyPI upload (version already exists)${NC}"
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apdev
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Shared development tools for Python projects - character validation, circular import detection, and more
|
|
5
|
-
Author-email:
|
|
5
|
+
Author-email: aiperceivable <tercel.yi@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
7
|
-
Project-URL: Homepage, https://
|
|
8
|
-
Project-URL: Documentation, https://github.com/
|
|
9
|
-
Project-URL: Repository, https://github.com/
|
|
10
|
-
Project-URL: Issues, https://github.com/
|
|
7
|
+
Project-URL: Homepage, https://aiperceivable.com
|
|
8
|
+
Project-URL: Documentation, https://github.com/aiperceivable/apdev
|
|
9
|
+
Project-URL: Repository, https://github.com/aiperceivable/apdev
|
|
10
|
+
Project-URL: Issues, https://github.com/aiperceivable/apdev/issues
|
|
11
11
|
Keywords: development-tools,quality-assurance,linting,static-analysis,character-validation,circular-imports,release-automation,unicode-checker,trojan-source-detection
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -86,12 +86,18 @@ apdev check-imports
|
|
|
86
86
|
|
|
87
87
|
Interactive release automation for publishing Python packages to PyPI and GitHub. Auto-detects project name from `pyproject.toml` and GitHub repo from git remote.
|
|
88
88
|
|
|
89
|
+
From the project root, `apdev release` uses the project's `.venv` automatically when no virtual environment is active. Install `build`, `pip`, and `twine` in the environment used for release.
|
|
90
|
+
|
|
89
91
|
```bash
|
|
90
92
|
# Run with auto-detected version from pyproject.toml
|
|
91
93
|
apdev release
|
|
92
94
|
|
|
93
95
|
# Or specify version explicitly
|
|
94
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
|
|
95
101
|
```
|
|
96
102
|
|
|
97
103
|
The command provides an interactive menu with steps:
|
|
@@ -102,7 +108,34 @@ The command provides an interactive menu with steps:
|
|
|
102
108
|
5. Check package (`twine check`)
|
|
103
109
|
6. Create git tag and push
|
|
104
110
|
7. Create GitHub release (via `gh` CLI or API)
|
|
105
|
-
8. Upload to PyPI (`twine upload
|
|
111
|
+
8. Upload to PyPI (`twine upload -r <repository> dist/*`)
|
|
112
|
+
|
|
113
|
+
Which `~/.pypirc` section is used, in order of precedence:
|
|
114
|
+
|
|
115
|
+
1. `--repository NAME` / `-r NAME`
|
|
116
|
+
2. `PYPI_REPOSITORY` environment variable
|
|
117
|
+
3. `[tool.apdev] pypi_repository` in `pyproject.toml`
|
|
118
|
+
4. the default `[pypi]` section
|
|
119
|
+
|
|
120
|
+
The resolved section is printed in the header before anything is uploaded, so a
|
|
121
|
+
second PyPI account is never a guess:
|
|
122
|
+
|
|
123
|
+
```ini
|
|
124
|
+
# ~/.pypirc
|
|
125
|
+
[distutils]
|
|
126
|
+
index-servers =
|
|
127
|
+
pypi
|
|
128
|
+
reachreel
|
|
129
|
+
|
|
130
|
+
[pypi]
|
|
131
|
+
username = __token__
|
|
132
|
+
password = pypi-A... # account A
|
|
133
|
+
|
|
134
|
+
[reachreel]
|
|
135
|
+
repository = https://upload.pypi.org/legacy/
|
|
136
|
+
username = __token__
|
|
137
|
+
password = pypi-B... # account B
|
|
138
|
+
```
|
|
106
139
|
|
|
107
140
|
Override auto-detection with environment variables:
|
|
108
141
|
|
|
@@ -116,22 +149,24 @@ Add to your project's `pyproject.toml` so commands can run without CLI arguments
|
|
|
116
149
|
|
|
117
150
|
```toml
|
|
118
151
|
[tool.apdev]
|
|
119
|
-
base_package = "mypackage"
|
|
120
|
-
src_dir = "src"
|
|
152
|
+
base_package = "mypackage" # Required by check-imports
|
|
153
|
+
src_dir = "src" # Source directory (default: "src")
|
|
154
|
+
pypi_repository = "mypackage" # .pypirc section for `apdev release` (default: "pypi")
|
|
121
155
|
```
|
|
122
156
|
|
|
123
|
-
With this config,
|
|
157
|
+
With this config, the commands work out of the box:
|
|
124
158
|
|
|
125
159
|
```bash
|
|
126
160
|
apdev check-chars # Checks default project directories and config files
|
|
127
161
|
apdev check-imports # Reads base_package / src_dir from pyproject.toml
|
|
162
|
+
apdev release # Reads pypi_repository, so the right PyPI account is used
|
|
128
163
|
```
|
|
129
164
|
|
|
130
165
|
## Pre-commit Integration
|
|
131
166
|
|
|
132
167
|
```yaml
|
|
133
168
|
repos:
|
|
134
|
-
- repo: https://github.com/
|
|
169
|
+
- repo: https://github.com/aiperceivable/apdev
|
|
135
170
|
rev: python/v0.1.0
|
|
136
171
|
hooks:
|
|
137
172
|
- id: check-chars
|
|
@@ -5,6 +5,11 @@ import subprocess
|
|
|
5
5
|
import sys
|
|
6
6
|
import textwrap
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from unittest.mock import Mock
|
|
9
|
+
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from apdev import cli
|
|
8
13
|
|
|
9
14
|
|
|
10
15
|
def run_apdev(*args: str, cwd: str | Path | None = None) -> subprocess.CompletedProcess[str]:
|
|
@@ -26,6 +31,114 @@ def test_cli_help() -> None:
|
|
|
26
31
|
assert "release" in result.stdout
|
|
27
32
|
|
|
28
33
|
|
|
34
|
+
@pytest.mark.parametrize(
|
|
35
|
+
("local_venv", "active_venv"), [(True, False), (True, True), (False, False)]
|
|
36
|
+
)
|
|
37
|
+
def test_cli_release_selects_project_virtualenv(
|
|
38
|
+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, local_venv: bool, active_venv: bool
|
|
39
|
+
) -> None:
|
|
40
|
+
monkeypatch.chdir(tmp_path)
|
|
41
|
+
project_venv = Path.cwd() / ".venv"
|
|
42
|
+
if local_venv:
|
|
43
|
+
(project_venv / "bin").mkdir(parents=True)
|
|
44
|
+
(project_venv / "pyvenv.cfg").touch()
|
|
45
|
+
python = project_venv / "bin" / "python"
|
|
46
|
+
python.touch()
|
|
47
|
+
python.chmod(0o755)
|
|
48
|
+
original_path = os.defpath
|
|
49
|
+
if active_venv:
|
|
50
|
+
active_path = str(tmp_path / "active")
|
|
51
|
+
monkeypatch.setenv("VIRTUAL_ENV", active_path)
|
|
52
|
+
original_path = os.pathsep.join((str(Path(active_path) / "bin"), original_path))
|
|
53
|
+
else:
|
|
54
|
+
monkeypatch.delenv("VIRTUAL_ENV", raising=False)
|
|
55
|
+
monkeypatch.setenv("PATH", original_path)
|
|
56
|
+
run = Mock(return_value=subprocess.CompletedProcess(args=[], returncode=0))
|
|
57
|
+
monkeypatch.setattr(cli.subprocess, "run", run)
|
|
58
|
+
|
|
59
|
+
assert cli.main(["release", "--yes", "0.1.0"]) == 0
|
|
60
|
+
|
|
61
|
+
run.assert_called_once()
|
|
62
|
+
args = run.call_args.args[0]
|
|
63
|
+
assert args[0] == "bash"
|
|
64
|
+
assert args[2:] == ["--yes", "0.1.0"]
|
|
65
|
+
env = run.call_args.kwargs["env"]
|
|
66
|
+
if local_venv and not active_venv:
|
|
67
|
+
assert env["PATH"] == os.pathsep.join((str(project_venv / "bin"), original_path))
|
|
68
|
+
assert env["VIRTUAL_ENV"] == str(project_venv)
|
|
69
|
+
assert "VIRTUAL_ENV" not in os.environ
|
|
70
|
+
else:
|
|
71
|
+
assert env["PATH"] == original_path
|
|
72
|
+
assert env.get("VIRTUAL_ENV") == os.environ.get("VIRTUAL_ENV")
|
|
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
|
+
|
|
29
142
|
def test_cli_check_chars_clean(tmp_path: Path) -> None:
|
|
30
143
|
"""apdev check-chars returns 0 for clean files."""
|
|
31
144
|
f = tmp_path / "ok.py"
|
|
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
|