Skip to content

Commit

Permalink
Inherit from install() class instead of install_data().
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Jan 16, 2023
1 parent 95feef8 commit e42991b
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@
"""

from pathlib import Path
import shutil
import sys

from setuptools import setup
from setuptools.command.build_py import build_py as _build_py

# Python 3.12+ doesn't ship the distutils package anymore, but setuptools vendors it.
try:
from setuptools._distutils.command.install_data import install_data as _install_data

print("Using distutils from setuptools")
except ImportError:
from distutils.command.install_data import install_data as _install_data

print("Using distutils from stdlib")
from setuptools.command.install import install as _install

REPO = Path(__file__).resolve().parent
sys.path.insert(0, str(REPO))
Expand All @@ -56,8 +48,8 @@ def run(self):


"""
We use the deprecated _install_data class since it provides the easiest way to
install data files outside of a Python package. This feature is needed for the
We use the deprecated install class since it provides the easiest way to install
data files outside of a Python package. This feature is needed for the
translation files, which must reside in <sys.prefix>/share/locale for the Glade
file to pick them up.
Expand All @@ -66,14 +58,17 @@ def run(self):
"""


class install_data(_install_data):
class install(_install):
def run(self):
_install.run(self)
for lang_dir in TMP_LOCALE_DIR.iterdir():
lang = lang_dir.name
lang_file = TMP_LOCALE_DIR / lang / "LC_MESSAGES" / "rednotebook.mo"
dest_dir = Path("share", "locale", lang, "LC_MESSAGES")
self.data_files.append((str(dest_dir), [str(lang_file)]))
_install_data.run(self)
dest_dir = (
Path(self.install_data) / "share" / "locale" / lang / "LC_MESSAGES"
)
dest_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(lang_file, dest_dir / "rednotebook.mo")


parameters = {
Expand All @@ -88,7 +83,7 @@ def run(self):
"url": info.url,
"license": "GPL",
"keywords": "journal, diary",
"cmdclass": {"build_py": build_py, "install_data": install_data},
"cmdclass": {"build_py": build_py, "install": install},
"scripts": ["rednotebook/rednotebook"],
"packages": [
"rednotebook",
Expand Down

0 comments on commit e42991b

Please sign in to comment.