From 552fbb9f752b7fac5e9a46ae73ab75d4c8ac5ed8 Mon Sep 17 00:00:00 2001 From: Akinori Hattori Date: Tue, 20 Feb 2024 22:30:42 +0900 Subject: [PATCH] Refine --- README.rst | 2 +- pyproject.toml | 6 ++++-- scmver/core.py | 6 ++---- scmver/setuptools.py | 5 ++--- scmver/subversion.py | 5 ++--- setup.cfg | 3 --- setup.py | 23 +++++++++++------------ tests/base.py | 5 ++--- tests/test_core.py | 2 +- tests/test_setuptools.py | 2 +- 10 files changed, 26 insertions(+), 33 deletions(-) diff --git a/README.rst b/README.rst index 92bb7c1..8caf8fd 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ pyproject.toml [build-system] requires = [ "setuptools >= 42.0", - "scmver[toml] >= 1.5", + "scmver[toml] >= 1.7", ] build-backend = "setuptools.build_meta" diff --git a/pyproject.toml b/pyproject.toml index cea3357..beb5d85 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ readme = "README.rst" authors = [ {name = "Akinori Hattori", email = "hattya@gmail.com"}, ] -license = {"text" = "MIT"} +license = {text = "MIT"} classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -66,7 +66,9 @@ Homepage = "https://github.com/hattya/scmver" [tool.setuptools] include-package-data = false -packages = ["scmver"] +packages = [ + "scmver", +] [tool.setuptools.package-data] scmver = [ diff --git a/scmver/core.py b/scmver/core.py index 98f256e..7f77989 100644 --- a/scmver/core.py +++ b/scmver/core.py @@ -96,8 +96,7 @@ def take(d: Mapping[str, str], *keys: str) -> Dict[str, Any]: return {k: d[k] for k in d if k in keys} root = os.path.abspath(root) - info = stat(root, **{k: kwargs[k] for k in kwargs if k.endswith('.tag')}) - if info: + if info := stat(root, **{k: kwargs[k] for k in kwargs if k.endswith('.tag')}): version = next_version(info, **take(kwargs, 'spec', 'local', 'version')) if 'write_to' in kwargs: generate(os.path.join(root, kwargs['write_to']), version, info, **take(kwargs, 'template')) @@ -205,8 +204,7 @@ def stat(path: Path, **kwargs: Any) -> Optional[SCMInfo]: for name, parse in impls: if (kwargs.get(name, True) and os.path.exists(os.path.join(path, name))): - info = parse(path, name=name, **kwargs) - if info: + if info := parse(path, name=name, **kwargs): return info p, path = path, os.path.dirname(path) if path == p: diff --git a/scmver/setuptools.py b/scmver/setuptools.py index 8244d34..069ee91 100644 --- a/scmver/setuptools.py +++ b/scmver/setuptools.py @@ -1,7 +1,7 @@ # # scmver.setuptools # -# Copyright (c) 2019-2023 Akinori Hattori +# Copyright (c) 2019-2024 Akinori Hattori # # SPDX-License-Identifier: MIT # @@ -18,8 +18,7 @@ def finalize_version(dist: setuptools.Distribution) -> None: - scmver = core.load_project() - if scmver is not None: + if (scmver := core.load_project()) is not None: dist.metadata.version = core.get_version(**scmver) diff --git a/scmver/subversion.py b/scmver/subversion.py index 3bb00f2..e2fcc87 100644 --- a/scmver/subversion.py +++ b/scmver/subversion.py @@ -1,7 +1,7 @@ # # scmver.subversion # -# Copyright (c) 2019-2023 Akinori Hattori +# Copyright (c) 2019-2024 Akinori Hattori # # SPDX-License-Identifier: MIT # @@ -167,8 +167,7 @@ def version() -> Tuple[Union[int, str], ...]: def run(*args: str, **kwargs: Any) -> Tuple[Union[str, ET.Element], str]: - xml = '--xml' in args - if xml: + if xml := '--xml' in args: kwargs['encoding'] = 'utf-8' out, err = util.exec_((cast(str, util.which('svn')), '--non-interactive') + args, **kwargs) return ET.fromstring(out.encode('utf-8')) if xml else out, err diff --git a/setup.cfg b/setup.cfg index 7f0f74f..f8c5784 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,9 +2,6 @@ formats = zip group = users -[bdist_wheel] -universal = 1 - [flake8] extend-ignore = E129, E741 max-line-length = 160 diff --git a/setup.py b/setup.py index 96276d1..e7bb6ed 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,6 @@ def finalize_options(self): def run(self): import unittest - self.run_command('egg_info') # run unittest discover argv = [sys.argv[0], 'discover', '--start-directory', 'tests'] if self.verbose: @@ -40,14 +39,14 @@ def run(self): unittest.main(None, argv=argv) -cmdclass = { - 'test': test, -} - -setup(version=scmver.get_version(**{ - 'root': os.path.dirname(os.path.abspath(__file__)), - 'spec': 'micro', - 'write_to': os.path.join('scmver', '__version__.py'), - 'fallback': 'scmver:__version__', - }), - cmdclass=cmdclass) +setup( + version=scmver.get_version(**{ + 'root': os.path.dirname(os.path.abspath(__file__)), + 'spec': 'micro', + 'write_to': os.path.join('scmver', '__version__.py'), + 'fallback': 'scmver:__version__', + }), + cmdclass={ + 'test': test, + }, +) diff --git a/tests/base.py b/tests/base.py index 1015af1..092e4ca 100644 --- a/tests/base.py +++ b/tests/base.py @@ -1,7 +1,7 @@ # # base # -# Copyright (c) 2019-2022 Akinori Hattori +# Copyright (c) 2019-2024 Akinori Hattori # # SPDX-License-Identifier: MIT # @@ -30,8 +30,7 @@ def tearDownClass(cls): locale.setlocale(locale.LC_ALL, cls._lc) def check_locale(self): - encoding = locale.getpreferredencoding(False) - if encoding.lower() not in ('cp932', 'euc-jp', 'utf-8'): + if locale.getpreferredencoding(False).lower() not in ('cp932', 'euc-jp', 'utf-8'): self.skipTest('requires UTF-8 or Japanese locale') def tempdir(self): diff --git a/tests/test_core.py b/tests/test_core.py index 25fb6c8..16e6d86 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -142,7 +142,7 @@ def test_load_project(self): [build-system] requires = [ "setuptools >= 42.0", - "scmver[toml] >= 1.5", + "scmver[toml] >= 1.7", ] build-backend = "setuptools.build_meta" """)) diff --git a/tests/test_setuptools.py b/tests/test_setuptools.py index c93e9b2..2256a0a 100644 --- a/tests/test_setuptools.py +++ b/tests/test_setuptools.py @@ -51,7 +51,7 @@ def finalize_version(self, scmver): [build-system] requires = [ "setuptools >= 42.0", - "scmver[toml] >= 1.5", + "scmver[toml] >= 1.7", ] build-backend = "setuptools.build_meta" """))