pam-python 0.2.6__py3-none-any.whl → 0.2.7__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.
pam/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """PAM Data Plugin framework."""
2
2
 
3
- __version__ = "0.2.6"
3
+ __version__ = "0.2.7"
pam/cli.py CHANGED
@@ -145,19 +145,10 @@ def _project_name(directory: Path) -> str:
145
145
 
146
146
 
147
147
  def _assert_new_project(directory: Path):
148
- known_project_files = set(COMMON_PROJECT_TEMPLATES.values())
149
- for templates in PACKAGE_MANAGER_TEMPLATES.values():
150
- known_project_files.update(templates.values())
151
- known_project_files.update({PROJECT_MARKER, "__init__.py", "uv.lock"})
152
- conflicts = [
153
- name for name in sorted(known_project_files)
154
- if (directory / name).exists()
155
- ]
156
- if conflicts:
157
- raise FileExistsError(
158
- "pam init only supports a new project directory; existing files: "
159
- + ", ".join(conflicts)
160
- )
148
+ # Kept for backward compatibility; collision handling is now in init_project
149
+ # via _prompt_overwrite_if_needed. Do not enforce allow-list here so
150
+ # unrelated files like .DS_Store are ignored.
151
+ return
161
152
 
162
153
 
163
154
  def _requirement_name(requirement: str) -> str:
@@ -180,45 +171,26 @@ def _assert_fresh_uv_project(directory: Path):
180
171
  "Run `uv add pam-python` before `uv run pam init`"
181
172
  )
182
173
 
183
- python_version = directory / ".python-version"
184
- if not python_version.is_file() or not python_version.read_text().strip().startswith("3.12"):
185
- raise FileExistsError(
186
- "A fresh uv project must pin Python 3.12; run `uv init --python 3.12`"
187
- )
188
174
 
189
- allowed = {
190
- ".git",
191
- ".gitignore",
192
- ".python-version",
193
- ".venv",
194
- "README.md",
195
- "main.py",
196
- "pyproject.toml",
197
- "uv.lock",
198
- }
199
- unexpected = sorted(path.name for path in directory.iterdir() if path.name not in allowed)
200
- if unexpected:
175
+ def _prompt_overwrite_if_needed(directory: Path, templates: dict[str, str]) -> bool:
176
+ dest_names = set(templates.values()) | {PROJECT_MARKER, "__init__.py"}
177
+ conflicts = sorted(name for name in dest_names if (directory / name).exists())
178
+ if not conflicts:
179
+ return True
180
+ print("The following files will be overwritten:")
181
+ for name in conflicts:
182
+ print(f" - {name}")
183
+ # Single confirmation round as requested: list collisions once, ask once.
184
+ if not sys.stdin.isatty():
201
185
  raise FileExistsError(
202
- "pam init only accepts a fresh uv project; existing files: "
203
- + ", ".join(unexpected)
204
- )
205
-
206
- readme = directory / "README.md"
207
- if readme.is_file() and readme.read_text(encoding="utf-8").strip():
208
- raise FileExistsError("pam init will not overwrite a non-empty README.md")
209
-
210
- main_file = directory / "main.py"
211
- if main_file.is_file():
212
- source = main_file.read_text(encoding="utf-8")
213
- uv_placeholder = re.fullmatch(
214
- r'def main\(\):\n'
215
- r' print\("Hello from [a-z0-9-]+!"\)\n\n\n'
216
- r'if __name__ == "__main__":\n'
217
- r' main\(\)\n?',
218
- source,
186
+ "pam init will overwrite existing files: " + ", ".join(conflicts) + ". "
187
+ "Run in an interactive terminal and confirm to overwrite."
219
188
  )
220
- if uv_placeholder is None:
221
- raise FileExistsError("pam init will not overwrite an edited main.py")
189
+ response = input("มีไฟล์ที่จะถูกเขียนทับตามรายการข้างบน ดำเนินการต่อหรือไม่? (y/N): ").strip().lower()
190
+ if response != "y":
191
+ print("Cancelled.")
192
+ return False
193
+ return True
222
194
 
223
195
 
224
196
  def _run_uv(args: list[str], cwd: Path):
@@ -263,6 +235,9 @@ def init_project(package_manager: str | None = None):
263
235
  if dest not in preserved_uv_files
264
236
  }
265
237
 
