Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97d11fd

Browse files
committed
clarify env_config creation step, and reduce code complexity
1 parent23bbe34 commit97d11fd

File tree

1 file changed

+29
-45
lines changed

1 file changed

+29
-45
lines changed

‎make.py‎

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
frompathlibimportPath
1313
fromwppmimportwppm,utils
1414

15-
# Define constant paths for clarity
1615
PORTABLE_DIRECTORY=Path(__file__).parent/"portable"
1716
assertPORTABLE_DIRECTORY.is_dir(),f"Portable directory not found:{PORTABLE_DIRECTORY}"
1817

@@ -35,8 +34,7 @@ def copy_items(source_directories: list[Path], target_directory: Path, verbose:
3534

3635
defparse_list_argument(argument_value:str|list[str],separator=" ")->list[str]:
3736
"""Parse a separated list argument into a list of strings."""
38-
ifnotargument_value:
39-
return []
37+
ifnotargument_value:return []
4038
returnargument_value.split(separator)ifisinstance(argument_value,str)elselist(argument_value)
4139

4240
classWinPythonDistributionBuilder:
@@ -72,7 +70,7 @@ def __init__(self, build_number: int, release_level: str, target_directory: Path
7270
def_get_python_zip_file(self)->Path:
7371
"""Finds the Python .zip file in the wheels directory."""
7472
forsource_iteminself.wheels_directory.iterdir():
75-
ifre.match(r"(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip",source_item.name):
73+
ifre.match(r"(pypy3|python-).*\.zip",source_item.name):
7674
returnsource_item
7775
raiseRuntimeError(f"Could not find Python zip package in{self.wheels_directory}")
7876

@@ -86,25 +84,9 @@ def python_full_version(self) -> str:
8684
"""Retrieves the Python full version string from the distribution."""
8785
returnutils.get_python_long_version(self.distribution.target)ifself.distributionelse"0.0.0"
8886

89-
@property
90-
defpython_executable_directory(self)->str:
91-
"""Returns the directory containing the Python executable."""
92-
ifself.winpython_directory:
93-
python_path_directory=self.winpython_directory/self.python_directory_name
94-
returnstr(python_path_directory)ifpython_path_directory.is_dir()elsestr(self.winpython_directory/self.python_name)
95-
return""
96-
97-
@property
98-
defarchitecture_bits(self)->int:
99-
"""Returns the architecture (32 or 64 bits) of the distribution."""
100-
returnself.distribution.architectureifself.distributionelse64
101-
10287
def_print_action(self,text:str):
10388
"""Prints an action message with progress indicator."""
104-
ifself.verbose:
105-
utils.print_box(text)
106-
else:
107-
print(f"{text}... ",end="",flush=True)
89+
utils.print_box(text)ifself.verboseelseprint(f"{text}...",end="",flush=True)
10890

10991
def_extract_python_archive(self):
11092
"""Extracts the Python zip archive to create the base Python environment."""
@@ -124,33 +106,38 @@ def _copy_essential_files(self):
124106
self._print_action(f"Copying tools to{tools_target_directory}")
125107
copy_items(self.tools_directories,tools_target_directory,self.verbose)
126108

127-
def_create_initial_batch_scripts(self):
128-
"""Creates initial batch scripts, including environment setup."""
129-
self._print_action("Creating initial batch scripts")
130-
# Replacements for batch scripts (PyPy compatibility)
131-
executable_name=self.distribution.short_exeifself.distributionelse"python.exe"# default to python.exe if distribution is not yet set
132-
init_variables= [('WINPYthon_exe',executable_name), ('WINPYthon_subdirectory_name',self.python_directory_name), ('WINPYVER',self.winpython_version_name)]
133-
init_variables+= [('WINPYVER2',f"{self.python_full_version}.{self.build_number}"), ('WINPYFLAVOR',self.flavor), ('WINPYARCH',self.architecture_bits)]
134-
withopen(self.winpython_directory/"scripts"/"env.ini","w")asf:
135-
f.writelines([f'{a}={b}\n'fora,bininit_variables])
109+
def_create_env_config(self):
110+
"""Creates environment setup"""
111+
self._print_action("Creating env.ini environment setup")
112+
executable_name=self.distribution.short_exeifself.distributionelse"python.exe"
113+
config= {
114+
"WINPYthon_exe":executable_name,
115+
"WINPYthon_subdirectory_name":self.python_directory_name,
116+
"WINPYVER":self.winpython_version_name,
117+
"WINPYVER2":f"{self.python_full_version}.{self.build_number}",
118+
"WINPYFLAVOR":self.flavor,
119+
"WINPYARCH":self.distribution.architectureifself.distributionelse64,
120+
}
121+
env_path=self.winpython_directory/"scripts"/"env.ini"
122+
env_path.parent.mkdir(parents=True,exist_ok=True)
123+
print("zzz env_path",env_path)
124+
self._print_action(f"Creating env.ini environment{env_path}")
125+
env_path.write_text("\n".join(f"{k}={v}"fork,vinconfig.items()))
136126

137127
defbuild(self,winpy_dir:Path=None):
138128
"""Make or finalise WinPython distribution in the target directory"""
139129
print(f"Building WinPython with Python archive:{self.python_zip_file.name}")
140-
self.winpython_directory=winpy_dir
141-
130+
self.winpython_directory=Path(winpy_dir)
142131
self._print_action(f"Creating WinPython{self.winpython_directory} base directory")
143132
ifself.winpython_directory.is_dir()andlen(self.winpython_directory.parts)>=4:
144133
shutil.rmtree(self.winpython_directory)
145-
os.makedirs(self.winpython_directory,exist_ok=True)
146134
# preventive re-Creation of settings directory
147135
(self.winpython_directory/"settings"/"AppData"/"Roaming").mkdir(parents=True,exist_ok=True)
148-
self._extract_python_archive()
149-
150-
self.distribution=wppm.Distribution(self.python_executable_directory,verbose=self.verbose)
151136

137+
self._extract_python_archive()
138+
self.distribution=wppm.Distribution(self.winpython_directory/self.python_directory_name,verbose=self.verbose)
152139
self._copy_essential_files()
153-
self._create_initial_batch_scripts()
140+
self._create_env_config()
154141

155142
defmake_all(build_number:int,release_level:str,basedir_wpy:Path=None,
156143
verbose:bool=False,
@@ -170,22 +157,19 @@ def make_all(build_number: int, release_level: str, basedir_wpy: Path = None,
170157
"""
171158
assertbasedir_wpyisnotNone,"The *winpython_dirname* directory must be specified"
172159

173-
tools_dirs_list=parse_list_argument(toolsdirs,",")
160+
tools_directories=[Path(d)fordinparse_list_argument(toolsdirs,",")]
174161
winpy_dir=Path(basedir_wpy)
175-
176162
utils.print_box(f"Making WinPython at{winpy_dir}")
177163
os.makedirs(winpy_dir,exist_ok=True)
164+
178165
builder=WinPythonDistributionBuilder(
179166
build_number,release_level,winpy_dir.parent,wheels_directory=source_dirs,
180-
tools_directories=[Path(d)fordintools_dirs_list],
181-
verbose=verbose,
182-
flavor=flavor
167+
tools_directories=tools_directories,
168+
verbose=verbose,flavor=flavor
183169
)
184-
builder.build(winpy_dir=winpy_dir)
185-
170+
builder.build(winpy_dir)
186171

187172
if__name__=="__main__":
188-
# DO create only one Winpython distribution at a time
189173
make_all(
190174
build_number=1,
191175
release_level="b3",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp