• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

haiiliin / abqpy / 17764620710

16 Sep 2025 11:42AM UTC coverage: 77.375%. First build
17764620710

Pull #6318

github

web-flow
Merge 3702bf6bb into 2789864a2
Pull Request #6318: [bugfix] Set configuration defaults directly in method signatures (backport #6311)

0 of 16 new or added lines in 2 files covered. (0.0%)

24415 of 31554 relevant lines covered (77.38%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.0
/src/abqpy/cli.py
1
from __future__ import annotations
1✔
2

3
import os
1✔
4
import subprocess
1✔
5

6
from typeguard import typechecked
1✔
7
from typing_extensions import Self
1✔
8

9
from .config import config
1✔
10

11

12
@typechecked
1✔
13
class AbqpyCLIBase:
1✔
14
    """Base class for Abaqus/CAE command line interface to run Abaqus commands."""
15

16
    def _parse_options(self, **options: str | int | bool | None) -> str:
1✔
17
        """Parse options to be passed to Abaqus/CAE command line interface.
18

19
        If the value is a string or an integer, the option will be passed as ``option=value``; if the value is a
20
        boolean, the option will be passed as ``option`` if True, or ignored if False; if the value is None, the option
21
        will be ignored.
22
        """
23
        return " ".join([f"{k}={v}" if isinstance(v, (str, int)) and not isinstance(v, bool) else
×
24
                         k for k, v in options.items() if v])  # fmt: skip
25

26
    def run(self, cmd: str):
1✔
27
        """Run custom command."""
28
        cmd = cmd.strip()
×
29
        message = f"Running the following command: {cmd}"
×
30
        print("", "-" * len(message), message, "-" * len(message), sep="\n")
×
31
        if config.execution_method == "os":
×
32
            return os.system(cmd)
×
33
        elif config.execution_method == "subprocess":
×
34
            return subprocess.run(cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
×
35
        else:
36
            raise ValueError(f"Invalid execution method: {config.execution_method}")
×
37

38
    def abaqus(self, *args, **options):
1✔
39
        """Run custom Abaqus command: ``abaqus {args} {options}``, arguments are separated by space, options are
40
        handled by the :meth:`._parse_options` method.
41

42
        Parameters
43
        ----------
44
        args, options
45
            Arguments and options to be passed to the Abaqus command.
46
        """
47
        abaqus = os.environ.get("ABAQUS_BAT_PATH", "abaqus")
×
48
        args, options = " ".join(args), self._parse_options(**options)
×
49
        return self.run(abaqus + (f" {args}" if args else "") + (f" {options}" if options else ""))
×
50

51

52
@typechecked
1✔
53
class AbqpyCLI(AbqpyCLIBase):
1✔
54
    """The abqpy command line interface."""
55

56
    @property
1✔
57
    def misc(self) -> Self:
1✔
58
        """Miscellaneous commands for backward compatibility."""
59
        return self
×
60

61
    def cae(
1✔
62
        self,
63
        script: str,
64
        *args,
65
        database: str | None = None,
66
        replay: str | None = None,
67
        recover: str | None = None,
68
        startup: str | None = None,
69
        gui: bool | None = None,
70
        envstartup: bool | None = None,
71
        savedOptions: bool | None = None,
72
        savedGuiPrefs: bool | None = None,
73
        startupDialog: bool | None = None,
74
        custom: str | None = None,
75
        guiTester: str | None = None,
76
        guiRecord: bool | None = None,
77
    ):
78
        """Run Abaqus/CAE command.
79

80
        Parameters
81
        ----------
82
        script : str
83
            The name of the python script to run
84
        args : str
85
            Extra arguments to be passed after the Abaqus/CAE command line options
86
        database : str, optional
87
            The name of the database file to open, by default None
88
        replay : str, optional
89
            The name of the replay file to open, by default None
90
        recover : str, optional
91
            The name of the journal file to open, by default None
92
        startup : str, optional
93
            The name of the startup file to open, by default None
94
        gui : bool, optional
95
            Run Abaqus/CAE command with the graphical user interface (GUI mode), by default False.
96
        envstartup : bool, optional
97
            Execute the Abaqus/CAE startup file, by default True
98
        savedOptions : bool, optional
99
            Use the saved options, by default True
100
        savedGuiPrefs : bool, optional
101
            Use the saved GUI preferences, by default True
102
        startupDialog : bool, optional
103
            Display the startup dialog, by default True
104
        custom : str, optional
105
            The name of the file containing Abaqus GUI Toolkit commands to be executed, by default None
106
        guiTester : str, optional
107
            This option starts a separate user interface containing the Abaqus Python development environment along
108
            with Abaqus/CAE.
109
        guiRecord : bool, optional
110
            Record the GUI commands to a file, by default None
111
        """
112
        # Option defaults
NEW
113
        database = database if database is not None else config.cae.database
×
NEW
114
        replay = replay if replay is not None else config.cae.replay
×
NEW
115
        recover = recover if recover is not None else config.cae.recover
×
NEW
116
        startup = startup if startup is not None else config.cae.startup
×
NEW
117
        gui = gui if gui is not None else config.cae.gui
×
NEW
118
        envstartup = envstartup if envstartup is not None else config.cae.envstartup
×
NEW
119
        savedOptions = savedOptions if savedOptions is not None else config.cae.savedOptions
×
NEW
120
        savedGuiPrefs = savedGuiPrefs if savedGuiPrefs is not None else config.cae.savedGuiPrefs
×
NEW
121
        startupDialog = startupDialog if startupDialog is not None else config.cae.startupDialog
×
NEW
122
        custom = custom if custom is not None else config.cae.custom
×
NEW
123
        guiTester = guiTester if guiTester is not None else config.cae.guiTester
×
NEW
124
        guiRecord = guiRecord if guiRecord is not None else config.cae.guiRecord
×
125

126
        # Parse options
127
        script = f'"{script}"'.replace('""', '"') if " " in script else script
×
128
        options = self._parse_options(script=script if gui else None, noGUI=script if not gui else None,
×
129
                                      database=database, replay=replay, recover=recover, startup=startup,
130
                                      noenvstartup=not envstartup, noSavedOptions=not savedOptions,
131
                                      noSavedGuiPrefs=not savedGuiPrefs, noStartupDialog=not startupDialog,
132
                                      custom=custom, guiTester=guiTester,
133
                                      guiRecord=True if guiRecord is True else None,
134
                                      guiNoRecord=True if guiRecord is False else None)  # fmt: skip
135
        args = ("--", *args) if args else ()
×
136

137
        # Execute command
138
        return self.abaqus("cae", options, *args)
×
139

140
    viewer = cae
1✔
141

142
    def pde(self, *scripts: str, script: str | None = None, **options):
1✔
143
        """Run Abaqus/PDE command.
144

145
        Parameters
146
        ----------
147
        scripts : str
148
            Scripts to be included in the Abaqus/PDE session
149
        script : str, optional
150
            Script to be opened at startup in Abaqus/PDE, by default None
151
        options
152
            Abaqus/CAE command line arguments
153
        """
154
        script = f'"{script}"'.replace('""', '"') if script is not None and " " in script else script
×
155
        scripts = tuple(f'"{s}"'.replace('""', '"') if " " in s else s for s in scripts)
×
156
        cae_opts = self._parse_options(**options)
×
157
        args = (*scripts,) + ((f"script={script}",) if script else ()) + ("-pde",) + ((cae_opts,) if cae_opts else ())
×
158
        return self.abaqus("pde", *args)
×
159

160
    def python(
1✔
161
        self,
162
        script: str,
163
        *args,
164
        sim: str | None = None,
165
        log: str | None = None,
166
    ):
167
        """Run Abaqus/Python command.
168

169
        Parameters
170
        ----------
171
        script : str
172
            The name of the python script to run
173
        args : str
174
            Extra arguments to be passed after the Abaqus/CAE command line options
175
        sim : str, optional
176
            The name of the simulation file to open, by default None
177
        log : str, optional
178
            The name of the log file to open, by default None
179
        """
180
        # Option defaults
NEW
181
        sim = sim if sim is not None else config.python.sim
×
NEW
182
        log = log if log is not None else config.python.log
×
183

184
        # Parse options
185
        options = self._parse_options(sim=sim, log=log)
×
186

187
        # Execute command
188
        script = f'"{script}"'.replace('""', '"') if " " in script else script
×
189
        return self.abaqus("python", script, options, *args)
×
190

191
    @typechecked
1✔
192
    def optimization(
1✔
193
        self,
194
        task: str,
195
        job: str,
196
        *,
197
        cpus: int | None = None,
198
        gpus: int | None = None,
199
        memory: int | None = None,
200
        interactive: bool = False,
201
        globalmodel: str | None = None,
202
        scratch: str | None = None,
203
    ):
204
        """Run Abaqus optimization command.
205

206
        Parameters
207
        ----------
208
        task : str
209
            The file containing the parameters that are used to execute the optimization.
210
        job : str
211
            The name of the folder in which the results of the optimization are stored.
212
        cpus : int, optional
213
            The number of processors to use during an analysis run if parallel processing is available.
214
        gpus : int, optional
215
            This acceleration of the Abaqus/Standard direct solver.
216
        memory : int, optional
217
            Maximum amount of memory or maximum percentage of the physical memory that can be allocated.
218
        interactive : bool, optional
219
            This option will cause the job to run interactively.
220
        globalmodel : str, optional
221
            The name of the global model's results file, ODB output database file, or SIM database file.
222
        scratch : str, optional
223
            The name of the directory used for scratch files.
224
        """
225
        # Execute command
226
        return self.abaqus("optimization", task=task, job=job, cpus=cpus, gpus=gpus, memory=memory,
×
227
                           interactive=interactive, globalmodel=globalmodel, scratch=scratch)  # fmt: skip
228

229
    def help(self, *args, **options):
1✔
230
        return self.abaqus("help", *args, **options)
×
231

232
    def information(self, *args, **options):
1✔
233
        return self.abaqus("information", *args, **options)
×
234

235
    def whereami(self, *args, **options):
1✔
236
        return self.abaqus("whereami", *args, **options)
×
237

238
    def cse(self, *args, **options):
1✔
239
        return self.abaqus("cse", *args, **options)
×
240

241
    def cosimulation(self, *args, **options):
1✔
242
        return self.abaqus("cosimulation", *args, **options)
×
243

244
    def fmu(self, *args, **options):
1✔
245
        return self.abaqus("fmu", *args, **options)
×
246

247
    def script(self, *args, **options):
1✔
248
        return self.abaqus("script", *args, **options)
×
249

250
    def doc(self, *args, **options):
1✔
251
        return self.abaqus("doc", *args, **options)
×
252

253
    def licensing(self, *args, **options):
1✔
254
        return self.abaqus("licensing", *args, **options)
×
255

256
    def ascfil(self, *args, **options):
1✔
257
        return self.abaqus("ascfil", *args, **options)
×
258

259
    def append(self, *args, **options):
1✔
260
        return self.abaqus("append", *args, **options)
×
261

262
    def findkeyword(self, *args, **options):
1✔
263
        return self.abaqus("findkeyword", *args, **options)
×
264

265
    def fetch(self, *args, **options):
1✔
266
        return self.abaqus("fetch", *args, **options)
×
267

268
    def make(self, *args, **options):
1✔
269
        return self.abaqus("make", *args, **options)
×
270

271
    def upgrade(self, *args, **options):
1✔
272
        return self.abaqus("upgrade", *args, **options)
×
273

274
    def sim_version(self, *args, **options):
1✔
275
        return self.abaqus("sim_version", *args, **options)
×
276

277
    def odb2sim(self, *args, **options):
1✔
278
        return self.abaqus("odb2sim", *args, **options)
×
279

280
    def odbreport(self, *args, **options):
1✔
281
        return self.abaqus("odbReport", *args, **options)
×
282

283
    def restartjoin(self, *args, **options):
1✔
284
        return self.abaqus("restartjoin", *args, **options)
×
285

286
    def substructurecombine(self, *args, **options):
1✔
287
        return self.abaqus("substructurecombine", *args, **options)
×
288

289
    def substructurerecover(self, *args, **options):
1✔
290
        return self.abaqus("substructurerecover", *args, **options)
×
291

292
    def odbcombine(self, *args, **options):
1✔
293
        return self.abaqus("odbcombine", *args, **options)
×
294

295
    def networkDBConnector(self, *args, **options):
1✔
296
        return self.abaqus("networkDBConnector", *args, **options)
×
297

298
    def emloads(self, *args, **options):
1✔
299
        return self.abaqus("emloads", *args, **options)
×
300

301
    def mtxasm(self, *args, **options):
1✔
302
        return self.abaqus("mtxasm", *args, **options)
×
303

304
    def fromnastran(self, *args, **options):
1✔
305
        return self.abaqus("fromnastran", *args, **options)
×
306

307
    def tonastran(self, *args, **options):
1✔
308
        return self.abaqus("tonastran", *args, **options)
×
309

310
    def fromansys(self, *args, **options):
1✔
311
        return self.abaqus("fromansys", *args, **options)
×
312

313
    def frompamcrash(self, *args, **options):
1✔
314
        return self.abaqus("frompamcrash", *args, **options)
×
315

316
    def fromradioss(self, *args, **options):
1✔
317
        return self.abaqus("fromradioss", *args, **options)
×
318

319
    def toOutput2(self, *args, **options):
1✔
320
        return self.abaqus("toOutput2", *args, **options)
×
321

322
    def fromdyna(self, *args, **options):
1✔
323
        return self.abaqus("fromdyna", *args, **options)
×
324

325
    def tozaero(self, *args, **options):
1✔
326
        return self.abaqus("tozaero", *args, **options)
×
327

328
    def adams(self, *args, **options):
1✔
329
        return self.abaqus("adams", *args, **options)
×
330

331
    def tosimpack(self, *args, **options):
1✔
332
        return self.abaqus("tosimpack", *args, **options)
×
333

334
    def fromsimpack(self, *args, **options):
1✔
335
        return self.abaqus("fromsimpack", *args, **options)
×
336

337
    def toexcite(self, *args, **options):
1✔
338
        return self.abaqus("toexcite", *args, **options)
×
339

340
    def moldflow(self, *args, **options):
1✔
341
        return self.abaqus("moldflow", *args, **options)
×
342

343
    def encrypt(self, *args, **options):
1✔
344
        return self.abaqus("encrypt", *args, **options)
×
345

346
    def decrypt(self, *args, **options):
1✔
347
        return self.abaqus("decrypt", *args, **options)
×
348

349
    def suspend(self, *args, **options):
1✔
350
        return self.abaqus("suspend", *args, **options)
×
351

352
    def resume(self, *args, **options):
1✔
353
        return self.abaqus("resume", *args, **options)
×
354

355
    def terminate(self, *args, **options):
1✔
356
        return self.abaqus("terminate", *args, **options)
×
357

358
    def sysVerify(self, *args, **options):
1✔
359
        return self.abaqus("sysVerify", *args, **options)
×
360

361

362
#: The abqpy command line interface, use this object to run abqpy commands from the python scripts
363
abaqus = AbqpyCLI()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc