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

haiiliin / abqpy / 13676984606

05 Mar 2025 01:21PM UTC coverage: 74.298% (-0.01%) from 74.31%
13676984606

push

github

web-flow
Bump pdm-project/setup-pdm from 3 to 4 (backport #5953) (#5978)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

25331 of 34094 relevant lines covered (74.3%)

0.74 hits per line

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

50.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 = False,
70
        envstartup: bool = True,
71
        savedOptions: bool = True,
72
        savedGuiPrefs: bool = True,
73
        startupDialog: bool = True,
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
        # Parse options
113
        options = self._parse_options(script=script if gui else None, noGUI=script if not gui else None,
×
114
                                      database=database, replay=replay, recover=recover, startup=startup,
115
                                      noenvstartup=not envstartup, noSavedOptions=not savedOptions,
116
                                      noSavedGuiPrefs=not savedGuiPrefs, noStartupDialog=not startupDialog,
117
                                      custom=custom, guiTester=guiTester,
118
                                      guiRecord=True if guiRecord is True else None,
119
                                      guiNoRecord=True if guiRecord is False else None)  # fmt: skip
120
        args = ("--", *args) if args else ()
×
121

122
        # Execute command
123
        return self.abaqus("cae", options, *args)
×
124

125
    viewer = cae
1✔
126

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

130
        Parameters
131
        ----------
132
        scripts : str
133
            Scripts to be included in the Abaqus/PDE session
134
        script : str, optional
135
            Script to be opened at startup in Abaqus/PDE, by default None
136
        options
137
            Abaqus/CAE command line arguments
138
        """
139
        cae_opts = self._parse_options(**options)
×
140
        args = (*scripts,) + ((f"script={script}",) if script else ()) + ("-pde",) + ((cae_opts,) if cae_opts else ())
×
141
        return self.abaqus("pde", *args)
×
142

143
    def python(
1✔
144
        self,
145
        script: str,
146
        *args,
147
        sim: str | None = None,
148
        log: str | None = None,
149
    ):
150
        """Run Abaqus/Python command.
151

152
        Parameters
153
        ----------
154
        script : str
155
            The name of the python script to run
156
        args : str
157
            Extra arguments to be passed after the Abaqus/CAE command line options
158
        sim : str, optional
159
            The name of the simulation file to open, by default None
160
        log : str, optional
161
            The name of the log file to open, by default None
162
        """
163
        # Parse options
164
        options = self._parse_options(sim=sim, log=log)
×
165

166
        # Execute command
167
        return self.abaqus("python", script, options, *args)
×
168

169
    @typechecked
1✔
170
    def optimization(
1✔
171
        self,
172
        task: str,
173
        job: str,
174
        *,
175
        cpus: int | None = None,
176
        gpus: int | None = None,
177
        memory: int | None = None,
178
        interactive: bool = False,
179
        globalmodel: str | None = None,
180
        scratch: str | None = None,
181
    ):
182
        """Run Abaqus optimization command.
183

184
        Parameters
185
        ----------
186
        task : str
187
            The file containing the parameters that are used to execute the optimization.
188
        job : str
189
            The name of the folder in which the results of the optimization are stored.
190
        cpus : int, optional
191
            The number of processors to use during an analysis run if parallel processing is available.
192
        gpus : int, optional
193
            This acceleration of the Abaqus/Standard direct solver.
194
        memory : int, optional
195
            Maximum amount of memory or maximum percentage of the physical memory that can be allocated.
196
        interactive : bool, optional
197
            This option will cause the job to run interactively.
198
        globalmodel : str, optional
199
            The name of the global model's results file, ODB output database file, or SIM database file.
200
        scratch : str, optional
201
            The name of the directory used for scratch files.
202
        """
203
        # Execute command
204
        return self.abaqus("optimization", task=task, job=job, cpus=cpus, gpus=gpus, memory=memory,
×
205
                           interactive=interactive, globalmodel=globalmodel, scratch=scratch)  # fmt: skip
206

207
    def help(self, *args, **options):
1✔
208
        return self.abaqus("help", *args, **options)
×
209

210
    def information(self, *args, **options):
1✔
211
        return self.abaqus("information", *args, **options)
×
212

213
    def whereami(self, *args, **options):
1✔
214
        return self.abaqus("whereami", *args, **options)
×
215

216
    def cse(self, *args, **options):
1✔
217
        return self.abaqus("cse", *args, **options)
×
218

219
    def cosimulation(self, *args, **options):
1✔
220
        return self.abaqus("cosimulation", *args, **options)
×
221

222
    def fmu(self, *args, **options):
1✔
223
        return self.abaqus("fmu", *args, **options)
×
224

225
    def script(self, *args, **options):
1✔
226
        return self.abaqus("script", *args, **options)
×
227

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

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

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

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

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

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

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

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

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

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

258
    def odbreport(self, *args, **options):
1✔
259
        return self.abaqus("odbReport", *args, **options)
×
260

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

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

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

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

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

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

279
    def mtxasm(self, *args, **options):
1✔
280
        return self.abaqus("mtxasm", *args, **options)
×
281

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

339

340
#: The abqpy command line interface, use this object to run abqpy commands from the python scripts
341
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