exebuilder 0.3.1__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.1
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,10 +1,28 @@
1
1
  """
2
- Build EXE files from Python files. (v0.3.1)
2
+ Build EXE files from Python files. (v0.3.2)
3
3
 
4
4
  Contents Updated!
5
5
  =================
6
6
 
7
- Fixed some module install bug.
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.
8
26
 
9
27
  Exebuilder
10
28
  ==========
@@ -21,7 +39,7 @@ API
21
39
  - build(file, prt=True)
22
40
  Build an EXE from a Python file.
23
41
 
24
- - runasexe(file, prt=True)
42
+ - runasexe(file, warnprt=True, buildprt=False)
25
43
  Build a temporary EXE and execute it immediately.
26
44
 
27
45
  Utilities
@@ -34,12 +52,12 @@ Utilities
34
52
  Built-in warning messages.
35
53
  """
36
54
  from pathlib import Path as _P
37
- __version__ = "0.3.1"
55
+ __version__ = "0.3.2"
38
56
  def is_pyfile(file:str|_P) -> bool:
39
57
  '''Return whether a file is a Python file.'''
40
58
  if isinstance(file,_P):
41
59
  file=file.name
42
- return file.endswith('.py')
60
+ return file.lower().endswith('.py')
43
61
  class _Warnings:
44
62
  def __init__(self):
45
63
  self.warns:dict[int,str]=dict()
@@ -55,10 +73,21 @@ Warnings=_Warnings()
55
73
  '''Exebuilder's warnings. Use Warnings[index] to get it.'''
56
74
  Warnings[1]="[exebuilder] only supports python file"
57
75
  Warnings[2]="something wrong when [exebuilder] building"
58
- def runasexe(pyfile: str | _P, prt:bool=True):
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):
59
80
  """Build and run a temporary EXE from a Python file."""
60
81
  from tempfile import TemporaryDirectory
61
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
62
91
  with TemporaryDirectory() as temp:
63
92
  temp = _P(temp)
64
93
  try:
@@ -70,16 +99,25 @@ def runasexe(pyfile: str | _P, prt:bool=True):
70
99
  "--specpath", str(temp),
71
100
  str(pyfile)
72
101
  ],
73
- stdout=subprocess.DEVNULL,
74
- stderr=subprocess.DEVNULL,
102
+ stdout=subprocess.DEVNULL if not buildprt else None,
103
+ stderr=subprocess.DEVNULL if not buildprt else None,
75
104
  check=True
76
105
  )
77
106
  except subprocess.CalledProcessError:
78
- if prt:
79
- print(f"Running failed: {Warnings[2]}")
107
+ if warnprt:
108
+ print(f"Building failed: {Warnings[2]}")
80
109
  return False
81
110
  exe = temp / f"{_P(pyfile).stem}.exe"
82
- subprocess.run([str(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
83
121
  return True
84
122
  def build(pyfile:str|_P, prt:bool=True) -> bool:
85
123
  '''Build an EXE from a python file. Prt controls whether messages are printed in the terminal.'''
@@ -87,9 +125,13 @@ def build(pyfile:str|_P, prt:bool=True) -> bool:
87
125
  import sys
88
126
  if isinstance(pyfile, _P):
89
127
  pyfile=str(pyfile)
128
+ if not _P(pyfile).exists():
129
+ if prt:
130
+ print(f"Building failed: {Warnings[5]}")
131
+ return False
90
132
  if not is_pyfile(pyfile):
91
133
  if prt:
92
- print(f"build failed: {Warnings[1]}")
134
+ print(f"Building failed: {Warnings[1]}")
93
135
  return False
94
136
  try:
95
137
  subprocess.run([
@@ -97,10 +139,11 @@ def build(pyfile:str|_P, prt:bool=True) -> bool:
97
139
  "--onefile",
98
140
  pyfile,
99
141
  ],check=True,
100
- stdout=subprocess.DEVNULL if not prt else None)
142
+ stdout=subprocess.DEVNULL if not prt else None,
143
+ stderr=subprocess.DEVNULL if not prt else None)
101
144
  except subprocess.CalledProcessError:
102
145
  if prt:
103
- print(f"build failed: {Warnings[2]}")
146
+ print(f"Building failed: {Warnings[2]}")
104
147
  return False
105
148
  if prt:
106
149
  print("Building success")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: exebuilder
3
- Version: 0.3.1
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,3 +1,2 @@
1
- build
2
1
  dist
3
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.1"
11
+ version = "0.3.2"
12
12
  authors = [
13
13
  { name="Victor Zou" }
14
14
  ]
File without changes
File without changes