From 7b7f863c65f127c382c7e013bd0e01d6495e7f32 Mon Sep 17 00:00:00 2001 From: FestplattenSchnitzel Date: Fri, 5 Aug 2022 19:34:28 +0200 Subject: [PATCH] [import] Rename to import_subcommand internally This enables normal import of the module without the need for workarounds. --- .gitlab-ci.yml | 3 +-- MANIFEST.in | 3 +-- fdroidserver/__main__.py | 4 ++- .../{import.py => import_subcommand.py} | 5 +--- tests/import_proxy.py | 27 ------------------- ...rt.TestCase => import_subcommand.TestCase} | 10 +++---- 6 files changed, 11 insertions(+), 41 deletions(-) rename fdroidserver/{import.py => import_subcommand.py} (98%) delete mode 100644 tests/import_proxy.py rename tests/{import.TestCase => import_subcommand.TestCase} (93%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0d8a9f06..ed1998ee 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -254,8 +254,7 @@ black: tests/build.TestCase tests/deploy.TestCase tests/exception.TestCase - tests/import.TestCase - tests/import_proxy.py + tests/import_subcommand.TestCase tests/init.TestCase tests/install.TestCase tests/key-tricks.py diff --git a/MANIFEST.in b/MANIFEST.in index 2d330a4a..33266a64 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -567,8 +567,7 @@ include tests/gnupghome/secring.gpg include tests/gnupghome/trustdb.gpg include tests/gradle-maven-blocks.yaml include tests/gradle-release-checksums.py -include tests/import_proxy.py -include tests/import.TestCase +include tests/import_subcommand.TestCase include tests/index.TestCase include tests/init.TestCase include tests/install.TestCase diff --git a/fdroidserver/__main__.py b/fdroidserver/__main__.py index 037c33d5..e470099c 100755 --- a/fdroidserver/__main__.py +++ b/fdroidserver/__main__.py @@ -40,7 +40,7 @@ COMMANDS = OrderedDict([ ("deploy", _("Interact with the repo HTTP server")), ("verify", _("Verify the integrity of downloaded packages")), ("checkupdates", _("Check for updates to applications")), - ("import", _("Add a new application from its source code")), + ("import", _("Extract application metadata from a source repository")), ("install", _("Install built packages on devices")), ("readmeta", _("Read all the metadata files and exit")), ("rewritemeta", _("Rewrite all the metadata files")), @@ -197,6 +197,8 @@ def main(): del sys.argv[1] if command in COMMANDS.keys(): + # import is named import_subcommand internally b/c import is reserved by Python + command = 'import_subcommand' if command == 'import' else command mod = __import__('fdroidserver.' + command, None, None, [command]) else: mod = __import__(available_plugins[command]['name'], None, None, [command]) diff --git a/fdroidserver/import.py b/fdroidserver/import_subcommand.py similarity index 98% rename from fdroidserver/import.py rename to fdroidserver/import_subcommand.py index d524632b..63aefe15 100644 --- a/fdroidserver/import.py +++ b/fdroidserver/import_subcommand.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# import.py - part of the FDroid server tools +# import_subcommand.py - part of the FDroid server tools # Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com # Copyright (C) 2013-2014 Daniel Martí # @@ -42,9 +42,6 @@ config = None options = None -# WARNING! This cannot be imported as a Python module, so reuseable functions need to go into common.py! - - def clone_to_tmp_dir(app): tmp_dir = Path('tmp') tmp_dir.mkdir(exist_ok=True) diff --git a/tests/import_proxy.py b/tests/import_proxy.py deleted file mode 100644 index 5a6dfced..00000000 --- a/tests/import_proxy.py +++ /dev/null @@ -1,27 +0,0 @@ -# workaround the syntax error from: import fdroidserver.import - -import inspect -import sys -from pathlib import Path - -localmodule = Path(__file__).resolve().parent.parent -print('localmodule: ' + str(localmodule)) -if localmodule not in sys.path: - sys.path.insert(0, str(localmodule)) - - -class Options: - def __init__(self): - self.rev = None - self.subdir = None - - -module = __import__('fdroidserver.import') -for name, obj in inspect.getmembers(module): - if name == 'import': - clone_to_tmp_dir = obj.clone_to_tmp_dir - obj.options = Options() - options = obj.options - break - -globals().update(vars(module)) diff --git a/tests/import.TestCase b/tests/import_subcommand.TestCase similarity index 93% rename from tests/import.TestCase rename to tests/import_subcommand.TestCase index 81aeac39..f4400e40 100755 --- a/tests/import.TestCase +++ b/tests/import_subcommand.TestCase @@ -15,15 +15,13 @@ from pathlib import Path import requests from testcommon import TmpCwd -# work around the syntax error from: import fdroidserver.import -import import_proxy - localmodule = Path(__file__).resolve().parent.parent print('localmodule: ' + str(localmodule)) if localmodule not in sys.path: sys.path.insert(0, str(localmodule)) import fdroidserver.common +import fdroidserver.import_subcommand import fdroidserver.metadata @@ -37,6 +35,8 @@ class ImportTest(unittest.TestCase): self.tmpdir.mkdir(exist_ok=True) # TODO: Python3.6: Accepts a path-like object. os.chdir(str(self.basedir)) + fdroidserver.import_subcommand.options = mock.Mock() + fdroidserver.import_subcommand.options.rev = None def test_import_gitlab(self): # FDroidPopen needs some config to work @@ -52,7 +52,7 @@ class ImportTest(unittest.TestCase): return app = fdroidserver.common.get_app_from_url(url) - import_proxy.clone_to_tmp_dir(app) + fdroidserver.import_subcommand.clone_to_tmp_dir(app) self.assertEqual(app.RepoType, 'git') self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git') @@ -103,7 +103,7 @@ class ImportTest(unittest.TestCase): ), mock.patch( 'shutil.rmtree', lambda a, onerror=None: None ): - build_dir = import_proxy.clone_to_tmp_dir(app) + build_dir = fdroidserver.import_subcommand.clone_to_tmp_dir(app) self.assertEqual('git', app.RepoType) self.assertEqual(url, app.Repo) self.assertEqual(url, app.SourceCode)