package-foundry 26.11.3__py3-none-any.whl
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.
- package_foundry/__init__.py +3 -0
- package_foundry/cli.py +431 -0
- package_foundry/metadata/__init__.py +0 -0
- package_foundry/metadata/author.py +7 -0
- package_foundry/metadata/constants.py +57 -0
- package_foundry/metadata/executables.py +7 -0
- package_foundry/metadata/maintainer.py +8 -0
- package_foundry/metadata/package.py +46 -0
- package_foundry/metadata/readme.py +9 -0
- package_foundry/metadata/ruff_ignored_inspection.py +13 -0
- package_foundry/templates/.editorconfig.tpl +17 -0
- package_foundry/templates/.github/ISSUE_TEMPLATE/bug_report.md.tpl +34 -0
- package_foundry/templates/.github/ISSUE_TEMPLATE/config.yml.tpl +5 -0
- package_foundry/templates/.github/ISSUE_TEMPLATE/feature_request.md.tpl +25 -0
- package_foundry/templates/.github/PULL_REQUEST_TEMPLATE.md.tpl +20 -0
- package_foundry/templates/.github/workflows/ci.yml.tpl +11 -0
- package_foundry/templates/.github/workflows/quality-gate.yml.tpl +105 -0
- package_foundry/templates/.github/workflows/release.yml.tpl +136 -0
- package_foundry/templates/.gitignore.tpl +167 -0
- package_foundry/templates/.pre-commit-config.yaml.tpl +60 -0
- package_foundry/templates/.readthedocs.yaml.tpl +33 -0
- package_foundry/templates/CODE_OF_CONDUCT.md.tpl +132 -0
- package_foundry/templates/CONTRIBUTING.md.tpl +76 -0
- package_foundry/templates/MANIFEST.in.tpl +4 -0
- package_foundry/templates/README.md.tpl +8 -0
- package_foundry/templates/SECURITY.md.tpl +18 -0
- package_foundry/templates/docs/Makefile.tpl +20 -0
- package_foundry/templates/docs/conf.py.tpl +77 -0
- package_foundry/templates/docs/make.bat.tpl +35 -0
- package_foundry/templates/pyproject.toml.tpl +263 -0
- package_foundry/templates/scripts/unix/install_requirements.sh.tpl +3 -0
- package_foundry/templates/scripts/unix/publish_to_pypi.sh.tpl +4 -0
- package_foundry/templates/scripts/windows/install_requirements.ps1.tpl +2 -0
- package_foundry/templates/scripts/windows/publish_to_pypi.ps1.tpl +3 -0
- package_foundry/templates/snippets/badges.tpl +6 -0
- package_foundry/templates/snippets/content.tpl +1 -0
- package_foundry/templates/snippets/empty.tpl +0 -0
- package_foundry/templates/snippets/installation.tpl +24 -0
- package_foundry/templates/snippets/licenses/GPL.md +1347 -0
- package_foundry/templates/snippets/licenses/MIT.md +21 -0
- package_foundry/templates/snippets/links.tpl +3 -0
- package_foundry/templates/snippets/maintenance.tpl +8 -0
- package_foundry/templates/snippets/publish.tpl +33 -0
- package_foundry/templates/snippets/tagline.tpl +1 -0
- package_foundry-26.11.3.dist-info/METADATA +274 -0
- package_foundry-26.11.3.dist-info/RECORD +49 -0
- package_foundry-26.11.3.dist-info/WHEEL +4 -0
- package_foundry-26.11.3.dist-info/entry_points.txt +2 -0
- package_foundry-26.11.3.dist-info/licenses/LICENSE.md +21 -0
package_foundry/cli.py
ADDED
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
from datetime import UTC, datetime
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
from os.path import basename
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
|
12
|
+
|
|
13
|
+
from package_foundry.metadata.constants import (
|
|
14
|
+
DJANGO_PYTHON_COMPATIBILITY,
|
|
15
|
+
LICENSE_GPL,
|
|
16
|
+
READTHEDOCS_PYTHON_VERSIONS,
|
|
17
|
+
)
|
|
18
|
+
from package_foundry.metadata.package import PackageMetadata
|
|
19
|
+
|
|
20
|
+
BASE_PATH = Path(__file__).parent
|
|
21
|
+
TEMPLATE_PATH = BASE_PATH / "templates"
|
|
22
|
+
|
|
23
|
+
CONFIG_DIR = Path(".package-foundry")
|
|
24
|
+
LEGACY_CONFIG_DIR = Path(".ambient-package-update")
|
|
25
|
+
# Package and module names of the ambient-package-update distribution, mapped to their package-foundry counterparts
|
|
26
|
+
LEGACY_NAMES = {
|
|
27
|
+
"ambient_package_update": "package_foundry",
|
|
28
|
+
"ambient-package-update": "package-foundry",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
app = typer.Typer()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@app.command()
|
|
35
|
+
def get_metadata() -> PackageMetadata:
|
|
36
|
+
"""
|
|
37
|
+
Load and return the PackageMetadata instance from the target package's
|
|
38
|
+
.package-foundry/metadata.py file.
|
|
39
|
+
|
|
40
|
+
Packages still configured for ambient-package-update are pointed to the migrate command.
|
|
41
|
+
"""
|
|
42
|
+
if not CONFIG_DIR.exists() and LEGACY_CONFIG_DIR.exists():
|
|
43
|
+
raise RuntimeError(
|
|
44
|
+
f'Found "{LEGACY_CONFIG_DIR}" from ambient-package-update. Run "package-foundry migrate" to move it to '
|
|
45
|
+
f'"{CONFIG_DIR}".'
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
sys.path.append(f"./{CONFIG_DIR}")
|
|
49
|
+
try:
|
|
50
|
+
m = import_module("metadata")
|
|
51
|
+
except ModuleNotFoundError as e:
|
|
52
|
+
if e.name == "metadata":
|
|
53
|
+
raise RuntimeError(f'Please create a directory "{CONFIG_DIR}" and add a "metadata.py".') from e
|
|
54
|
+
if e.name and e.name.split(".")[0] in LEGACY_NAMES:
|
|
55
|
+
raise RuntimeError(
|
|
56
|
+
f'"{CONFIG_DIR / "metadata.py"}" imports from "{e.name}". Run "package-foundry migrate" to switch it '
|
|
57
|
+
f'to "package_foundry".'
|
|
58
|
+
) from e
|
|
59
|
+
raise
|
|
60
|
+
finally:
|
|
61
|
+
sys.path.pop()
|
|
62
|
+
|
|
63
|
+
return m.METADATA
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_unsupported_version_combinations(*, python_versions: list[str], django_versions: list[str]) -> list[tuple]:
|
|
67
|
+
"""
|
|
68
|
+
Return the (python_version, django_version) pairs that Django does not support upstream.
|
|
69
|
+
|
|
70
|
+
Both version sets have to be covered by DJANGO_PYTHON_COMPATIBILITY. A version the map
|
|
71
|
+
does not know about aborts rendering, because either direction would otherwise degrade
|
|
72
|
+
silently: an unmapped Django version yields no exclusions and renders a matrix whose
|
|
73
|
+
dependencies cannot resolve, while an unmapped Python version is excluded everywhere and
|
|
74
|
+
renders a matrix that quietly tests nothing.
|
|
75
|
+
|
|
76
|
+
For the same reason, a Python version that none of the given Django versions supports
|
|
77
|
+
aborts rendering: the package would advertise it while the matrix never runs it.
|
|
78
|
+
"""
|
|
79
|
+
unmapped_django_versions = [version for version in django_versions if version not in DJANGO_PYTHON_COMPATIBILITY]
|
|
80
|
+
known_python_versions = {
|
|
81
|
+
version for compatible_versions in DJANGO_PYTHON_COMPATIBILITY.values() for version in compatible_versions
|
|
82
|
+
}
|
|
83
|
+
unmapped_python_versions = [version for version in python_versions if version not in known_python_versions]
|
|
84
|
+
|
|
85
|
+
if unmapped_django_versions or unmapped_python_versions:
|
|
86
|
+
unmapped = [f"Django {version}" for version in unmapped_django_versions] + [
|
|
87
|
+
f"Python {version}" for version in unmapped_python_versions
|
|
88
|
+
]
|
|
89
|
+
raise RuntimeError(
|
|
90
|
+
f"{', '.join(unmapped)} missing from DJANGO_PYTHON_COMPATIBILITY. Add the version there so the "
|
|
91
|
+
f"rendered CI matrix covers the supported combinations and excludes the unsupported ones."
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
untested_python_versions = []
|
|
95
|
+
if django_versions:
|
|
96
|
+
untested_python_versions = [
|
|
97
|
+
python_version
|
|
98
|
+
for python_version in python_versions
|
|
99
|
+
if all(python_version not in DJANGO_PYTHON_COMPATIBILITY[version] for version in django_versions)
|
|
100
|
+
]
|
|
101
|
+
if untested_python_versions:
|
|
102
|
+
raise RuntimeError(
|
|
103
|
+
f"Python {', '.join(untested_python_versions)} is not supported by any of the Django versions "
|
|
104
|
+
f"{', '.join(django_versions)}, so the rendered CI matrix would never test it. Remove it from "
|
|
105
|
+
f"supported_python_versions or add a Django version that supports it to supported_django_versions."
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return [
|
|
109
|
+
(python_version, django_version)
|
|
110
|
+
for django_version in django_versions
|
|
111
|
+
for python_version in python_versions
|
|
112
|
+
if python_version not in DJANGO_PYTHON_COMPATIBILITY[django_version]
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def get_readthedocs_python_version(*, python_versions: list[str]) -> str:
|
|
117
|
+
"""
|
|
118
|
+
Return the newest of python_versions that Read the Docs offers as build.tools.python.
|
|
119
|
+
|
|
120
|
+
Read the Docs adds new interpreters some time after their release, so the newest supported
|
|
121
|
+
Python version is not necessarily available there yet.
|
|
122
|
+
"""
|
|
123
|
+
available_versions = [version for version in python_versions if version in READTHEDOCS_PYTHON_VERSIONS]
|
|
124
|
+
if not available_versions:
|
|
125
|
+
raise RuntimeError(
|
|
126
|
+
f"None of the Python versions {', '.join(python_versions)} is in READTHEDOCS_PYTHON_VERSIONS. Add the "
|
|
127
|
+
f"versions Read the Docs offers as build.tools.python there."
|
|
128
|
+
)
|
|
129
|
+
return available_versions[-1]
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def create_rendered_file(*, template: Path | str, relative_target_path: Path | str) -> None:
|
|
133
|
+
"""
|
|
134
|
+
Render a single Jinja2 template and write the result to relative_target_path.
|
|
135
|
+
|
|
136
|
+
The Jinja2 environment searches .package-foundry/templates/ first, then the
|
|
137
|
+
built-in templates directory, so local overrides take precedence. Template globals
|
|
138
|
+
(version, current_year, license_label) are injected alongside the package metadata.
|
|
139
|
+
Output is post-processed to collapse consecutive blank lines and ensure a single
|
|
140
|
+
trailing newline.
|
|
141
|
+
"""
|
|
142
|
+
metadata_dict = get_metadata().__dict__
|
|
143
|
+
|
|
144
|
+
# Special case: We might want to set an explicit GitHub package name
|
|
145
|
+
metadata_dict["github_package_name"] = metadata_dict["github_package_name"] or metadata_dict["package_name"]
|
|
146
|
+
|
|
147
|
+
metadata_dict["unsupported_version_combinations"] = get_unsupported_version_combinations(
|
|
148
|
+
python_versions=metadata_dict["supported_python_versions"],
|
|
149
|
+
django_versions=metadata_dict["supported_django_versions"],
|
|
150
|
+
)
|
|
151
|
+
metadata_dict["readthedocs_python_version"] = get_readthedocs_python_version(
|
|
152
|
+
python_versions=metadata_dict["supported_python_versions"],
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
env = Environment(
|
|
156
|
+
loader=FileSystemLoader(
|
|
157
|
+
[
|
|
158
|
+
CONFIG_DIR / "templates",
|
|
159
|
+
TEMPLATE_PATH,
|
|
160
|
+
]
|
|
161
|
+
),
|
|
162
|
+
autoescape=select_autoescape(),
|
|
163
|
+
keep_trailing_newline=True,
|
|
164
|
+
lstrip_blocks=True,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
j2_template = env.get_template(str(template).replace("\\", "/"))
|
|
168
|
+
|
|
169
|
+
# Get version from file
|
|
170
|
+
regex = r'__version__\s*=\s*"(\d+\.\d+\.\d+)"'
|
|
171
|
+
with open(Path.cwd() / metadata_dict["module_name"] / "__init__.py") as f:
|
|
172
|
+
match = re.search(regex, f.read())
|
|
173
|
+
if match:
|
|
174
|
+
j2_template.globals["version"] = match[1]
|
|
175
|
+
|
|
176
|
+
j2_template.globals["current_year"] = datetime.now(tz=UTC).date().year
|
|
177
|
+
j2_template.globals["license_label"] = (
|
|
178
|
+
"GNU General Public License (GPL)" if metadata_dict["license"] == LICENSE_GPL else "MIT License"
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
print(f"> Rendering template {basename(template)!r}...")
|
|
182
|
+
rendered_string = j2_template.render(metadata_dict)
|
|
183
|
+
|
|
184
|
+
# Post-processing: Remove multiple newlines
|
|
185
|
+
rendered_string = re.sub(r"\n{2,}", "\n\n", rendered_string)
|
|
186
|
+
|
|
187
|
+
# Post-processing: Ensure one newline at file end
|
|
188
|
+
rendered_string = re.sub(r"\n{2}$", "\n", rendered_string)
|
|
189
|
+
|
|
190
|
+
# Create missing directories
|
|
191
|
+
relative_target_dir = os.path.dirname(relative_target_path)
|
|
192
|
+
if relative_target_dir:
|
|
193
|
+
os.makedirs(os.path.dirname(relative_target_path), exist_ok=True)
|
|
194
|
+
|
|
195
|
+
with open(relative_target_path, "w") as f:
|
|
196
|
+
f.write(rendered_string)
|
|
197
|
+
|
|
198
|
+
abs_path = Path(relative_target_path).resolve()
|
|
199
|
+
print(f'> Successfully rendered template "{abs_path}".')
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def get_template_list(*, include_snippets: bool = False) -> list[str]:
|
|
203
|
+
"""
|
|
204
|
+
Return relative template paths from the built-in templates directory.
|
|
205
|
+
|
|
206
|
+
Snippets are excluded by default. Pass include_snippets=True to include them
|
|
207
|
+
(used by eject_template to list all ejectable templates).
|
|
208
|
+
"""
|
|
209
|
+
return [
|
|
210
|
+
str(Path(Path(path).relative_to(TEMPLATE_PATH), file))
|
|
211
|
+
for path, subdirs, files in os.walk(TEMPLATE_PATH)
|
|
212
|
+
for file in files
|
|
213
|
+
if include_snippets or "snippets" not in path
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def get_local_template_list(*, include_snippets: bool = False) -> list[str]:
|
|
218
|
+
"""
|
|
219
|
+
Return relative template paths from the target package's local template directory
|
|
220
|
+
(.package-foundry/templates/).
|
|
221
|
+
|
|
222
|
+
These are package-specific templates that have no built-in counterpart, such as
|
|
223
|
+
extra documentation pages. Returns an empty list if the directory does not exist.
|
|
224
|
+
Snippets are excluded by default.
|
|
225
|
+
"""
|
|
226
|
+
local_template_path = CONFIG_DIR / "templates"
|
|
227
|
+
if not local_template_path.exists():
|
|
228
|
+
return []
|
|
229
|
+
return [
|
|
230
|
+
str(Path(Path(path).relative_to(local_template_path), file))
|
|
231
|
+
for path, subdirs, files in os.walk(local_template_path)
|
|
232
|
+
for file in files
|
|
233
|
+
if include_snippets or "snippets" not in path
|
|
234
|
+
]
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def setup_package_basics(metadata_dict: dict) -> None:
|
|
238
|
+
"""
|
|
239
|
+
Create package folder and __init__.py with claim and version if they don't exist.
|
|
240
|
+
Updates claim in existing __init__.py files.
|
|
241
|
+
"""
|
|
242
|
+
module_name = metadata_dict["module_name"]
|
|
243
|
+
module_path = Path.cwd() / module_name
|
|
244
|
+
|
|
245
|
+
# Create module folder if it doesn't exist
|
|
246
|
+
if not module_path.exists():
|
|
247
|
+
print(f"> Creating module directory '{module_name}'...")
|
|
248
|
+
module_path.mkdir(parents=True, exist_ok=True)
|
|
249
|
+
|
|
250
|
+
# Check for __init__.py and create if missing
|
|
251
|
+
init_file = module_path / "__init__.py"
|
|
252
|
+
if not init_file.exists():
|
|
253
|
+
print("> Creating __init__.py with claim and version...")
|
|
254
|
+
init_file.write_text(f'"""{metadata_dict["claim"]}"""\n\n__version__ = "1.0.0"\n')
|
|
255
|
+
else:
|
|
256
|
+
print("> Updating __init__.py claim...")
|
|
257
|
+
content = init_file.read_text()
|
|
258
|
+
|
|
259
|
+
# Extract existing version if present
|
|
260
|
+
regex = r'__version__\s*=\s*"(\d+\.\d+\.\d+)"'
|
|
261
|
+
match = re.search(regex, content)
|
|
262
|
+
version = match[1] if match else "1.0.0"
|
|
263
|
+
|
|
264
|
+
# Replace claim at the beginning (first docstring)
|
|
265
|
+
content = re.sub(r'^""".*?"""', f'"""{metadata_dict["claim"]}"""', content, count=1, flags=re.DOTALL)
|
|
266
|
+
|
|
267
|
+
# Ensure __version__ is present
|
|
268
|
+
if not re.search(regex, content):
|
|
269
|
+
# Add version after the docstring
|
|
270
|
+
content = re.sub(
|
|
271
|
+
r'^(""".*?""")\s*', rf'\1\n\n__version__ = "{version}"\n', content, count=1, flags=re.DOTALL
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
init_file.write_text(content)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
@app.command()
|
|
278
|
+
def render_templates():
|
|
279
|
+
"""
|
|
280
|
+
Render all templates into the target package.
|
|
281
|
+
|
|
282
|
+
Built-in templates and local package-specific templates are merged; if both define
|
|
283
|
+
the same path, the local version takes precedence (handled by Jinja2's loader
|
|
284
|
+
ordering). The LICENSE.md file is rendered separately as it is chosen conditionally
|
|
285
|
+
based on the configured license type.
|
|
286
|
+
"""
|
|
287
|
+
# Collect all template files; local templates shadow built-in ones with the same path
|
|
288
|
+
template_list = list(dict.fromkeys([*get_template_list(), *get_local_template_list()]))
|
|
289
|
+
|
|
290
|
+
for template in template_list:
|
|
291
|
+
print(f"> Found template {template!r}...")
|
|
292
|
+
|
|
293
|
+
print("Start rending distribution templates.")
|
|
294
|
+
|
|
295
|
+
for template in template_list:
|
|
296
|
+
create_rendered_file(
|
|
297
|
+
template=template,
|
|
298
|
+
relative_target_path=template.removesuffix(".tpl"),
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
# The licence file is conditional, so we have to render it separately
|
|
302
|
+
metadata_dict = get_metadata().__dict__
|
|
303
|
+
create_rendered_file(
|
|
304
|
+
template=f"snippets/licenses/{metadata_dict['license']}.md",
|
|
305
|
+
relative_target_path="LICENSE.md",
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
# Package basics
|
|
309
|
+
setup_package_basics(metadata_dict)
|
|
310
|
+
|
|
311
|
+
print("Rendering finished.")
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
@app.command()
|
|
315
|
+
def build_docs(package_name: str):
|
|
316
|
+
"""
|
|
317
|
+
Build Sphinx HTML documentation for the given package by running sphinx-build
|
|
318
|
+
in its docs/ directory.
|
|
319
|
+
"""
|
|
320
|
+
print(f'Building docs for package "{package_name}"')
|
|
321
|
+
subprocess.call(f"cd ../{package_name} && sphinx-build docs/ docs/_build/html/", shell=True)
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
@app.command()
|
|
325
|
+
def run_tests():
|
|
326
|
+
"""
|
|
327
|
+
Install the target package's dependencies and run its test suite with pytest.
|
|
328
|
+
"""
|
|
329
|
+
print("Running tests")
|
|
330
|
+
|
|
331
|
+
package_data = get_metadata()
|
|
332
|
+
dependency_list = package_data.dependencies
|
|
333
|
+
|
|
334
|
+
if package_data.optional_dependencies:
|
|
335
|
+
for opt_dependency in package_data.optional_dependencies.values():
|
|
336
|
+
dependency_list += opt_dependency
|
|
337
|
+
|
|
338
|
+
dependency_list = " ".join(f'"{d}"' for d in dependency_list)
|
|
339
|
+
subprocess.call(f"pip install {dependency_list}", shell=True)
|
|
340
|
+
|
|
341
|
+
django_settings = "--ds settings " if package_data.tests_require_django else ""
|
|
342
|
+
subprocess.call(f"pytest {django_settings}tests", shell=True)
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
@app.command()
|
|
346
|
+
def eject_template():
|
|
347
|
+
"""
|
|
348
|
+
Interactively copy a built-in template into .package-foundry/templates/ so
|
|
349
|
+
the target package can customise it. Only built-in templates are listed; locally
|
|
350
|
+
overridden templates are already present in that directory.
|
|
351
|
+
"""
|
|
352
|
+
template_list = get_template_list(include_snippets=True)
|
|
353
|
+
|
|
354
|
+
for i, template in enumerate(template_list, start=1):
|
|
355
|
+
print(f"{i:>2}) {template}")
|
|
356
|
+
|
|
357
|
+
template_no = typer.prompt("Choose template")
|
|
358
|
+
template_no = int(template_no)
|
|
359
|
+
|
|
360
|
+
if template_no > len(template_list):
|
|
361
|
+
raise typer.Abort("Invalid template number")
|
|
362
|
+
|
|
363
|
+
print(f"Ejecting template {template_list[template_no - 1]}")
|
|
364
|
+
|
|
365
|
+
template = template_list[template_no - 1]
|
|
366
|
+
|
|
367
|
+
contents = Path(TEMPLATE_PATH / template).read_text()
|
|
368
|
+
|
|
369
|
+
output = CONFIG_DIR / "templates" / template
|
|
370
|
+
os.makedirs(output.parent, exist_ok=True)
|
|
371
|
+
output.write_text(contents)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
@app.command()
|
|
375
|
+
def migrate():
|
|
376
|
+
"""
|
|
377
|
+
Move the target package from ambient-package-update to package-foundry.
|
|
378
|
+
|
|
379
|
+
Renames .ambient-package-update/ to .package-foundry/ and replaces the ambient-package-update
|
|
380
|
+
package and module names in every file inside it, i.e. metadata.py and ejected templates.
|
|
381
|
+
Running it again on an already migrated package only repeats the replacement, so an interrupted
|
|
382
|
+
migration can be finished. Run render-templates afterwards so the rendered files pick up the new names.
|
|
383
|
+
"""
|
|
384
|
+
if LEGACY_CONFIG_DIR.exists():
|
|
385
|
+
if CONFIG_DIR.exists():
|
|
386
|
+
typer.secho(
|
|
387
|
+
f'Both "{LEGACY_CONFIG_DIR}" and "{CONFIG_DIR}" exist. Move the remaining files from '
|
|
388
|
+
f'"{LEGACY_CONFIG_DIR}" to "{CONFIG_DIR}", delete it and run this command again.',
|
|
389
|
+
fg=typer.colors.RED,
|
|
390
|
+
err=True,
|
|
391
|
+
)
|
|
392
|
+
raise typer.Exit(code=1)
|
|
393
|
+
LEGACY_CONFIG_DIR.rename(CONFIG_DIR)
|
|
394
|
+
print(f'> Renamed "{LEGACY_CONFIG_DIR}" to "{CONFIG_DIR}".')
|
|
395
|
+
elif not CONFIG_DIR.exists():
|
|
396
|
+
typer.secho(
|
|
397
|
+
f'Neither "{CONFIG_DIR}" nor "{LEGACY_CONFIG_DIR}" found. Run this command from the package root.',
|
|
398
|
+
fg=typer.colors.RED,
|
|
399
|
+
err=True,
|
|
400
|
+
)
|
|
401
|
+
raise typer.Exit(code=1)
|
|
402
|
+
|
|
403
|
+
skipped_paths = []
|
|
404
|
+
for path in sorted(CONFIG_DIR.rglob("*")):
|
|
405
|
+
if not path.is_file() or "__pycache__" in path.parts:
|
|
406
|
+
continue
|
|
407
|
+
try:
|
|
408
|
+
content = path.read_text(encoding="utf-8", newline="")
|
|
409
|
+
except UnicodeDecodeError:
|
|
410
|
+
skipped_paths.append(path)
|
|
411
|
+
continue
|
|
412
|
+
migrated = content
|
|
413
|
+
for legacy_name, name in LEGACY_NAMES.items():
|
|
414
|
+
migrated = migrated.replace(legacy_name, name)
|
|
415
|
+
if migrated != content:
|
|
416
|
+
path.write_text(migrated, encoding="utf-8", newline="")
|
|
417
|
+
print(f'> Updated "{path}".')
|
|
418
|
+
|
|
419
|
+
for path in skipped_paths:
|
|
420
|
+
typer.secho(
|
|
421
|
+
f'> Skipped "{path}" because it is not UTF-8 encoded. Replace any '
|
|
422
|
+
f"{' / '.join(LEGACY_NAMES)} in it by hand.",
|
|
423
|
+
fg=typer.colors.YELLOW,
|
|
424
|
+
err=True,
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
print('Migration finished. Run "package-foundry render-templates" to update the rendered files.')
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
if __name__ == "__main__":
|
|
431
|
+
app()
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
DEV_DEPENDENCIES = [
|
|
2
|
+
# Updater
|
|
3
|
+
"typer~=0.27",
|
|
4
|
+
# Test runner
|
|
5
|
+
"pytest-cov~=7.1",
|
|
6
|
+
"pytest-django~=4.14",
|
|
7
|
+
"pytest-mock~=3.17",
|
|
8
|
+
# Linting
|
|
9
|
+
"pre-commit~=4.7",
|
|
10
|
+
# Documentation
|
|
11
|
+
"sphinx~=8.2",
|
|
12
|
+
"sphinx-rtd-theme~=3.1",
|
|
13
|
+
"sphinx-mdinclude~=0.6",
|
|
14
|
+
# Release
|
|
15
|
+
"uv~=0.13",
|
|
16
|
+
"keyring~=25.7",
|
|
17
|
+
# Build
|
|
18
|
+
"package-foundry",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
SUPPORTED_DJANGO_VERSIONS = [
|
|
22
|
+
"5.2",
|
|
23
|
+
"6.0",
|
|
24
|
+
"6.1",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
# Python versions each Django version runs on, as documented in the Django installation FAQ.
|
|
28
|
+
# Used to keep unsupported combinations out of the rendered CI test matrix.
|
|
29
|
+
DJANGO_PYTHON_COMPATIBILITY = {
|
|
30
|
+
"4.2": ["3.8", "3.9", "3.10", "3.11", "3.12"],
|
|
31
|
+
"5.0": ["3.10", "3.11", "3.12"],
|
|
32
|
+
"5.1": ["3.10", "3.11", "3.12", "3.13"],
|
|
33
|
+
"5.2": ["3.10", "3.11", "3.12", "3.13", "3.14"],
|
|
34
|
+
"6.0": ["3.12", "3.13", "3.14"],
|
|
35
|
+
"6.1": ["3.12", "3.13", "3.14", "3.15"],
|
|
36
|
+
"6.2": ["3.12", "3.13", "3.14", "3.15"],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
SUPPORTED_PYTHON_VERSIONS = [
|
|
40
|
+
"3.11",
|
|
41
|
+
"3.12",
|
|
42
|
+
"3.13",
|
|
43
|
+
"3.14",
|
|
44
|
+
"3.15",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
# Python versions Read the Docs offers as build.tools.python, as documented in its config file reference:
|
|
48
|
+
# https://docs.readthedocs.com/platform/stable/config-file/v2.html#build-tools-python
|
|
49
|
+
READTHEDOCS_PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13", "3.14"]
|
|
50
|
+
|
|
51
|
+
LICENSE_MIT = "MIT"
|
|
52
|
+
LICENSE_GPL = "GPL"
|
|
53
|
+
|
|
54
|
+
DEPLOYMENT_STATUS_ALPHA = "3 - Alpha"
|
|
55
|
+
DEPLOYMENT_STATUS_BETA = "4 - Beta"
|
|
56
|
+
DEPLOYMENT_STATUS_STABLE = "5 - Production/Stable"
|
|
57
|
+
DEPLOYMENT_STATUS_INACTIVE = "7 - Inactive"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
import datetime
|
|
3
|
+
|
|
4
|
+
from package_foundry.metadata.author import PackageAuthor
|
|
5
|
+
from package_foundry.metadata.constants import LICENSE_MIT
|
|
6
|
+
from package_foundry.metadata.executables import ScriptExecutable
|
|
7
|
+
from package_foundry.metadata.maintainer import PackageMaintainer
|
|
8
|
+
from package_foundry.metadata.readme import ReadmeContent
|
|
9
|
+
from package_foundry.metadata.ruff_ignored_inspection import (
|
|
10
|
+
RuffFilePatternIgnoredInspection,
|
|
11
|
+
RuffIgnoredInspection,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclasses.dataclass
|
|
16
|
+
class PackageMetadata:
|
|
17
|
+
package_name: str
|
|
18
|
+
licenser: str
|
|
19
|
+
authors: list[PackageAuthor]
|
|
20
|
+
maintainer: PackageMaintainer
|
|
21
|
+
development_status: str
|
|
22
|
+
readme_content: ReadmeContent
|
|
23
|
+
claim: str
|
|
24
|
+
has_migrations: bool
|
|
25
|
+
dependencies: list[str]
|
|
26
|
+
supported_django_versions: list[str]
|
|
27
|
+
supported_python_versions: list[str]
|
|
28
|
+
github_package_group: str
|
|
29
|
+
min_coverage: float = 100.0
|
|
30
|
+
license: str = LICENSE_MIT
|
|
31
|
+
license_year: int = datetime.datetime.now(tz=datetime.UTC).year
|
|
32
|
+
main_branch: str = "master"
|
|
33
|
+
tests_require_django: bool = True
|
|
34
|
+
github_package_name: str = None
|
|
35
|
+
module_name: str | None = None
|
|
36
|
+
optional_dependencies: dict[str, list[str]] = None
|
|
37
|
+
ruff_ignore_list: list[RuffIgnoredInspection] = None
|
|
38
|
+
ruff_file_based_ignore_list: list[RuffFilePatternIgnoredInspection] = None
|
|
39
|
+
script_executables: list[ScriptExecutable] = dataclasses.field(default_factory=list)
|
|
40
|
+
gitignore_list: list[str] = dataclasses.field(default_factory=list)
|
|
41
|
+
|
|
42
|
+
def __post_init__(self):
|
|
43
|
+
if not self.module_name:
|
|
44
|
+
self.module_name = self.package_name.replace("-", "_")
|
|
45
|
+
if not self.github_package_name:
|
|
46
|
+
self.github_package_name = self.package_name.replace("_", "-")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# http://editorconfig.org
|
|
2
|
+
|
|
3
|
+
root = true
|
|
4
|
+
|
|
5
|
+
[*]
|
|
6
|
+
charset = utf-8
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
trim_trailing_whitespace = true
|
|
10
|
+
|
|
11
|
+
[*.{py,rst,ini}]
|
|
12
|
+
indent_style = space
|
|
13
|
+
indent_size = 4
|
|
14
|
+
|
|
15
|
+
[*.yml]
|
|
16
|
+
indent_style = space
|
|
17
|
+
indent_size = 2
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Report a problem to help us improve
|
|
4
|
+
title: ''
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Describe the bug
|
|
10
|
+
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
## To reproduce
|
|
14
|
+
|
|
15
|
+
Steps to reproduce the behavior:
|
|
16
|
+
|
|
17
|
+
1. ...
|
|
18
|
+
2. ...
|
|
19
|
+
3. ...
|
|
20
|
+
|
|
21
|
+
## Expected behavior
|
|
22
|
+
|
|
23
|
+
A clear and concise description of what you expected to happen.
|
|
24
|
+
|
|
25
|
+
## Environment
|
|
26
|
+
|
|
27
|
+
- `{{ github_package_name|replace("_", "-") }}` version:
|
|
28
|
+
- Python version:
|
|
29
|
+
{% if tests_require_django %}- Django version:
|
|
30
|
+
{% endif %}- Operating system:
|
|
31
|
+
|
|
32
|
+
## Additional context
|
|
33
|
+
|
|
34
|
+
Add any other context, tracebacks, or screenshots about the problem here.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
blank_issues_enabled: true
|
|
2
|
+
contact_links:
|
|
3
|
+
- name: Security vulnerability
|
|
4
|
+
url: https://github.com/{{ github_package_group|replace("_", "-") }}/{{ github_package_name|replace("_", "-") }}/security/advisories/new
|
|
5
|
+
about: Please report security issues privately via a security advisory, not as a public issue.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: ''
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Is your feature request related to a problem?
|
|
10
|
+
|
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always
|
|
12
|
+
frustrated when [...]
|
|
13
|
+
|
|
14
|
+
## Describe the solution you'd like
|
|
15
|
+
|
|
16
|
+
A clear and concise description of what you want to happen.
|
|
17
|
+
|
|
18
|
+
## Describe alternatives you've considered
|
|
19
|
+
|
|
20
|
+
A clear and concise description of any alternative solutions or features you've
|
|
21
|
+
considered.
|
|
22
|
+
|
|
23
|
+
## Additional context
|
|
24
|
+
|
|
25
|
+
Add any other context or screenshots about the feature request here.
|