Skip to content

Commit

Permalink
improve dynamic version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jan 12, 2024
1 parent 11f4714 commit f6786ea
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _LOCAL/
/config.yaml
/data
/*.log
kleinanzeigen_bot/version.py
kleinanzeigen_bot/_version.py
downloaded-ads

# python
Expand All @@ -19,6 +19,7 @@ __pycache__
/.eggs
/*.egg-info
/.mypy_cache
/.pdm-build/
/.pdm-python

# Eclipse
Expand Down
3 changes: 2 additions & 1 deletion kleinanzeigen_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from . import utils, resources, extract # pylint: disable=W0406
from .utils import abspath, apply_defaults, ensure, is_frozen, pause, pluralize, safe_get, parse_datetime
from .selenium_mixin import SeleniumMixin
from ._version import __version__

# W0406: possibly a bug, see https://github.com/PyCQA/pylint/issues/3933

Expand Down Expand Up @@ -65,7 +66,7 @@ def __del__(self) -> None:
self.webdriver = None

def get_version(self) -> str:
return importlib.metadata.version(__package__).removesuffix(".editable")
return __version__

def run(self, args:list[str]) -> None:
self.parse_args(args)
Expand Down
7 changes: 5 additions & 2 deletions pyinstaller.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanze
PyInstaller config file, see https://pyinstaller.readthedocs.io/en/stable/spec-files.html
"""
from PyInstaller.utils.hooks import copy_metadata, collect_data_files
from PyInstaller.utils.hooks import collect_data_files

datas = [
* copy_metadata('kleinanzeigen_bot'), # required to get version info
* collect_data_files("kleinanzeigen_bot"), # embeds *.yaml files
* collect_data_files("selenium_stealth"), # embeds *.js files

# required to get version info via 'importlib.metadata.version(__package__)'
# but we use https://backend.pdm-project.org/metadata/#writing-dynamic-version-to-file
# * copy_metadata('kleinanzeigen_bot'),
]

excluded_modules = [
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Issues = "https://github.com/Second-Hand-Friends/kleinanzeigen-bot/issues"
[tool.pdm.version] # https://backend.pdm-project.org/metadata/#dynamic-project-version
source = "call"
getter = "version:get_version"
write_to = "kleinanzeigen_bot/_version.py"
write_template = "__version__ = '{}'\n"

[tool.pdm.dev-dependencies]
dev = [
Expand Down

0 comments on commit f6786ea

Please sign in to comment.