def setUp(self): arg_dict = yaml.safe_load(open(".qgis-plugin-ci")) self.parameters = Parameters(arg_dict) self.transifex_token = os.getenv('transifex_token') assert self.transifex_token is not None self.t = Translation(self.parameters, transifex_token=self.transifex_token)
def setUp(self): with open(".qgis-plugin-ci") as f: arg_dict = yaml.safe_load(f) self.parameters = Parameters(arg_dict) self.transifex_token = os.getenv("transifex_token") self.assertIsNotNone(self.transifex_token) self.t = Translation(self.parameters, transifex_token=self.transifex_token)
class TestTranslation(unittest.TestCase): def setUp(self): arg_dict = yaml.safe_load(open(".qgis-plugin-ci")) self.parameters = Parameters(arg_dict) self.transifex_token = os.getenv('transifex_token') assert self.transifex_token is not None self.t = Translation(self.parameters, transifex_token=self.transifex_token) def tearDown(self): try: self.t._t.delete_project(self.parameters.project_slug) except PyTransifexException: pass def test_creation(self): self.t = Translation(self.parameters, transifex_token=self.transifex_token) self.tearDown() self.t = Translation(self.parameters, transifex_token=self.transifex_token) def test_pull(self): self.t.pull() self.t.compile_strings() def test_push(self): self.t.update_strings() self.t.push()
class TestTranslation(unittest.TestCase): def setUp(self): with open(".qgis-plugin-ci") as f: arg_dict = yaml.safe_load(f) self.parameters = Parameters(arg_dict) self.transifex_token = os.getenv("transifex_token") self.assertIsNotNone(self.transifex_token) self.t = Translation(self.parameters, transifex_token=self.transifex_token) def tearDown(self): try: self.t._t.delete_project(self.parameters.project_slug) except PyTransifexException: pass try: self.t._t.delete_team("{}-team".format( self.parameters.project_slug)) except PyTransifexException: pass @unittest.skipIf(can_skip_test(), "Missing transifex_token") def test_creation(self): self.t = Translation(self.parameters, transifex_token=self.transifex_token) self.tearDown() self.t = Translation(self.parameters, transifex_token=self.transifex_token) @unittest.skipIf(can_skip_test(), "Missing transifex_token") def test_pull(self): self.t.pull() self.t.compile_strings() @unittest.skipIf(can_skip_test(), "Missing transifex_token") def test_push(self): self.t.update_strings() self.t.push()
def main(): # create the top-level parser parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("-v", "--version", help="print the version and exit", action="store_true") subparsers = parser.add_subparsers(title="commands", description="qgis-plugin-ci command", dest="command") # package package_parser = subparsers.add_parser( "package", help="creates an archive of the plugin") package_parser.add_argument("release_version", help="The version to be released") package_parser.add_argument( "--transifex-token", help= "The Transifex API token. If specified translations will be pulled and compiled.", ) package_parser.add_argument( "-u", "--plugin-repo-url", help= "If specified, a XML repository file will be created in the current directory, the zip URL will use this parameter.", ) package_parser.add_argument( "-c", "--allow-uncommitted-changes", action="store_true", help= "If omitted, uncommitted changes are not allowed before packaging. If specified and some changes are " "detected, a hard reset on a stash create will be used to revert changes made by qgis-plugin-ci.", ) package_parser.add_argument( "-d", "--disable-submodule-update", action="store_true", help= "If omitted, a git submodule is updated. If specified, git submodules will not be updated/initialized before packaging.", ) # changelog changelog_parser = subparsers.add_parser("changelog", help="gets the changelog content") changelog_parser.add_argument( "release_version", help="The version to be released. If nothing is speficied, \ the latest version specified into the changelog is used.", default="latest", ) # release release_parser = subparsers.add_parser("release", help="release the plugin") release_parser.add_argument("release_version", help="The version to be released (x.y.z).") release_parser.add_argument( "--release-tag", help="The release tag, if different from the version (e.g. vx.y.z).", ) release_parser.add_argument( "--transifex-token", help= "The Transifex API token. If specified translations will be pulled and compiled.", ) release_parser.add_argument( "--github-token", help= "The Github API token. If specified, the archive will be pushed to an already existing release.", ) release_parser.add_argument( "--create-plugin-repo", action="store_true", help= "Will create a XML repo as a Github release asset. Github token is required.", ) release_parser.add_argument( "--allow-uncommitted-changes", action="store_true", help= "If omitted, uncommitted changes are not allowed before releasing. If specified and some changes are " "detected, a hard reset on a stash create will be used to revert changes made by qgis-plugin-ci.", ) release_parser.add_argument( "--disable-submodule-update", action="store_true", help= "If omitted, a git submodule is updated. If specified, git submodules will not be updated/initialized before packaging.", ) release_parser.add_argument( "--osgeo-username", help="The Osgeo user name to publish the plugin.") release_parser.add_argument( "--osgeo-password", help="The Osgeo password to publish the plugin.") # pull-translation pull_tr_parser = subparsers.add_parser( "pull-translation", help="pull translations from Transifex") pull_tr_parser.add_argument("transifex_token", help="The Transifex API token") pull_tr_parser.add_argument("--compile", action="store_true", help="Will compile TS files into QM files") # push-translation push_tr_parser = subparsers.add_parser( "push-translation", help="update strings and push translations") push_tr_parser.add_argument("transifex_token", help="The Transifex API token") args = parser.parse_args() # print the version and exit if args.version: import pkg_resources print("qgis-plugin-ci version: {}".format( pkg_resources.get_distribution("qgis-plugin-ci").version)) parser.exit() # if no command is passed, print the help and exit if not args.command: parser.print_help() parser.exit() exit_val = 0 if os.path.isfile(".qgis-plugin-ci"): # We read the .qgis-plugin-ci file with open(".qgis-plugin-ci", "r", encoding="utf8") as f: arg_dict = yaml.safe_load(f) else: config = configparser.ConfigParser() config.read("setup.cfg") if "qgis-plugin-ci" in config.sections(): # We read the setup.cfg file arg_dict = dict(config.items("qgis-plugin-ci")) else: # We don't have either a .qgis-plugin-ci or a setup.cfg if args.command == "changelog": # but for the "changelog" sub command, the config file is not required, we can continue arg_dict = dict() else: raise ConfigurationNotFound( ".qgis-plugin-ci or setup.cfg with a 'qgis-plugin-ci' section have not been found." ) parameters = Parameters(arg_dict) # CHANGELOG if args.command == "changelog": try: c = ChangelogParser(changelog_path=parameters.changelog_path, ) content = c.content(args.release_version) if content: print(content) except Exception: # Better to be safe pass return exit_val # PACKAGE if args.command == "package": release( parameters, release_version=args.release_version, transifex_token=args.transifex_token, allow_uncommitted_changes=args.allow_uncommitted_changes, plugin_repo_url=args.plugin_repo_url, disable_submodule_update=args.disable_submodule_update, ) # RELEASE elif args.command == "release": release( parameters, release_version=args.release_version, release_tag=args.release_tag, transifex_token=args.transifex_token, github_token=args.github_token, upload_plugin_repo_github=args.create_plugin_repo, osgeo_username=args.osgeo_username, osgeo_password=args.osgeo_password, allow_uncommitted_changes=args.allow_uncommitted_changes, disable_submodule_update=args.disable_submodule_update, ) # TRANSLATION PULL elif args.command == "pull-translation": t = Translation(parameters, args.transifex_token) t.pull() if args.compile: t.compile_strings() # TRANSLATION PUSH elif args.command == "push-translation": t = Translation(parameters, args.transifex_token) t.update_strings() t.push() return exit_val
def release( parameters: Parameters, release_version: str, release_tag: str = None, github_token: str = None, upload_plugin_repo_github: str = False, transifex_token: str = None, osgeo_username: str = None, osgeo_password: str = None, allow_uncommitted_changes: bool = False, plugin_repo_url: str = None, disable_submodule_update: bool = False, ): """ Parameters ---------- parameters The configuration parameters release_version: The release version (x.y.z) release_tag: The release tag (vx.y.z). If not given, the release version will be used github_token The Github token upload_plugin_repo_github If true, a custom repo will be created as a release asset on Github and could later be used in QGIS as a custom plugin repository. plugin_repo_url If set, this URL will be used to create the ZIP URL in the XML file transifex_token The Transifex token osgeo_username osgeo username to upload the plugin to official QGIS repository osgeo_password osgeo password to upload the plugin to official QGIS repository allow_uncommitted_changes If False, uncommitted changes are not allowed before packaging/releasing. If True and some changes are detected, a hard reset on a stash create will be used to revert changes made by qgis-plugin-ci. disable_submodule_update If omitted, a git submodule is updated. If specified, git submodules will not be updated/initialized before packaging. """ if transifex_token is not None: tr = Translation(parameters, create_project=False, transifex_token=transifex_token) tr.pull() tr.compile_strings() archive_name = parameters.archive_name(parameters.plugin_path, release_version) is_prerelease = False if github_token is not None: is_prerelease = release_is_prerelease(parameters, release_tag=release_version, github_token=github_token) print("*** is pre-release: {}".format("YES" if is_prerelease else "NO")) create_archive( parameters, release_version, archive_name, add_translations=transifex_token is not None, allow_uncommitted_changes=allow_uncommitted_changes, is_prerelease=is_prerelease, disable_submodule_update=disable_submodule_update, ) # if pushing to QGIS repo and pre-release, create an extra package with qgisMinVersion to 3.14 # since only QGIS 3.14+ supports the beta/experimental plugins trial experimental_archive_name = None if osgeo_username is not None and is_prerelease: experimental_archive_name = parameters.archive_name( parameters.plugin_path, release_version, True) create_archive( parameters, release_version, experimental_archive_name, add_translations=transifex_token is not None, allow_uncommitted_changes=allow_uncommitted_changes, is_prerelease=True, raise_min_version="3.14", disable_submodule_update=disable_submodule_update, ) if github_token is not None: upload_asset_to_github_release( parameters, asset_path=archive_name, release_tag=release_version, github_token=github_token, ) if upload_plugin_repo_github: xml_repo = create_plugin_repo( parameters=parameters, release_version=release_version, release_tag=release_tag, archive=archive_name, osgeo_username=osgeo_username, ) upload_asset_to_github_release( parameters, asset_path=xml_repo, release_tag=release_version, github_token=github_token, asset_name="plugins.xml", ) if plugin_repo_url: xml_repo = create_plugin_repo( parameters=parameters, release_version=release_version, release_tag=release_tag, archive=archive_name, osgeo_username=osgeo_username, plugin_repo_url=plugin_repo_url, ) print("Local XML repo file created : {}".format(xml_repo)) if osgeo_username is not None: assert osgeo_password is not None if is_prerelease: assert experimental_archive_name is not None upload_plugin_to_osgeo( username=osgeo_username, password=osgeo_password, archive=experimental_archive_name, ) else: upload_plugin_to_osgeo(username=osgeo_username, password=osgeo_password, archive=archive_name)
def test_release_with_transifex(self): assert self.transifex_token is not None t = Translation(self.parameters, transifex_token=self.transifex_token) release(self.parameters, RELEASE_VERSION_TEST, transifex_token=self.transifex_token)
def main(): # create the top-level parser parser = argparse.ArgumentParser() parser.add_argument("-v", "--version", help="print the version and exit", action='store_true') subparsers = parser.add_subparsers(title='commands', description='qgis-plugin-ci command', dest='command') # package package_parser = subparsers.add_parser( 'package', help='creates an archive of the plugin') package_parser.add_argument('release_version', help='The version to be released') package_parser.add_argument( '--transifex-token', help= 'The Transifex API token. If specified translations will be pulled and compiled.' ) package_parser.add_argument( '--plugin-repo-url', help= 'If specified, a XML repository file will be created in the current directory, the zip URL will use this parameter.' ) package_parser.add_argument( '--allow-uncommitted-changes', action='store_true', help= 'If omitted, uncommitted changes are not allowed before packaging. If specified and some changes are ' 'detected, a hard reset on a stash create will be used to revert changes made by qgis-plugin-ci.' ) package_parser.add_argument( '--disable-submodule-update', action='store_true', help= 'If omitted, a git submodule is updated. If specified, git submodules will not be updated/initialized before packaging.' ) # changelog changelog_parser = subparsers.add_parser('changelog', help='gets the changelog content') changelog_parser.add_argument('release_version', help='The version to be released') # release release_parser = subparsers.add_parser('release', help='release the plugin') release_parser.add_argument('release_version', help='The version to be released') release_parser.add_argument( '--transifex-token', help= 'The Transifex API token. If specified translations will be pulled and compiled.' ) release_parser.add_argument( '--github-token', help= 'The Github API token. If specified, the archive will be pushed to an already existing release.' ) release_parser.add_argument( '--create-plugin-repo', action='store_true', help= 'Will create a XML repo as a Github release asset. Github token is required.' ) release_parser.add_argument( '--allow-uncommitted-changes', action='store_true', help= 'If omitted, uncommitted changes are not allowed before releasing. If specified and some changes are ' 'detected, a hard reset on a stash create will be used to revert changes made by qgis-plugin-ci.' ) release_parser.add_argument( '--disable-submodule-update', action='store_true', help= 'If omitted, a git submodule is updated. If specified, git submodules will not be updated/initialized before packaging.' ) release_parser.add_argument( '--osgeo-username', help='The Osgeo user name to publish the plugin.') release_parser.add_argument( '--osgeo-password', help='The Osgeo password to publish the plugin.') # pull-translation pull_tr_parser = subparsers.add_parser( 'pull-translation', help='pull translations from Transifex') pull_tr_parser.add_argument('transifex_token', help='The Transifex API token') pull_tr_parser.add_argument('--compile', action='store_true', help='Will compile TS files into QM files') # push-translation push_tr_parser = subparsers.add_parser( 'push-translation', help='update strings and push translations') push_tr_parser.add_argument('transifex_token', help='The Transifex API token') args = parser.parse_args() # print the version and exit if args.version: import pkg_resources print('qgis-plugin-ci version: {}'.format( pkg_resources.get_distribution('qgis-plugin-ci').version)) parser.exit() # if no command is passed, print the help and exit if not args.command: parser.print_help() parser.exit() exit_val = 0 if os.path.isfile(".qgis-plugin-ci"): arg_dict = yaml.safe_load(open(".qgis-plugin-ci")) else: config = configparser.ConfigParser() config.read("setup.cfg") if "qgis-plugin-ci" not in config.sections(): raise ConfigurationNotFound( ".qgis-plugin-ci or setup.cfg with a 'qgis-plugin-ci' section have not been found." ) arg_dict = dict(config.items("qgis-plugin-ci")) parameters = Parameters(arg_dict) # PACKAGE if args.command == 'package': release( parameters, release_version=args.release_version, transifex_token=args.transifex_token, allow_uncommitted_changes=args.allow_uncommitted_changes, plugin_repo_url=args.plugin_repo_url, disable_submodule_update=args.disable_submodule_update, ) # RELEASE elif args.command == 'release': release( parameters, release_version=args.release_version, transifex_token=args.transifex_token, github_token=args.github_token, upload_plugin_repo_github=args.create_plugin_repo, osgeo_username=args.osgeo_username, osgeo_password=args.osgeo_password, allow_uncommitted_changes=args.allow_uncommitted_changes, disable_submodule_update=args.disable_submodule_update, ) # CHANGELOG elif args.command == 'changelog': try: c = ChangelogParser(parameters.changelog_regexp) content = c.content(args.release_version) if content: print(content) except Exception: # Better to be safe pass # TRANSLATION PULL elif args.command == 'pull-translation': t = Translation(parameters, args.transifex_token) t.pull() if args.compile: t.compile_strings() # TRANSLATION PUSH elif args.command == 'push-translation': t = Translation(parameters, args.transifex_token) t.update_strings() t.push() return exit_val
def test_creation(self): self.t = Translation(self.parameters, transifex_token=self.transifex_token) self.tearDown() self.t = Translation(self.parameters, transifex_token=self.transifex_token)