pyhabitat 1.0.9__py3-none-any.whl → 1.0.11__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.
Potentially problematic release.
This version of pyhabitat might be problematic. Click here for more details.
- pyhabitat/environment.py +36 -4
- {pyhabitat-1.0.9.dist-info → pyhabitat-1.0.11.dist-info}/METADATA +9 -3
- pyhabitat-1.0.11.dist-info/RECORD +7 -0
- pyhabitat-1.0.9.dist-info/RECORD +0 -7
- {pyhabitat-1.0.9.dist-info → pyhabitat-1.0.11.dist-info}/WHEEL +0 -0
- {pyhabitat-1.0.9.dist-info → pyhabitat-1.0.11.dist-info}/licenses/LICENSE +0 -0
- {pyhabitat-1.0.9.dist-info → pyhabitat-1.0.11.dist-info}/top_level.txt +0 -0
pyhabitat/environment.py
CHANGED
|
@@ -449,22 +449,54 @@ def web_browser_is_available() -> bool:
|
|
|
449
449
|
return False
|
|
450
450
|
|
|
451
451
|
# --- LAUNCH MECHANISMS BASED ON ENVIRONMENT ---
|
|
452
|
-
def
|
|
453
|
-
"""
|
|
452
|
+
def open_text_file_for_editing(filepath):
|
|
453
|
+
"""
|
|
454
|
+
Opens a file with the environment's default application (Windows, Linux, macOS)
|
|
455
|
+
or a guaranteed console editor (nano) in constrained environments (Termux, iSH)
|
|
456
|
+
after ensuring line-ending compatibility.
|
|
457
|
+
"""
|
|
454
458
|
if is_windows():
|
|
455
459
|
os.startfile(filepath)
|
|
456
460
|
elif is_termux():
|
|
461
|
+
# Install dependencies if missing (Termux pkg returns non-zero if already installed, so no check=True)
|
|
462
|
+
subprocess.run(['pkg','install', 'dos2unix', 'nano'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
463
|
+
_run_dos2unix(filepath)
|
|
457
464
|
subprocess.run(['nano', filepath])
|
|
458
465
|
elif is_ish_alpine():
|
|
459
|
-
|
|
466
|
+
# Install dependencies if missing (apk returns 0 if already installed, so check=True is safe)
|
|
467
|
+
subprocess.run(['apk','add', 'dos2unix'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
|
468
|
+
subprocess.run(['apk','add', 'nano'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
|
469
|
+
_run_dos2unix(filepath)
|
|
460
470
|
subprocess.run(['nano', filepath])
|
|
471
|
+
# --- Standard Unix-like Systems (Conversion + Default App) ---
|
|
461
472
|
elif is_linux():
|
|
473
|
+
_run_dos2unix(filepath) # Safety conversion for user-defined console apps
|
|
462
474
|
subprocess.run(['xdg-open', filepath])
|
|
475
|
+
|
|
463
476
|
elif is_apple():
|
|
477
|
+
_run_dos2unix(filepath) # Safety conversion for user-defined console apps
|
|
464
478
|
subprocess.run(['open', filepath])
|
|
465
479
|
else:
|
|
466
480
|
print("Unsupported operating system.")
|
|
467
|
-
|
|
481
|
+
|
|
482
|
+
"""Why Not Use check=True on Termux:
|
|
483
|
+
The pkg utility in Termux is a wrapper around Debian's apt. When you run pkg install <package>, if the package is already installed, the utility often returns an exit code of 100 (or another non-zero value) to indicate that no changes were made because the package was already present.
|
|
484
|
+
"""
|
|
485
|
+
|
|
486
|
+
def _run_dos2unix(filepath):
|
|
487
|
+
"""Attempt to run dos2unix, failing silently if not installed."""
|
|
488
|
+
try:
|
|
489
|
+
# We rely on shutil.which not being needed, as this is a robust built-in utility on most targets
|
|
490
|
+
# The command won't raise an exception unless the process itself fails, not just if the utility isn't found.
|
|
491
|
+
# We also don't use check=True here to allow silent failure if the utility is missing (e.g., minimalist Linux).
|
|
492
|
+
subprocess.run(['dos2unix', filepath], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
493
|
+
except FileNotFoundError:
|
|
494
|
+
# This will be raised if 'dos2unix' is not on the system PATH
|
|
495
|
+
pass
|
|
496
|
+
except Exception:
|
|
497
|
+
# Catch other subprocess errors (e.g. permission issues)
|
|
498
|
+
pass
|
|
499
|
+
|
|
468
500
|
def _get_pipx_paths():
|
|
469
501
|
"""
|
|
470
502
|
Returns the configured/default pipx binary and home directories.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyhabitat
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.11
|
|
4
4
|
Summary: A lightweight library for detecting system environment, GUI, and build properties.
|
|
5
5
|
Author-email: George Clayton Bennett <george.bennett@memphistn.gov>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -27,7 +27,7 @@ Stop writing verbose `sys.platform` and environment variable checks. Use **`pyha
|
|
|
27
27
|
|
|
28
28
|
---
|
|
29
29
|
|
|
30
|
-
Read the code on [github](https://github.com/City-of-Memphis-Wastewater/pyhabitat/blob/main/pyhabitat/environment.py).
|
|
30
|
+
Read the code on [github](https://github.com/City-of-Memphis-Wastewater/pyhabitat/blob/main/pyhabitat/environment.py). 🌐
|
|
31
31
|
|
|
32
32
|
---
|
|
33
33
|
|
|
@@ -36,10 +36,12 @@ Read the code on [github](https://github.com/City-of-Memphis-Wastewater/pyhabita
|
|
|
36
36
|
```bash
|
|
37
37
|
pip install pyhabitat
|
|
38
38
|
```
|
|
39
|
+
|
|
39
40
|
---
|
|
40
41
|
|
|
41
42
|
<details>
|
|
42
|
-
<summary> Motivation </summary>
|
|
43
|
+
<summary> 🧠 Motivation </summary>
|
|
44
|
+
|
|
43
45
|
This library is especially useful for **leveraging Python in mobile environments** (`Termux` on Android and `iSH` on iOS), which often have particular limitations and require special handling. For example, it helps automate work-arounds like using **localhost plotting** when `matplotlib` is unavailable or **web-based interfaces** when `tkinter` is missing.
|
|
44
46
|
|
|
45
47
|
Our team is fundamentally driven by enabling mobile computing for true utility applications, leveraging environments like Termux (Android) and iSH (iOS). This includes highly practical solutions, such as deploying a lightweight Python web server (e.g., Flask, http.server, FastAPI) directly on a handset, or orchestrating full-stack, utility-grade applications that allow technicians to manage data and systems right from their mobile device in a way that is cross-platform and not overly catered to the App Store.
|
|
@@ -119,6 +121,10 @@ Key Question: "What could I do next?"
|
|
|
119
121
|
|
|
120
122
|
The module exposes all detection functions directly for easy access.
|
|
121
123
|
|
|
124
|
+
### 0\. Current Use
|
|
125
|
+
|
|
126
|
+
The `pipeline-eds` package uses the `pyhabitat` library to handle [configuration](https://github.com/City-of-Memphis-Wastewater/pipeline/blob/main/src/pipeline/security_and_config.py) and [plotting](https://github.com/City-of-Memphis-Wastewater/pipeline/blob/main/src/pipeline/cli.py), among other things.
|
|
127
|
+
|
|
122
128
|
### 1\. Checking Environment and Build Type
|
|
123
129
|
|
|
124
130
|
```python
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pyhabitat/__init__.py,sha256=fy1SRFXok05bCprjGMCXS5afw27iKBJCLeSQTuBjlRI,1101
|
|
2
|
+
pyhabitat/environment.py,sha256=c_eUqlqiAYGBX2LLCMo3PctOYhwTywOrCBrvjg_rXUs,20248
|
|
3
|
+
pyhabitat-1.0.11.dist-info/licenses/LICENSE,sha256=D4fg30ctUGnCJlWu3ONv5-V8JE1v3ctakoJTcVjsJlg,1072
|
|
4
|
+
pyhabitat-1.0.11.dist-info/METADATA,sha256=eBf2FoFx5utwcsPoRymXTI5vp5av1szHnOxtLfHO8VM,8819
|
|
5
|
+
pyhabitat-1.0.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
pyhabitat-1.0.11.dist-info/top_level.txt,sha256=zXYK44Qu8EqxUETREvd2diMUaB5JiGRErkwFaoLQnnI,10
|
|
7
|
+
pyhabitat-1.0.11.dist-info/RECORD,,
|
pyhabitat-1.0.9.dist-info/RECORD
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
pyhabitat/__init__.py,sha256=fy1SRFXok05bCprjGMCXS5afw27iKBJCLeSQTuBjlRI,1101
|
|
2
|
-
pyhabitat/environment.py,sha256=rteFLXko5VaxwgfQYRR7SBQaRygKqrNr0YjRYQ5mybo,18206
|
|
3
|
-
pyhabitat-1.0.9.dist-info/licenses/LICENSE,sha256=D4fg30ctUGnCJlWu3ONv5-V8JE1v3ctakoJTcVjsJlg,1072
|
|
4
|
-
pyhabitat-1.0.9.dist-info/METADATA,sha256=Th1AvU7Fvpy7WSaesAi1BMVoRcECPlWsmcWV2RGKgNA,8478
|
|
5
|
-
pyhabitat-1.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
-
pyhabitat-1.0.9.dist-info/top_level.txt,sha256=zXYK44Qu8EqxUETREvd2diMUaB5JiGRErkwFaoLQnnI,10
|
|
7
|
-
pyhabitat-1.0.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|