From da6d58faa47b64b3d1b8f238cb8878bfaf46f7a0 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Tue, 16 Jul 2019 15:33:04 +0200 Subject: [PATCH] try to install file --- .gitignore | 3 ++ .travis.yml | 4 ++- .../plugins.xml.template | 4 +-- qgispluginci/release.py | 19 +++++++++++-- qgispluginci/utils.py | 9 ++++++ scripts/qgis-plugin-ci | 13 +++++---- setup.py | 28 ++++++++++--------- test/test_release.py | 3 +- 8 files changed, 58 insertions(+), 25 deletions(-) rename {templates => qgispluginci}/plugins.xml.template (87%) diff --git a/.gitignore b/.gitignore index 519a48c7..b9cc85a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Sphinx documentation docs/_build/ docs/_autosummary/ +build/ +dist/ +*.egg-info __pycache__/ *.pyc diff --git a/.travis.yml b/.travis.yml index 800a4277..b0a2156b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,9 @@ env: # github_token - secure: "Rotw5IvMPKugnm+Ohvrt2RZNGZK2beQIg2IEfvVK+2f37QeySehs/JoekI7xMPdKtlp2TX9ZT3WY29y6E192GmarCsFjuCbJWZ0PFvOIJSb5zmjO1L3HSTbNMTCU8Kewiv0LODM9k/KoXraizOQYewnD52bjgO3BupfYcRtODuyQDYFThZ9a5S6cvEGr4iV34Uviwlm0rLvWrwncfsoKH/2WAzDdChXhNoawtJugF2OHhZcXm1gXdHPfhWiNIzpZVO01wdt4PPSOBj/cGCVXTaWN/yus8qoF3xaPzB85dsox2H34IBsllJCV+/AFjbpwJD6LZbD7tgLDknmj7ILTFG7/B/ddSuEycxcO9+C4njRVxZFxg9/Lu3No1iDA5tMpiFUbAbXPzZL013tXo4DTbth2EnaaDPtY0pwvq9yZX/Or7Z3EFsYGyKPnN3cOiT4UWrZ04fqTyeMtW7jBR+6vOKkM9rw0dJ1yAqQbNgFZ428ktB9oknHxAkKuBieXceaeC3jaT9NSOybzwvPWDh3J5OD0InsaaQF7mK8DA7F15YbrU46vEL5H5TTcz57w+TMbo/VsxVWR8rhTCR3DvzmgwAwqU0pU95m/Uj8QoZTLIaf+qCCeX/Vj0q1k/b2aWAKV7IJm3vWOPalk+TYo5FByp9RCCN8dSHcBBZfSxrALslA=" -install: pip install -r requirements.txt +install: + - pip install -r requirements.txt + - python setup.py install script: - nose2 -v diff --git a/templates/plugins.xml.template b/qgispluginci/plugins.xml.template similarity index 87% rename from templates/plugins.xml.template rename to qgispluginci/plugins.xml.template index d19f52f4..d735c7b7 100644 --- a/templates/plugins.xml.template +++ b/qgispluginci/plugins.xml.template @@ -14,8 +14,8 @@ __RELEASE_DATE__ __EXPERIMENTAL__ __DEPRECATED__ - https://github.com/__ORG__/__REPO__/issues - https://github.com/__ORG__/__REPO__ + __ISSUE_TRACKER__ + __REPO__ __TAGS__ diff --git a/qgispluginci/release.py b/qgispluginci/release.py index ea47b0e9..6b0196da 100644 --- a/qgispluginci/release.py +++ b/qgispluginci/release.py @@ -10,16 +10,18 @@ from github import Github, GithubException import xmlrpc.client import re +import pkg_resources from qgispluginci.parameters import Parameters from qgispluginci.translation import Translation -from qgispluginci.utils import replace_in_file +from qgispluginci.utils import replace_in_file, configure_file from qgispluginci.exceptions import GithubReleaseNotFound, GithubReleaseCouldNotUploadAsset def release(parameters: Parameters, release_version: str, github_token: str = None, + upload_plugin_repo_github: str = False, transifex_token: str = None, osgeo_username: str = None, osgeo_password: str = None): @@ -42,8 +44,11 @@ def release(parameters: Parameters, output = '{project_slug}-{release_version}.zip'.format(project_slug=parameters.project_slug, release_version=release_version) create_archive(parameters, output=output, add_translations=transifex_token is not None) - if github_token: + if github_token is not None: upload_asset_to_github_release(parameters, archive=output, release_tag=release_version, github_token=github_token) + if upload_plugin_repo_github: + xml_repo = create_plugin_repo() + if osgeo_username is not None: assert osgeo_password is not None upload_plugin_to_osgeo(username=osgeo_username, password=osgeo_password, archive=output) @@ -133,6 +138,16 @@ def upload_asset_to_github_release(parameters: Parameters, raise GithubReleaseCouldNotUploadAsset('Could not upload asset for release {}.'.format(release_tag)) +def create_plugin_repo() -> str: + """ + Creates the plugin repo as an XML file + """ + xml_template = pkg_resources.resource_filename('qgispluginci', 'plugins.xml.template') + _, xml_repo = mkstemp(suffix='.xml') + configure_file(xml_template, xml_repo, {}) + return xml_repo + + def upload_plugin_to_osgeo(username: str, password: str, archive: str): """ Upload the plugin to QGIS repository diff --git a/qgispluginci/utils.py b/qgispluginci/utils.py index b48286cb..864f4fd0 100644 --- a/qgispluginci/utils.py +++ b/qgispluginci/utils.py @@ -10,6 +10,15 @@ def replace_in_file(file_path: str, pattern: str, new: str, encoding = "utf8"): f.write(content) +def configure_file(source_file: str, dest_file: str, replace: dict): + with open(source_file, 'r') as f: + content = f.read() + for pattern, new in replace.items(): + content = re.sub(pattern, new, content, flags=re.M) + with open(dest_file, 'w') as f: + f.write(content) + + def touch_file(path, update_time: bool = False, create_dir: bool = True): basedir = os.path.dirname(path) if create_dir and not os.path.exists(basedir): diff --git a/scripts/qgis-plugin-ci b/scripts/qgis-plugin-ci index 930848b3..40c61770 100755 --- a/scripts/qgis-plugin-ci +++ b/scripts/qgis-plugin-ci @@ -25,6 +25,8 @@ if __name__ == "__main__": 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.') # pull-translation @@ -56,19 +58,18 @@ if __name__ == "__main__": success = release(parameters, release_version=args.release_version, transifex_token=args.transifex_token, - github_token=args.github_token) + github_token=args.github_token, + upload_plugin_repo_github=args.create_plugin_repo) if not success: exit_val = 1 elif args.command == 'pull-translation': - success = Translation(parameters, args.transifex_token).pull() - if not success: - exit_val = 1 + success = Translation(parameters, args.transifex_token).pull() + if not success: + exit_val = 1 elif args.command == 'push-translation': t = Translation(parameters, args.transifex_token) t.update_strings() t.push() - if not success: - exit_val = 1 exit(exit_val) diff --git a/setup.py b/setup.py index 021a4502..dc5ffe59 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup import sys -python_min_version = (3, 7) +python_min_version=(3, 7) if sys.version_info < python_min_version: sys.exit('qgis-plugin-ci requires at least Python version {vmaj}.{vmin}.\n' @@ -11,28 +11,30 @@ curver=sys.version)) setup( - name = 'qgis-plugin-ci', - packages = [ + name='qgis-plugin-ci', + packages=[ 'qgispluginci' ], - scripts = [ + scripts=[ 'scripts/qgis-plugin-ci' ], - version = '[VERSION]', - description = 'Let QGIS-plugin-ci package and release your QGIS plugins for you.', - author = 'Denis Rouzaud', - author_email = 'denis.rouzaud@gmail.com', - url = 'https://github.com/opengisch/qgis-plugin-ci', - download_url = 'https://github.com/opengisch/qgis-plugin-ci/archive/[VERSION].tar.gz', # I'll explain this in a second - keywords = ['QGIS'], - classifiers = [ + package_data={'': ['plugins.xml.template']}, + include_package_data=True, # required for files in MANIFEST.in + version='[VERSION]', + description='Let QGIS-plugin-ci package and release your QGIS plugins for you. Have a tea or go skiing meanwhile.', + author='Denis Rouzaud', + author_email='denis.rouzaud@gmail.com', + url='https://github.com/opengisch/qgis-plugin-ci', + download_url='https://github.com/opengisch/qgis-plugin-ci/archive/[VERSION].tar.gz', + keywords=['QGIS'], + classifiers=[ 'Topic :: Scientific/Engineering :: GIS', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 'Intended Audience :: System Administrators', 'Intended Audience :: Information Technology', 'Development Status :: 3 - Alpha' ], - install_requires = [ + install_requires=[ 'python-slugify', 'pyyaml', 'pytransifex', diff --git a/test/test_release.py b/test/test_release.py index 78021f26..c036ec5b 100644 --- a/test/test_release.py +++ b/test/test_release.py @@ -49,7 +49,7 @@ def test_release_with_transifex(self): release(self.parameters, RELEASE_VERSION_TEST, transifex_token=self.transifex_token) def test_release_upload_github(self): - release(self.parameters, RELEASE_VERSION_TEST, github_token=self.github_token) + release(self.parameters, RELEASE_VERSION_TEST, github_token=self.github_token, upload_plugin_repo_github=True) gh_release = self.repo.get_release(id=RELEASE_VERSION_TEST) archive_name = 'qgis-plugin-ci-{}.zip'.format(RELEASE_VERSION_TEST) @@ -63,5 +63,6 @@ def test_release_upload_github(self): self.assertTrue(False, 'asset not found') + if __name__ == '__main__': unittest.main() \ No newline at end of file