exebuilder 0.3.0__tar.gz → 0.3.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exebuilder
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A simple EXE builder for Python files.
5
5
  Author: Victor Zou
6
6
  Project-URL: Homepage, https://github.com/qzou1222-alt/exebuilder
@@ -0,0 +1,151 @@
1
+ """
2
+ Build EXE files from Python files. (v0.3.2)
3
+
4
+ Contents Updated!
5
+ =================
6
+
7
+ 1. Fixed some building and checking bug:
8
+
9
+ - runasexe can't catch some error;
10
+
11
+ - runasexe doesn't check exe is exists;
12
+
13
+ - runasexe building messege is always hidden;
14
+
15
+ - runasexe can't check a file is python file.
16
+
17
+ 2. Optimized some checking codes:
18
+
19
+ - Added more warnings;
20
+
21
+ - runasexe parameter "prt" disassemble to two parameters: "warnprt" and "buildprt";
22
+
23
+ - All methods support .PY file now;
24
+
25
+ - Unified warning messages.
26
+
27
+ Exebuilder
28
+ ==========
29
+
30
+ CLI
31
+ ---
32
+
33
+ exebuilder <file> [--quiet]
34
+ Build a Python file into an EXE using PyInstaller.
35
+
36
+ API
37
+ ---
38
+
39
+ - build(file, prt=True)
40
+ Build an EXE from a Python file.
41
+
42
+ - runasexe(file, warnprt=True, buildprt=False)
43
+ Build a temporary EXE and execute it immediately.
44
+
45
+ Utilities
46
+ ---------
47
+
48
+ - is_pyfile(file)
49
+ Check whether a file is a Python file.
50
+
51
+ - Warnings
52
+ Built-in warning messages.
53
+ """
54
+ from pathlib import Path as _P
55
+ __version__ = "0.3.2"
56
+ def is_pyfile(file:str|_P) -> bool:
57
+ '''Return whether a file is a Python file.'''
58
+ if isinstance(file,_P):
59
+ file=file.name
60
+ return file.lower().endswith('.py')
61
+ class _Warnings:
62
+ def __init__(self):
63
+ self.warns:dict[int,str]=dict()
64
+ self._private=False
65
+ def __init_subclass__(cls):
66
+ raise TypeError("[exebuilder._Warnings] cannot be subclass")
67
+ def __setitem__(self, warnindex:int, warn:str):
68
+ if not self._private:
69
+ self.warns[warnindex]=warn
70
+ def __getitem__(self, warnindex:int):
71
+ return self.warns[warnindex]
72
+ Warnings=_Warnings()
73
+ '''Exebuilder's warnings. Use Warnings[index] to get it.'''
74
+ Warnings[1]="[exebuilder] only supports python file"
75
+ Warnings[2]="something wrong when [exebuilder] building"
76
+ Warnings[3]="EXE not found"
77
+ Warnings[4]="something wrong when EXE running"
78
+ Warnings[5]="python file not found"
79
+ def runasexe(pyfile: str | _P, warnprt:bool=True, buildprt:bool=False):
80
+ """Build and run a temporary EXE from a Python file."""
81
+ from tempfile import TemporaryDirectory
82
+ import subprocess
83
+ if not is_pyfile(pyfile):
84
+ if warnprt:
85
+ print(f"Building failed: {Warnings[1]}")
86
+ return False
87
+ if not _P(pyfile).exists():
88
+ if warnprt:
89
+ print(f"Building failed: {Warnings[5]}")
90
+ return False
91
+ with TemporaryDirectory() as temp:
92
+ temp = _P(temp)
93
+ try:
94
+ subprocess.run([
95
+ "pyinstaller",
96
+ "--onefile",
97
+ "--distpath", str(temp),
98
+ "--workpath", str(temp),
99
+ "--specpath", str(temp),
100
+ str(pyfile)
101
+ ],
102
+ stdout=subprocess.DEVNULL if not buildprt else None,
103
+ stderr=subprocess.DEVNULL if not buildprt else None,
104
+ check=True
105
+ )
106
+ except subprocess.CalledProcessError:
107
+ if warnprt:
108
+ print(f"Building failed: {Warnings[2]}")
109
+ return False
110
+ exe = temp / f"{_P(pyfile).stem}.exe"
111
+ if not exe.exists():
112
+ if warnprt:
113
+ print(f"Building failed: {Warnings[3]}")
114
+ return False
115
+ try:
116
+ subprocess.run([str(exe)],check=True)
117
+ except subprocess.CalledProcessError:
118
+ if warnprt:
119
+ print(f"Running failed: {Warnings[4]}")
120
+ return False
121
+ return True
122
+ def build(pyfile:str|_P, prt:bool=True) -> bool:
123
+ '''Build an EXE from a python file. Prt controls whether messages are printed in the terminal.'''
124
+ import subprocess
125
+ import sys
126
+ if isinstance(pyfile, _P):
127
+ pyfile=str(pyfile)
128
+ if not _P(pyfile).exists():
129
+ if prt:
130
+ print(f"Building failed: {Warnings[5]}")
131
+ return False
132
+ if not is_pyfile(pyfile):
133
+ if prt:
134
+ print(f"Building failed: {Warnings[1]}")
135
+ return False
136
+ try:
137
+ subprocess.run([
138
+ sys.executable, "-m", "PyInstaller",
139
+ "--onefile",
140
+ pyfile,
141
+ ],check=True,
142
+ stdout=subprocess.DEVNULL if not prt else None,
143
+ stderr=subprocess.DEVNULL if not prt else None)
144
+ except subprocess.CalledProcessError:
145
+ if prt:
146
+ print(f"Building failed: {Warnings[2]}")
147
+ return False
148
+ if prt:
149
+ print("Building success")
150
+ return True
151
+ Warnings._private=True
@@ -0,0 +1,13 @@
1
+ def main():
2
+ from . import build
3
+ import sys
4
+ args = sys.argv[1:]
5
+ if not args:
6
+ print("Usage: exebuilder <file> [--quiet]")
7
+ return
8
+ file = args[0]
9
+ flags = args[1:]
10
+ prt = "--quiet" not in flags
11
+ build(file,prt)
12
+ if __name__ == "__main__":
13
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exebuilder
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A simple EXE builder for Python files.
5
5
  Author: Victor Zou
6
6
  Project-URL: Homepage, https://github.com/qzou1222-alt/exebuilder
@@ -1,5 +1,7 @@
1
1
  ReadMe.md
2
2
  pyproject.toml
3
+ exebuilder/__init__.py
4
+ exebuilder/__main__.py
3
5
  exebuilder.egg-info/PKG-INFO
4
6
  exebuilder.egg-info/SOURCES.txt
5
7
  exebuilder.egg-info/dependency_links.txt
@@ -0,0 +1,2 @@
1
+ dist
2
+ exebuilder
@@ -8,7 +8,7 @@ Issues = "https://github.com/qzou1222-alt/exebuilder/issues"
8
8
  exebuilder = "exebuilder.__main__:main"
9
9
  [project]
10
10
  name = "exebuilder"
11
- version = "0.3.0"
11
+ version = "0.3.2"
12
12
  authors = [
13
13
  { name="Victor Zou" }
14
14
  ]
@@ -18,4 +18,6 @@ requires-python = ">=3.10"
18
18
 
19
19
  dependencies = [
20
20
  "pyinstaller"
21
- ]
21
+ ]
22
+ [tool.setuptools.packages.find]
23
+ where = ["."]
File without changes
File without changes