浏览代码

Setup.cfg for py2 (#483)

New Future 4 月之前
父节点
当前提交
ecee2bf644
共有 7 个文件被更改,包括 35 次插入13 次删除
  1. 3 1
      .github/workflows/build.yml
  2. 3 5
      ddns/__init__.py
  3. 4 4
      ddns/__main__.py
  4. 21 2
      ddns/util/config.py
  5. 1 0
      docker/test-in-docker.sh
  6. 1 1
      pyproject.toml
  7. 2 0
      setup.cfg

+ 3 - 1
.github/workflows/build.yml

@@ -159,8 +159,9 @@ jobs:
           macos-app-name: ${{ runner.os == 'macOS' && 'DDNS' || '' }}
           macos-app-icon: ${{ runner.os == 'macOS' && 'doc/img/ddns.png' || '' }}
 
-      - run: ./dist/ddns || test -f config.json
+      - run: ./dist/ddns -v
       - run: ./dist/ddns -h
+      - run: ./dist/ddns || test -f config.json
 
       # Upload build result
       - name: Upload Artifacts
@@ -309,6 +310,7 @@ jobs:
             echo "Loading image for $platform..."
             docker load < ddns-oci-${tag}.tar
             echo "Running test..."
+            docker run --platform $platform --rm ${{ env.DOCKER_IMG }}:$tag -v
             docker run --platform $platform --rm ${{ env.DOCKER_IMG }}:$tag -h
             docker run --platform $platform --rm -v "$(pwd):/ddns/" ${{ env.DOCKER_IMG }}:$tag || test -e "config.json"
             sudo rm -f config.json

+ 3 - 5
ddns/__init__.py

@@ -12,10 +12,8 @@ __version__ = "${BUILD_VERSION}"
 build_date = "${BUILD_DATE}"
 
 __doc__ = """
-ddns[%s]
+ddns[{}@{}]
 (i) homepage or docs [文档主页]: https://ddns.newfuture.cc/
-(?) issues or bugs [问题和帮助]: https://github.com/NewFuture/DDNS/issues
+(?) issues or bugs [问题和反馈]: https://github.com/NewFuture/DDNS/issues
 Copyright (c) New Future (MIT License)
-""" % (
-    __version__
-)
+""".format(__version__, build_date)

+ 4 - 4
ddns/__main__.py

@@ -13,12 +13,12 @@ from logging import basicConfig, info, warning, error, debug, DEBUG, NOTSET
 
 import sys
 
-from .__init__ import __version__ as version, __description__, __doc__
+from .__init__ import __version__, __description__, __doc__, build_date
 from .util import ip
 from .util.cache import Cache
 from .util.config import init_config, get_config
 
-environ["DDNS_VERSION"] = "${BUILD_VERSION}"
+environ["DDNS_VERSION"] = __version__
 
 
 def is_false(value):
@@ -124,7 +124,7 @@ def main():
         # 兼容windows 和部分ASCII编码的老旧系统
         sys.stdout = TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
         sys.stderr = TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
-    init_config(__description__, __doc__, version)
+    init_config(__description__, __doc__, __version__, build_date)
 
     log_level = get_config('log.level')
     log_format = get_config('log.format', '%(asctime)s %(levelname)s [%(module)s]: %(message)s')
@@ -138,7 +138,7 @@ def main():
         filename=get_config('log.file'),
     )
 
-    info("DDNS[ %s ] run: %s %s", version, os_name, sys.platform)
+    info("DDNS[ %s ] run: %s %s", __version__, os_name, sys.platform)
 
     # Dynamically import the dns module as configuration
     dns_provider = str(get_config('dns', 'dnspod').lower())

+ 21 - 2
ddns/util/config.py

@@ -6,6 +6,7 @@ from os import stat, environ, path
 from logging import error, getLevelName
 from ast import literal_eval
 
+import platform
 import sys
 
 
@@ -75,7 +76,22 @@ def parse_array_string(value, enable_simple_split):
     return value
 
 
-def init_config(description, doc, version):
+def get_system_info_str():
+    system = platform.system()
+    release = platform.release()
+    machine = platform.machine()
+    arch = platform.architecture()[0]  # '64bit' or '32bit'
+
+    return "{}-{} {} ({})".format(system, release, machine, arch)
+
+
+def get_python_info_str():
+    version = platform.python_version()
+    branch, py_build_date = platform.python_build()
+    return "Python-{} {} ({})".format(version, branch, py_build_date)
+
+
+def init_config(description, doc, version, date):
     """
     配置
     """
@@ -83,7 +99,10 @@ def init_config(description, doc, version):
     parser = ArgumentParser(
         description=description, epilog=doc, formatter_class=RawTextHelpFormatter
     )
-    parser.add_argument("-v", "--version", action="version", version=version)
+    sysinfo = get_system_info_str()
+    pyinfo = get_python_info_str()
+    version_str = "v{} ({})\n{}\n{}".format(version, date, pyinfo, sysinfo)
+    parser.add_argument("-v", "--version", action="version", version=version_str)
     parser.add_argument(
         "-c", "--config", metavar="FILE", help="load config file [配置文件路径]"
     )

+ 1 - 0
docker/test-in-docker.sh

@@ -41,6 +41,7 @@ else
 fi
 
 docker run --rm -v="$volume:/dist" --platform=$platform $container /dist/$file -h
+docker run --rm -v="$volume:/dist" --platform=$platform $container /dist/$file --version
 docker run --rm -v="$volume:/dist" --platform=$platform $container sh -c "/dist/$file || test -f config.json"
 # delete to avoid being reused
 docker image rm $container

+ 1 - 1
pyproject.toml

@@ -54,7 +54,7 @@ dev = [
 #    "pytest-cov",
     "black",
     "flake8",
-    "setuptools_scm"
+#    "setuptools_scm"
 ]
 
 # Setuptools configuration

+ 2 - 0
setup.cfg

@@ -0,0 +1,2 @@
+[bdist_wheel]
+universal = 1