238
+ if not _prompt_overwrite_if_needed(destination, templates):
239
+ return
240
+
266
241
  with tempfile.TemporaryDirectory(prefix=".pam-init-", dir=destination) as temp_dir:
267
242
  staging = Path(temp_dir)
268
243
  for src, dest in templates.items():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pam-python
3
- Version: 0.2.6
3
+ Version: 0.2.7
4
4
  Summary: Pam Python Library
5
5
  Author-email: Narongrit Kanhanoi <narongrit@pams.ai>
6
6
  Project-URL: Homepage, https://github.com/heart/pam-python
@@ -1,6 +1,6 @@
1
- pam/__init__.py,sha256=kNpy26ztXRQlEGfE7Shran_YH6Tjy29whcWyW9vwcH4,56
1
+ pam/__init__.py,sha256=U3TQ5a4YxJeZTrlqKyKOvXPGWW7MMKw624l-8NBMCi4,56
2
2
  pam/api.py,sha256=T1plaZ1EyGFz59EdP5ibnl7n0NxduhBPN-jGYe20rCU,7844
3
- pam/cli.py,sha256=bMwQ8UjeCWXXhOKOBbUy135PFNHhC_roYIGUy7dge3c,14264
3
+ pam/cli.py,sha256=n1gPTP0TwT0rV-3nrYLjSDc4bL77Jogpreb1HazJ5YA,13633
4
4
  pam/interface_task_manager.py,sha256=V6WMifh5t0tIq9m46eH0RlXDmhbRNPc7XVs6R2rOejE,1985
5
5
  pam/logger.py,sha256=JYPfIpaQZy6QrfVKrzEMrxOgTzWIEhoegvIZgHTGWoc,3021
6
6
  pam/request_file_format.py,sha256=fSRlJagbvVGqdIEqhINSeqBNUTNQdm8GL5JfqgX9bxU,317
@@ -70,9 +70,9 @@ pam/templates/service/pandas/service_class.tmpl,sha256=qaq9tqRhxogWQlqi09dbX5vLu
70
70
  pam/templates/service/polars/functions.tmpl,sha256=7Qlwsd5Q1vdkOvXHtlltjb2oS-i7JuNKPor2iNDSsQg,701
71
71
  pam/templates/service/polars/service.test.tmpl,sha256=nC6VoauZMYy_UTTXxxergfWbXvUD_VWwpM7-7A3aKqE,6881
72
72
  pam/templates/service/polars/service_class.tmpl,sha256=jMGeruXduu0eBB7FPDEkZu8b4mSIO3uRt5TiDuNq5T4,3688
73
- pam_python-0.2.6.dist-info/licenses/LICENSE.txt,sha256=yeHD2-gzrkkET2ZkMe22WyUGpDjlwTrqA4POb0FoZi4,1138
74
- pam_python-0.2.6.dist-info/METADATA,sha256=5XB1Om7Ur-8Azz8jiiRte87_y2xY2gorw1e_sTMyjno,9974
75
- pam_python-0.2.6.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
76
- pam_python-0.2.6.dist-info/entry_points.txt,sha256=xqYpsIqvNlO0j8elZc02bDwR-12dLK9FU2B1ACsLYxw,37
77
- pam_python-0.2.6.dist-info/top_level.txt,sha256=0EOjbyc3hQyzjhn6iyMgsEseqA66Xz0p27iBN7G7W1w,4
78
- pam_python-0.2.6.dist-info/RECORD,,
73
+ pam_python-0.2.7.dist-info/licenses/LICENSE.txt,sha256=yeHD2-gzrkkET2ZkMe22WyUGpDjlwTrqA4POb0FoZi4,1138
74
+ pam_python-0.2.7.dist-info/METADATA,sha256=T2NuYuNt32F9WkIgVrWGXRNs6_Gg3GK0ZopEFymPimU,9974
75
+ pam_python-0.2.7.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
76
+ pam_python-0.2.7.dist-info/entry_points.txt,sha256=xqYpsIqvNlO0j8elZc02bDwR-12dLK9FU2B1ACsLYxw,37
77
+ pam_python-0.2.7.dist-info/top_level.txt,sha256=0EOjbyc3hQyzjhn6iyMgsEseqA66Xz0p27iBN7G7W1w,4
78
+ pam_python-0.2.7.dist-info/RECORD,,