PYV
Install
pip install pyv_file_running
Usage
There is a new file extension .pyv which is used to write python code with conditional compilation.
print("start")
$ version <= 3.7; platform == "win32"
print("old windows")
$ version == 3.8
print("python 3.8")
$ platform == "win32"
print("windows")
$ _
print("other")
$
s = f"""{
$ version <= 9.99
"this is contain"
$
}
"""
ss = """
$ version == 9.99
this is still here
$
"""
print("end")
The special syntax $ is used to write conditional compilation code.
The syntax is as follows:
$ condition
code
$
The condition only supports "version", "platform", and "implement" three keywords, and supports the following operators: ==, !=, <=, >=, <, >. For "platform" and "implement", it only support "==" or "!=". The version must contain the major and minor version number (e.g. 3.7).
The "$ _" means that if the condition above are not satisfied, the code below will be analyse.
The "$" means the end of the analyse.
If the syntan appeared in string, it will be ignored.
Comment
You can also use "#" to write comments.
$ version <= 3.7; platform == "win32" # this is a comment
code
$
Exec the file
You can use this module to exec it:
import pyv
global_dict = {}
local_dict = {}
pyv.exec_pyv_file("test.pyv", global_dict, local_dict)
Set a new environment
You can set a new environment:
import pyv
pyv.set_new_env(version=(3, 8), platform="win32", implement="cpython")
Then you can use this environment in the .pyv file:
import pyv
new_env = pyv.set_new_env(version=(3, 8), platform="win32", implement="cpython")
with open("test.pyv", "r") as f:
code = f.read()
final_code = pyv.preprocess_pyv(code, new_env)
with open("test.py", "w") as f:
f.write(final_code)
Write the file to python
You can use this module to write the .pyv file to python file:
import pyv
pyv.witer_pyv_file_to_py("test.pyv", "test.py")
If you have the code string, you can also write it to python file:
import pyv
code = """
$ version <= 3.7; platform == "win32"
print("old_python")
$ _
print("other")
$
"""
pyv.witer_pyv_to_py(code, "test.py")
All apis
pyv.set_new_env(version: tuple[int, int] | None=None, platform: str | None=None, implement: str | None=None) -> dict[str, Any]: ...
pyv.preprocess_pyv(source: str, env=None) -> str: ...
pyv.exec_pyv_source(source: str, filename="<pyv>", globals=None, locals=None, env=None) -> None: ...
pyv.exec_pyv_file(path: str, globals=None, locals=None, env=None) -> None: ...
pyv.witer_pyv_to_py(source: str, filename: str, env=None) -> None: ...
pyv.witer_pyv_file_to_py(path: str, file_name: str, env=None) -> None: ...
License
MIT
Metadata
Release files for pyv-file-running 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyv_file_running-1.0.2.tar.gz | 4.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyv_file_running-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / pyv_file_running-1.0.2.tar.gz
| Download URL | pyv_file_running-1.0.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33c480e634af6c0c270f65be78e9bcf773b606ed0a8571642f1f865b9bc0fa15
|
|
BLAKE2b-256 checksum How to use checksums |
669d175e581fb341968aee2e4aba2b97344f66e688bec3efe1e2a7ebe29c35f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / pyv_file_running-1.0.2-py3-none-any.whl
| Download URL | pyv_file_running-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a51d20428e23d379adf047e95618eb1bd6313cee3534412bf197f77bad44d63
|
|
BLAKE2b-256 checksum How to use checksums |
bc299cd625a95f1a1e28acbe8b3f0c9045d4bf61b1d2c790b50fa3ac3a1f0e03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for pyv-file-running 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.