@@ -82,7 +82,7 @@ def check_mystmd_installed(self):
82
82
self .cprint (f"✗ Unexpected error occurred: { str (e )} " , "red" )
83
83
raise
84
84
85
- def run_command (self , * args , env_vars = {}):
85
+ def run_command (self , * args , env_vars = {}, user = None , group = None ):
86
86
"""
87
87
Run a command using the MyST executable.
88
88
@@ -99,7 +99,15 @@ def run_command(self, *args, env_vars={}):
99
99
env = os .environ .copy ()
100
100
env .update (env_vars )
101
101
102
- process = subprocess .Popen (command , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
102
+ if user and group :
103
+ uid = os .getpwnam (user ).pw_uid
104
+ gid = os .getgrnam (group ).gr_gid
105
+ process = subprocess .Popen (command , env = env ,
106
+ preexec_fn = lambda : os .setgid (gid ) or os .setuid (uid ),
107
+ stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
108
+ else :
109
+ process = subprocess .Popen (command , env = env , stdout = subprocess .PIPE , stderr = subprocess .PIPE , text = True )
110
+
103
111
output = []
104
112
error_output = []
105
113
@@ -131,7 +139,7 @@ def run_command(self, *args, env_vars={}):
131
139
print (f"Unexpected error: { e } " )
132
140
return None
133
141
134
- def build (self , * args ):
142
+ def build (self , * args , user = None , group = None ):
135
143
"""
136
144
Build the MyST markdown project with specified arguments.
137
145
@@ -143,9 +151,9 @@ def build(self, *args):
143
151
"""
144
152
os .chdir (self .build_dir )
145
153
self .cprint (f"--> Self env vars { self .env_vars } " , "green" )
146
- return self .run_command (* args , env_vars = self .env_vars )
154
+ return self .run_command (* args , env_vars = self .env_vars , user = user , group = group )
147
155
148
- def convert (self , input_file , output_file ):
156
+ def convert (self , input_file , output_file , user = None , group = None ):
149
157
"""
150
158
Convert a MyST markdown file to another format.
151
159
@@ -156,4 +164,4 @@ def convert(self, input_file, output_file):
156
164
Returns:
157
165
str: Command output or None if failed.
158
166
"""
159
- return self .run_command ('convert' , input_file , '-o' , output_file ,env_vars = [] )
167
+ return self .run_command ('convert' , input_file , '-o' , output_file ,env_vars = self . env_vars , user = user , group = group )
0 commit comments