Skip to content

Commit

Permalink
Replace old double-source with setuptools_scm (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacob authored Aug 12, 2024
1 parent e20da43 commit 38e693f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 31 deletions.
21 changes: 3 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions blackboard_sync/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"__title__",
"__summary__",
"__uri__",
"__version__",
"__author__",
"__email__",
"__license__",
Expand All @@ -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__ = "[email protected]"

Expand Down
2 changes: 1 addition & 1 deletion blackboard_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
11 changes: 9 additions & 2 deletions blackboard_sync/sync_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))

Expand Down
8 changes: 7 additions & 1 deletion blackboard_sync/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@
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:
return Path('/.flatpak-info').exists()

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:
Expand Down
6 changes: 4 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------------------------------
Expand All @@ -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 ---------------------------------------------------

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"]
Expand All @@ -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",
Expand Down

0 comments on commit 38e693f

Please sign in to comment.