# HG changeset patch
# User paugier <pierre.augier@univ-grenoble-alpes.fr>
# Date 1736866516 -3600
#      Tue Jan 14 15:55:16 2025 +0100
# Node ID 9ff926737dbca0f3efaa4ad6f03e164cc4f1e11d
# Parent  38b5bf8247940d125987b9c6a7eac439453729e5
setup: __modulepolicy__.py created in the source dir for editable mode

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -495,9 +495,6 @@
                 )
 
     def run(self):
-        basepath = os.path.join(self.build_lib, 'mercurial')
-        self.mkpath(basepath)
-
         rust = self.distribution.rust
         if self.distribution.pure:
             modulepolicy = 'py'
@@ -513,6 +510,14 @@
                 b'modulepolicy = b"%s"\n' % modulepolicy.encode('ascii'),
             ]
         )
+
+        if self.editable_mode:
+            here = os.path.dirname(__file__)
+            basepath = os.path.join(here, 'mercurial')
+        else:
+            basepath = os.path.join(self.build_lib, 'mercurial')
+            self.mkpath(basepath)
+
         write_if_changed(os.path.join(basepath, '__modulepolicy__.py'), content)
 
         build_py.run(self)