Browse Source

Merge fixup (imports, deployment)

- Now uses runpy to run borg as a package directly
- Copy borg package to library directory, that way Python finds it all automatically
  via program name
Marian Beermann 9 years ago
parent
commit
ed05b4ceff

+ 14 - 14
deployment/windows/buildwin32.py

@@ -1,8 +1,11 @@
 import shutil
 import os
 import subprocess
+import sys
 from modulefinder import ModuleFinder
 
+import borg
+
 # Creates standalone Windows executable
 # First build by following instructions from installation.rst
 
@@ -42,20 +45,15 @@ int wmain(int argc , wchar_t *argv[] )
 
     PySys_SetArgv(argc, argv);
 
-    wchar_t path[MAX_PATH];
-    GetModuleFileNameW(NULL, path, MAX_PATH);
-    PathRemoveFileSpecW(path);
-
-    FILE* file_1 = _wfopen(wcsncat(path, L"/borg/__main__.py", 17), L"r");
-    PyRun_AnyFile(file_1, "borg/__main__.py");
+    PyRun_SimpleString("from runpy import run_module\\n"
+                       "run_module('borg')");
 
     Py_Finalize();
-    PyMem_RawFree(program);
     return 0;
 }
 """)
 source.close()
-subprocess.run('gcc wrapper.c -lpython3.5m -lshlwapi -municode -o ' + builddir + '/bin/borg.exe')
+subprocess.check_call('gcc wrapper.c -lpython3.5m -lshlwapi -municode -o ' + builddir + '/bin/borg.exe')
 os.remove('wrapper.c')
 
 print('Searching modules')
@@ -65,7 +63,7 @@ modulepath = os.path.abspath(os.path.join(gccpath, '../lib/python3.5/'))
 shutil.copytree(os.path.join(modulepath, 'encodings'), os.path.join(builddir, 'lib/python3.5/encodings'))
 
 finder = ModuleFinder()
-finder.run_script('borg/__main__.py')
+finder.run_script(os.path.join(borg.__path__[0], '__main__.py'))
 extramodules = [os.path.join(modulepath, 'site.py')]
 
 for module in extramodules:
@@ -98,9 +96,10 @@ for name, mod in items:
         continue
     lib = file.find('lib')
     if lib == -1:
-        relpath = os.path.relpath(file)
-        os.makedirs(os.path.join(builddir, 'bin', os.path.split(relpath)[0]), exist_ok=True)
-        shutil.copyfile(file, os.path.join(builddir, 'bin', relpath))
+        # Part of the borg package
+        relpath = os.path.relpath(file)[4:]
+        os.makedirs(os.path.join(builddir, 'lib', 'python3.5', os.path.split(relpath)[0]), exist_ok=True)
+        shutil.copyfile(file, os.path.join(builddir, 'lib', 'python3.5', relpath))
         continue
     relativepath = file[file.find('lib')+4:]
     os.makedirs(os.path.join(builddir, 'lib', os.path.split(relativepath)[0]), exist_ok=True)
@@ -112,9 +111,10 @@ for name, mod in items:
 for dll in finddlls(os.path.join(builddir, "bin/borg.exe")):
     if builddir not in dll:
         shutil.copyfile(dll, os.path.join(builddir, 'bin', os.path.split(dll)[1]))
-shutil.copyfile('borg/__main__.py', os.path.join(builddir, 'bin/borg/__main__.py'))
 
-for extmodule in ['borg/chunker-cpython-35m.dll', 'borg/compress-cpython-35m.dll', 'borg/crypto-cpython-35m.dll', 'borg/hashindex-cpython-35m.dll']:
+shutil.copyfile('src/borg/__main__.py', os.path.join(builddir, 'lib/python3.5/borg/__main__.py'))
+
+for extmodule in ['src/borg/chunker-cpython-35m.dll', 'src/borg/compress-cpython-35m.dll', 'src/borg/crypto-cpython-35m.dll', 'src/borg/hashindex-cpython-35m.dll']:
     for dll in finddlls(extmodule):
         if builddir not in dll:
             shutil.copyfile(dll, os.path.join(builddir, 'bin', os.path.split(dll)[1]))

+ 3 - 3
deployment/windows/installer.iss

@@ -2,7 +2,7 @@
 #define MyAppVersion "1.1"
 #define MyAppPublisher "The Borg Collective"
 #define MyAppURL "https://borgbackup.rtfd.org/"
-#define MyAppExeName "borg-shell.bat"
+#define MyAppExeName "bin/borg.exe"
 
 [Setup]
 AppId={{1B6E8CD4-25F2-4400-A53F-4338D6614475}
@@ -16,7 +16,8 @@ AppUpdatesURL={#MyAppURL}
 DefaultDirName={pf}\{#MyAppName}
 DefaultGroupName={#MyAppName}
 AllowNoIcons=yes
-LicenseFile=LICENSE
+LicenseFile=LICENSE
+InfoBeforeFile=AUTHORS
 OutputBaseFilename=Borg Backup {#MyAppVersion} Setup
 Compression=lzma/normal
 SolidCompression=yes
@@ -31,7 +32,6 @@ Name: "english"; MessagesFile: "compiler:Default.isl"
 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
 
 [Files]
-Source: "deployment\windows\borg-shell.bat"; DestDir: "{app}"; Flags: ignoreversion
 Source: "win32exe\bin\*"; DestDir: "{app}\bin"; Flags: replacesameversion recursesubdirs
 Source: "win32exe\lib\*"; DestDir: "{app}\lib"; Flags: replacesameversion recursesubdirs
 ; NOTE: Don't use "Flags: ignoreversion" on any shared system files

+ 1 - 1
setup.py

@@ -345,7 +345,7 @@ if not on_rtd:
 
 
 def parse(root, describe_command=None):
-    file = open('borg/_version.py', 'w')
+    file = open('src/borg/_version.py', 'w')
     output = subprocess.check_output("git describe --tags --long").decode().strip()
     file.write('version = "' + output + '"\n')
     return output

+ 8 - 8
src/borg/helpers.py

@@ -1,11 +1,3 @@
-
-if sys.platform != 'win32':
-    import grp
-    import pwd
-else:
-    import posixpath
-    import encodings.idna
-
 import argparse
 import hashlib
 import logging
@@ -28,6 +20,14 @@ from itertools import islice
 from operator import attrgetter
 from string import Formatter
 
+if sys.platform != 'win32':
+    import grp
+    import pwd
+else:
+    import posixpath
+    import encodings.idna
+
+
 import msgpack
 import msgpack.fallback
 

+ 1 - 1
src/borg/platform/windows.pyx

@@ -8,7 +8,7 @@ cimport cpython.array
 import array
 
 import platform
-from .helpers import safe_decode, safe_encode
+from ..helpers import safe_decode, safe_encode
 
 API_VERSION = 3