chiark / gitweb /
documentation/python: define an environment variable when generating.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 8 Oct 2020 10:17:31 +0000 (12:17 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 8 Oct 2020 10:17:31 +0000 (12:17 +0200)
I need that for some REALLY DIRTY hacks.

doc/documentation/python.rst
documentation/python.py

index 4476a3848c796a45fd5eaf571f3d2b14889b675e..b776243049d16ac4ec19c24fd9788f80f51aa88b 100644 (file)
@@ -505,6 +505,13 @@ option:
         'fastmath._native': 'fastmath'
     }
 
+.. block-warning:: Overrides based an environment variable
+
+    When m.css is run, an environment variable named
+    :sh:`$MCSS_GENERATING_OUTPUT` is set. This can be used for *really dirty*
+    hacks when monkey-patching imported modules is not enough (for example in
+    order to change behavior inside native modules).
+
 `Docstrings`_
 -------------
 
index 0c750426788c36e839e1c8d7a09299b410f75ed9..48b0bd6f3724d374389fbae9f6f5ad5231cfd32a 100755 (executable)
@@ -2677,6 +2677,14 @@ if __name__ == '__main__': # pragma: no cover
     parser.add_argument('--debug', help="verbose debug output", action='store_true')
     args = parser.parse_args()
 
+    # Set an environment variable indicating m.css is being run. This can be
+    # used for REALLY DIRTY hacks when monkey-patching imported modules is not
+    # enough (for example in order to change behavior inside native modules and
+    # such)
+    #
+    # Since this is done here in __main__, it can't be checked by a test.
+    os.environ['MCSS_GENERATING_OUTPUT'] = '1'
+
     # Load configuration from a file, update the defaults with it
     config = copy.deepcopy(default_config)
     name, _ = os.path.splitext(os.path.basename(args.conf))