diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 6886e90..0000000 --- a/.flake8 +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -exclude = .venv/,.tox/,dist/,build/,doc/,.eggs/ -format = pylint diff --git a/.gitignore b/.gitignore index be6d5ab..e1fc810 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ *.egg-info/ -*.py[cod] +*.py[rcod] .cache/ .coverage .eggs/ .tox/ +.venv/ +build/ +coverage.* +dist/ doc/build/ +htmlcov/ +pip-wheel-metadata/ diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..66460d4 --- /dev/null +++ b/.python-version @@ -0,0 +1,2 @@ +3.7.6 +3.6.7 diff --git a/doc/source/development.rst b/doc/source/development.rst index 2f58a13..4724c13 100644 --- a/doc/source/development.rst +++ b/doc/source/development.rst @@ -37,21 +37,12 @@ Tag the release and push to github.com Upload to `PyPI`_ ^^^^^^^^^^^^^^^^^ -* Install `Twine`_ using `pip`. - - .. code-block:: bash - - $ pip install twine - * Upload to `PyPI`_. .. code-block:: bash - $ cd /path/to/gilt - $ rm -rf build/ dist/ - $ python setup.py sdist bdist_wheel - $ twine upload dist/* - $ rm -rf build/ dist/ + $ tox -e build-dists + $ tox -e publish-dists Post-release ------------ @@ -65,4 +56,3 @@ Roadmap .. _`PyPI`: https://pypi.python.org/pypi/python-gilt .. _`ISSUES`: https://github.com/metacloud/gilt/issues -.. _`Twine`: https://pypi.python.org/pypi/twine diff --git a/gilt/__init__.py b/gilt/__init__.py index 6975223..4b95875 100644 --- a/gilt/__init__.py +++ b/gilt/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -20,7 +18,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -import pbr.version +try: + import pkg_resources -version_info = pbr.version.VersionInfo('python-gilt') # noqa -__version__ = version_info.release_string() + __version__ = pkg_resources.get_distribution('gilt').version +except Exception: # pragma: no cover + __version__ = 'unknown' diff --git a/gilt/config.py b/gilt/config.py index a170df8..53a185d 100644 --- a/gilt/config.py +++ b/gilt/config.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -31,7 +29,7 @@ class ParseError(Exception): - """ Error raised when a config can't be loaded properly. """ + """Error raised when a config can't be loaded properly. """ pass @@ -39,8 +37,7 @@ class ParseError(Exception): def config(filename): - """ - Construct `Config` object and return a list. + """Construct `Config` object and return a list. :parse filename: A string containing the path to YAML file. :return: list @@ -60,8 +57,7 @@ def config(filename): def _get_files_config(src_dir, files_list): - """ - Construct `FileConfig` object and return a list. + """Construct `FileConfig` object and return a list. :param src_dir: A string containing the source directory. :param files_list: A list of dicts containing the src/dst mapping of files @@ -77,8 +73,7 @@ def _get_files_config(src_dir, files_list): def _get_config_generator(filename): - """ - A generator which populates and return a dict. + """A generator which populates and return a dict. :parse filename: A string containing the path to YAML file. :return: dict @@ -106,8 +101,7 @@ def _get_config_generator(filename): def _get_files_generator(src_dir, files_list): - """ - A generator which populates and return a dict. + """A generator which populates and return a dict. :param src_dir: A string containing the source directory. :param files_list: A list of dicts containing the src/dst mapping of files @@ -124,8 +118,7 @@ def _get_files_generator(src_dir, files_list): def _get_config(filename): - """ - Parse the provided YAML file and return a dict. + """Parse the provided YAML file and return a dict. :parse filename: A string containing the path to YAML file. :return: dict @@ -143,9 +136,7 @@ def _get_config(filename): def _get_dst_dir(dst_dir): - """ - Prefix the provided string with working directory and return a - str. + """Prefix the provided string with working directory and return a str. :param dst_dir: A string to be prefixed with the working dir. :return: str @@ -157,20 +148,19 @@ def _get_dst_dir(dst_dir): def _get_lock_file(name): - """ Return the lock file for the given name. """ + """Return the lock file for the given name. """ return os.path.join( _get_lock_dir(), name, ) def _get_base_dir(): - """ Return gilt's base working directory. """ + """Return gilt's base working directory. """ return os.path.expanduser(BASE_WORKING_DIR) def _get_lock_dir(): - """ - Construct gilt's lock directory and return a str. + """Construct gilt's lock directory and return a str. :return: str """ @@ -180,8 +170,7 @@ def _get_lock_dir(): def _get_clone_dir(): - """ - Construct gilt's clone directory and return a str. + """Construct gilt's clone directory and return a str. :return: str """ @@ -191,8 +180,7 @@ def _get_clone_dir(): def _makedirs(path): - """ - Create a base directory of the provided path and return None. + """Create a base directory of the provided path and return None. :param path: A string containing a path to be deconstructed and basedir created. diff --git a/gilt/git.py b/gilt/git.py index a15530c..41b791e 100644 --- a/gilt/git.py +++ b/gilt/git.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -30,8 +28,7 @@ def clone(name, repository, destination, debug=False): - """ - Clone the specified repository into a temporary directory and return None. + """Clone the specified repository into a temporary directory and return None. :param name: A string containing the name of the repository being cloned. :param repository: A string containing the repository to clone. @@ -47,9 +44,7 @@ def clone(name, repository, destination, debug=False): def extract(repository, destination, version, debug=False): - """ - Extract the specified repository/version into the given directory and - return None. + """Extract the specified repository/version into the directory and return None. :param repository: A string containing the path to the repository to be extracted. @@ -75,9 +70,7 @@ def extract(repository, destination, version, debug=False): def overlay(repository, files, version, debug=False): - """ - Overlay files from the specified repository/version into the given - directory and return None. + """Overlay files from repository/version into the directory and return None. :param repository: A string containing the path to the repository to be extracted. @@ -107,8 +100,7 @@ def overlay(repository, files, version, debug=False): def _get_version(version, debug=False): - """ - Handle switching to the specified version and return None. + """Handle switching to the specified version and return None. 1. Fetch the origin. 2. Checkout the specified version. @@ -134,8 +126,7 @@ def _get_version(version, debug=False): def _has_commit(version, debug=False): - """ - Determine a version is a local git commit sha or not. + """Determine a version is a local git commit sha or not. :param version: A string containing the branch/tag/sha to be determined. :param debug: An optional bool to toggle debug output. @@ -152,8 +143,7 @@ def _has_commit(version, debug=False): def _has_tag(version, debug=False): - """ - Determine a version is a local git tag name or not. + """Determine a version is a local git tag name or not. :param version: A string containing the branch/tag/sha to be determined. :param debug: An optional bool to toggle debug output. @@ -169,8 +159,7 @@ def _has_tag(version, debug=False): def _has_branch(version, debug=False): - """ - Determine a version is a local git branch name or not. + """Determine a version is a local git branch name or not. :param version: A string containing the branch/tag/sha to be determined. :param debug: An optional bool to toggle debug output. diff --git a/gilt/shell.py b/gilt/shell.py index ef5b589..9e3ad05 100644 --- a/gilt/shell.py +++ b/gilt/shell.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -32,7 +30,7 @@ class NotFoundError(Exception): - """ Error raised when a config can not be found. """ + """Error raised when a config can not be found. """ pass @@ -48,7 +46,7 @@ class NotFoundError(Exception): @click.version_option(version=gilt.__version__) @click.pass_context def main(ctx, config, debug): # pragma: no cover - """ gilt - A GIT layering tool. """ + """gilt - A GIT layering tool. """ ctx.obj = {} ctx.obj['args'] = {} ctx.obj['args']['debug'] = debug @@ -58,7 +56,7 @@ def main(ctx, config, debug): # pragma: no cover @click.command() @click.pass_context def overlay(ctx): # pragma: no cover - """ Install gilt dependencies """ + """Install gilt dependencies """ args = ctx.obj.get('args') filename = args.get('config') debug = args.get('debug') diff --git a/gilt/util.py b/gilt/util.py index 5763cda..26a2275 100644 --- a/gilt/util.py +++ b/gilt/util.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -34,18 +32,17 @@ def print_info(msg): - """ Print the given message to STDOUT. """ + """Print the given message to STDOUT. """ print(msg) def print_warn(msg): - """ Print the given message to STDOUT in YELLOW. """ + """Print the given message to STDOUT in YELLOW. """ print('{}{}'.format(colorama.Fore.YELLOW, msg)) def run_command(cmd, debug=False): - """ - Execute the given command and return None. + """Execute the given command and return None. :param cmd: A `sh.Command` object to execute. :param debug: An optional bool to toggle debug output. @@ -72,7 +69,7 @@ def build_sh_cmd(cmd, cwd=None): @contextlib.contextmanager def saved_cwd(): - """ Context manager to restore previous working directory. """ + """Context manager to restore previous working directory. """ saved = os.getcwd() try: yield @@ -81,8 +78,7 @@ def saved_cwd(): def copy(src, dst): - """ - Handle the copying of a file or directory. + """Handle the copying of a file or directory. The destination basedir _must_ exist. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6bfbd72 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + 'setuptools >= 41.0.0', + 'setuptools_scm >= 1.15.0', + 'setuptools_scm_git_archive >= 1.0', + 'wheel', +] +build-backend = 'setuptools.build_meta' diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 9364580..0000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -click -colorama -fasteners -git-url-parse -pbr -PyYAML -sh diff --git a/setup.cfg b/setup.cfg index e91dce8..087daea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,16 @@ +[aliases] +dists = clean --all sdist bdist_wheel + +[bdist_wheel] +universal = 1 + [metadata] name = python-gilt summary = gilt - A GIT layering tool. description-file = README.rst author = John Dewey -author-email = jodewey@cisco.com -home-page = https://github.com/metacloud/gilt +author-email = john@dewey.ws +home-page = https://github.com/retr0h/gilt classifier = Development Status :: 4 - Beta Environment :: Console @@ -15,29 +21,52 @@ classifier = License :: OSI Approved :: MIT License Natural Language :: English Operating System :: OS Independent - Programming Language :: Python :: 2 - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 Topic :: System :: Systems Administration Topic :: Utilities -[pbr] -skip_authors = True -skip_changelog = True -warnerrors = True +[options] +use_scm_version = True +python_requires = >=3.6 +packages = find: +include_package_data = True +zip_safe = False + +# These are required during `setup.py` run: +setup_requires = + setuptools_scm >= 1.15.0 + setuptools_scm_git_archive >= 1.0 + +# These are required in actual runtime: +install_requires = + click + colorama + fasteners + git-url-parse + PyYAML + sh -[global] -setup-hooks = - pbr.hooks.setup_hook +[options.extras_require] +# These are required during test: +test = + flake8 + hacking + pep517 + pytest + pytest-cov + pytest-helpers-namespace + pytest-mock + twine + yapf==0.16.3 -[entry_points] +[options.entry_points] console_scripts = gilt = gilt.shell:main -[files] -packages = - gilt +[options.packages.find] +where = . [build_sphinx] all_files = 1 diff --git a/setup.py b/setup.py index 9793a62..ca3c2b5 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -22,4 +20,7 @@ import setuptools -setuptools.setup(setup_requires=['pbr'], pbr=True) +if __name__ == "__main__": + setuptools.setup( + use_scm_version=True, setup_requires=["setuptools_scm"], + ) diff --git a/test-requirements.txt b/test-requirements.txt deleted file mode 100644 index cbe8719..0000000 --- a/test-requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -flake8 -pytest -pytest-cov -pytest-helpers-namespace -pytest-mock -yapf==0.16.3 diff --git a/test/conftest.py b/test/conftest.py index 13065f6..67accca 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/test_config.py b/test/test_config.py index 11c9b34..70f255c 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/test_git.py b/test/test_git.py index cdbde74..ba431b9 100644 --- a/test/test_git.py +++ b/test/test_git.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/test_shell.py b/test/test_shell.py index f99817c..a4ee90d 100644 --- a/test/test_shell.py +++ b/test/test_shell.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/test_util.py b/test/test_util.py index 45930ae..17f2c52 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2016 Cisco Systems, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/tox.ini b/tox.ini index b1f3018..062cfeb 100644 --- a/tox.ini +++ b/tox.ini @@ -1,18 +1,17 @@ [tox] minversion = 1.8 envlist = - py{27,36}-unit - py{27,36}-lint + py{36,37}-unit + py{36,37}-lint doc [testenv] passenv = * -deps = - -rrequirements.txt - -rtest-requirements.txt commands = unit: py.test --runslow -vv {posargs} lint: flake8 +extras = + test [testenv:format] commands = @@ -24,3 +23,47 @@ deps= -rdoc-requirements.txt commands= python setup.py build_sphinx --builder=html + +[testenv:build-dists-local] +usedevelop = false +skip_install = true +commands = + python -m pep517.build \ + --source \ + --binary \ + --out-dir {toxinidir}/dist/ \ + {toxinidir} + +[testenv:build-dists] +commands = + rm -rfv {toxinidir}/dist/ + {[testenv:build-dists-local]commands} +whitelist_externals = + rm + +[testenv:publish-dists] +commands = + bash -c '\ + twine upload {toxinidir}/dist/*.whl \ + -u $TWINE_USERNAME \ + -p $TWINE_PASSWORD \ + --repository-url $TWINE_REPOSITORY \ + ' +whitelist_externals = + bash + +[flake8] +max-line-length = 79 +format = pylint +exclude = + .eggs/ + .tox/, + .venv*, + build/, + dist/, + doc/, + interpolation.py, +#- [H106] Don't put vim configuration in source files. +#- [H203] Use assertIs(Not)None to check for None. +#- [H904] Delay string interpolations at logging calls. +enable-extensions = H106,H203,H904