From 38e693f4489f291ebbd584dcba4c120fdd2d0240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20S=C3=A1nchez?= Date: Tue, 13 Aug 2024 00:34:26 +0100 Subject: [PATCH] Replace old double-source with setuptools_scm (#288) --- .github/workflows/build.yml | 21 +++------------------ blackboard_sync/__about__.py | 3 --- blackboard_sync/__init__.py | 2 +- blackboard_sync/sync_controller.py | 11 +++++++++-- blackboard_sync/updates.py | 8 +++++++- docs/conf.py | 6 ++++-- pyproject.toml | 7 +++---- 7 files changed, 27 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5996f7b..bf9a80a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,25 +38,10 @@ jobs: - name: Run test suite run: pytest -vvvv - version-check: - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Check version against tag - run: | - VER=$(awk -F'["]' '/^__version__ =/ {print $2}' b*/__a*) - if [ "$GITHUB_REF_NAME" != "$VER" ]; then - echo "Version $VER does not match the GitHub tag $GITHUB_REF_NAME" - exit 1 - fi - pypi: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') - needs: [ test, version-check ] + needs: [ test ] steps: - name: Checkout repository uses: actions/checkout@v3 @@ -84,7 +69,7 @@ jobs: flatpak: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') - needs: [ test, version-check ] + needs: [ test ] env: MATURIN_REF: v1.2.3 SETUPTOOLS_RUST_REF: v1.7.0 @@ -132,7 +117,7 @@ jobs: matrix: os: [macos-latest, windows-latest] if: startsWith(github.ref, 'refs/tags/') - needs: [ test, version-check ] + needs: [ test ] env: PRE_RELEASE: ${{ contains(github.ref_name, '-') }} steps: diff --git a/blackboard_sync/__about__.py b/blackboard_sync/__about__.py index 68485a0..b2d2b16 100644 --- a/blackboard_sync/__about__.py +++ b/blackboard_sync/__about__.py @@ -22,7 +22,6 @@ "__title__", "__summary__", "__uri__", - "__version__", "__author__", "__email__", "__license__", @@ -33,8 +32,6 @@ __summary__ = "Automatic Syncing Of Your Blackboard Content" __uri__ = "https://github.com/sanjacob/BlackboardSync" -__version__ = "0.12.0-alpha.1" - __author__ = "Jacob Sánchez" __email__ = "jacobszpz@protonmail.com" diff --git a/blackboard_sync/__init__.py b/blackboard_sync/__init__.py index 07963b1..1c1dcab 100644 --- a/blackboard_sync/__init__.py +++ b/blackboard_sync/__init__.py @@ -28,7 +28,7 @@ import logging -from .__about__ import __title__, __summary__, __uri__, __version__ +from .__about__ import __title__, __summary__, __uri__ from .__about__ import __author__, __email__, __license__ from .__about__ import __copyright__ diff --git a/blackboard_sync/sync_controller.py b/blackboard_sync/sync_controller.py index f1436c5..ed59daa 100644 --- a/blackboard_sync/sync_controller.py +++ b/blackboard_sync/sync_controller.py @@ -21,13 +21,14 @@ import sys import webbrowser from typing import Optional +from importlib.metadata import version, PackageNotFoundError from PyQt6.QtCore import Qt from PyQt6.QtWidgets import QApplication, QStyleFactory, QSystemTrayIcon, QWidget from .sync import BlackboardSync from .institutions import Institution, get_names, InstitutionLogin -from .__about__ import __title__, __version__ +from .__about__ import __title__ from .updates import check_for_updates from .qt.qt_elements import (LoginWebView, SyncTrayIcon, SettingsWindow, RedownloadDialog, OSUtils, SetupWizard, UpdateFoundDialog) @@ -50,7 +51,13 @@ def __init__(self): self.app = QApplication(sys.argv) self.app.setApplicationName(__title__) - self.app.setApplicationVersion(__version__) + + try: + __version__ = version("blackboard_sync") + except PackageNotFoundError: + pass + else: + self.app.setApplicationVersion(__version__) QApplication.setStyle(QStyleFactory.create("Fusion")) diff --git a/blackboard_sync/updates.py b/blackboard_sync/updates.py index 7567f55..f888197 100644 --- a/blackboard_sync/updates.py +++ b/blackboard_sync/updates.py @@ -22,7 +22,7 @@ from pathlib import Path from typing import Optional from packaging import version -from .__about__ import __version__ +from importlib.metadata import version, PackageNotFoundError def is_inside_container() -> bool: @@ -30,6 +30,12 @@ def is_inside_container() -> bool: def check_for_updates() -> Optional[str]: """Checks if there is a newer release than the current on Github.""" + # Get version + try: + __version__ = version("blackboard_sync") + except PackageNotFoundError: + return None + url = 'https://api.github.com/repos/sanjacob/BlackboardSync/releases/latest' response = requests.get(url, timeout=2000) if response.status_code == 200: diff --git a/docs/conf.py b/docs/conf.py index a49825b..c195fbf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,6 +14,8 @@ import sys sys.path.insert(0, os.path.abspath('..')) +from importlib.metadata import version as get_version + from blackboard_sync import __about__ # -- Project information ----------------------------------------------------- @@ -23,8 +25,8 @@ author = __about__.__author__ # The full version, including alpha/beta/rc tags -release = __about__.__version__ - +release = get_version("blackboard_sync") +version = ".".join(release.split('.')[:2]) # -- General configuration --------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 415743a..8b45346 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=61.0", "setuptools_scm[toml]>=6.2"] +requires = ["setuptools>=64", "setuptools_scm>=8"] build-backend = "setuptools.build_meta" [project] @@ -36,9 +36,6 @@ dependencies = [ [project.scripts] blackboardsync = "blackboard_sync:__main__.main" -[tool.setuptools.dynamic] -version = {attr = "blackboard_sync.__version__"} - [project.optional-dependencies] test = ["pytest", "hypothesis", "coverage", "pytest-qt", "pytest-mock"] package = ["pyinstaller>=5.13.2", "build", "twine"] @@ -48,6 +45,8 @@ package = ["pyinstaller>=5.13.2", "build", "twine"] "Repository" = "https://github.com/sanjacob/BlackboardSync" "Bug Tracker" = "https://github.com/sanjacob/BlackboardSync/issues" +[tool.setuptools_scm] + [tool.setuptools] packages = [ "blackboard_sync",