diff options
author | Shane McDonald <me@shanemcd.com> | 2022-06-27 15:22:25 +0200 |
---|---|---|
committer | Shane McDonald <me@shanemcd.com> | 2022-06-27 19:30:01 +0200 |
commit | cbea36745e0d4790b0b90b35fa16f7e7dcce3493 (patch) | |
tree | 7b2de75201390add9262fd8c02a832605317cafa | |
parent | Updated setup.py --version to python3 -m setuptools_scm. (diff) | |
download | awx-cbea36745e0d4790b0b90b35fa16f7e7dcce3493.tar.xz awx-cbea36745e0d4790b0b90b35fa16f7e7dcce3493.zip |
Transition from setup.py to setup.cfg
-rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
-rw-r--r-- | .github/workflows/stage.yml | 2 | ||||
-rw-r--r-- | Makefile | 18 | ||||
-rw-r--r-- | awx/__init__.py | 36 | ||||
-rw-r--r-- | pyproject.toml | 14 | ||||
-rw-r--r-- | requirements/requirements_dev.txt | 1 | ||||
-rw-r--r-- | setup.cfg | 24 | ||||
-rwxr-xr-x | setup.py | 190 | ||||
-rw-r--r-- | tools/ansible/build.yml | 2 | ||||
-rw-r--r-- | tools/ansible/roles/dockerfile/templates/Dockerfile.j2 | 2 | ||||
-rw-r--r-- | tools/scripts/scm_version.py | 4 | ||||
-rwxr-xr-x | tools/scripts/setup.py | 20 | ||||
-rw-r--r-- | tox.ini | 5 |
13 files changed, 104 insertions, 216 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01e33079c8..74bc2122d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -113,7 +113,7 @@ jobs: - name: Install playbook dependencies run: | - python3 -m pip install docker + python3 -m pip install docker setuptools_scm - name: Build AWX image working-directory: awx diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index af8054058e..24710e8789 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -65,7 +65,7 @@ jobs: - name: Install playbook dependencies run: | - python3 -m pip install docker + python3 -m pip install docker setuptools_scm - name: Build and stage AWX working-directory: awx @@ -5,8 +5,8 @@ NPM_BIN ?= npm CHROMIUM_BIN=/tmp/chrome-linux/chrome GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) MANAGEMENT_COMMAND ?= awx-manage -VERSION := $(shell $(PYTHON) -m setuptools_scm) -COLLECTION_VERSION := $(shell $(PYTHON) -m setuptools_scm | cut -d . -f 1-3) +VERSION := $(shell $(PYTHON) tools/scripts/scm_version.py) +COLLECTION_VERSION := $(shell $(PYTHON) tools/scripts/scm_version.py | cut -d . -f 1-3) # NOTE: This defaults the container image version to the branch that's active COMPOSE_TAG ?= $(GIT_BRANCH) @@ -45,7 +45,7 @@ I18N_FLAG_FILE = .i18n_built .PHONY: awx-link clean clean-tmp clean-venv requirements requirements_dev \ develop refresh adduser migrate dbchange \ receiver test test_unit test_coverage coverage_html \ - dev_build release_build sdist \ + sdist \ ui-release ui-devel \ VERSION PYTHON_VERSION docker-compose-sources \ .git/hooks/pre-commit @@ -269,7 +269,7 @@ api-lint: yamllint -s . awx-link: - [ -d "/awx_devel/awx.egg-info" ] || $(PYTHON) /awx_devel/setup.py egg_info_dev + [ -d "/awx_devel/awx.egg-info" ] || $(PYTHON) /awx_devel/tools/scripts/setup.py egg_info_dev cp -f /tmp/awx.egg-link /var/lib/awx/venv/awx/lib/$(PYTHON)/site-packages/awx.egg-link TEST_DIRS ?= awx/main/tests/unit awx/main/tests/functional awx/conf/tests awx/sso/tests @@ -420,21 +420,13 @@ ui-test-general: $(NPM_BIN) run --prefix awx/ui pretest $(NPM_BIN) run --prefix awx/ui/ test-general --runInBand -# Build a pip-installable package into dist/ with a timestamped version number. -dev_build: - $(PYTHON) setup.py dev_build - -# Build a pip-installable package into dist/ with the release version number. -release_build: - $(PYTHON) setup.py release_build - HEADLESS ?= no ifeq ($(HEADLESS), yes) dist/$(SDIST_TAR_FILE): else dist/$(SDIST_TAR_FILE): $(UI_BUILD_FLAG_FILE) endif - $(PYTHON) setup.py $(SDIST_COMMAND) + $(PYTHON) -m build -s ln -sf $(SDIST_TAR_FILE) dist/awx.tar.gz sdist: dist/$(SDIST_TAR_FILE) diff --git a/awx/__init__.py b/awx/__init__.py index 62925baeb1..676d2725a9 100644 --- a/awx/__init__.py +++ b/awx/__init__.py @@ -6,9 +6,40 @@ import os import sys import warnings -from pkg_resources import get_distribution -__version__ = get_distribution('awx').version +def get_version(): + version_from_file = get_version_from_file() + if version_from_file: + return version_from_file + else: + from setuptools_scm import get_version + + version = get_version(root='..', relative_to=__file__) + return version + + +def get_version_from_file(): + vf = version_file() + if vf: + with open(vf, 'r') as file: + return file.read().strip() + + +def version_file(): + current_dir = os.path.dirname(os.path.abspath(__file__)) + version_file = os.path.join(current_dir, '..', 'VERSION') + + if os.path.exists(version_file): + return version_file + + +try: + import pkg_resources + + __version__ = pkg_resources.get_distribution('awx').version +except pkg_resources.DistributionNotFound: + __version__ = get_version() + __all__ = ['__version__'] @@ -21,7 +52,6 @@ try: except ImportError: # pragma: no cover MODE = 'production' - import hashlib try: diff --git a/pyproject.toml b/pyproject.toml index 351a98ee3c..9670a1906a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,13 @@ +[build-system] +requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] +build-backend = "setuptools.build_meta" + +# Do not uncomment the line below. We need to be able to override the version via a file, and this +# causes the "version" key in setup.cfg to be ignored. +# [tool.setuptools_scm] + [tool.black] line-length = 160 fast = true skip-string-normalization = true exclude = "awx_collection" - -[build-system] -requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"] - - -[tool.setuptools_scm] diff --git a/requirements/requirements_dev.txt b/requirements/requirements_dev.txt index 0b1d2279ef..4db1327d40 100644 --- a/requirements/requirements_dev.txt +++ b/requirements/requirements_dev.txt @@ -1,3 +1,4 @@ +build django-debug-toolbar==3.2.4 django-rest-swagger # pprofile - re-add once https://github.com/vpelletier/pprofile/issues/41 is addressed diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..e72b2d4546 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,24 @@ +[metadata] +name = awx +author = Red Hat +author_email = info@ansible.com +version = attr: awx.get_version + +[options] +packages = + awx +zip_safe = False +include_package_data = True + +[options.entry_points] +console_scripts = + awx-manage = awx:manage +awx.credential_plugins = + conjur = awx.main.credential_plugins.conjur:conjur_plugin + hashivault_kv = awx.main.credential_plugins.hashivault:hashivault_kv_plugin + hashivault_ssh = awx.main.credential_plugins.hashivault:hashivault_ssh_plugin + azure_kv = awx.main.credential_plugins.azure_kv:azure_keyvault_plugin + aim = awx.main.credential_plugins.aim:aim_plugin + centrify_vault_kv = awx.main.credential_plugins.centrify_vault:centrify_plugin + thycotic_dsv = awx.main.credential_plugins.dsv:dsv_plugin + thycotic_tss = awx.main.credential_plugins.tss:tss_plugin diff --git a/setup.py b/setup.py deleted file mode 100755 index 4fc109c3c9..0000000000 --- a/setup.py +++ /dev/null @@ -1,190 +0,0 @@ -#!/usr/bin/env python - -# Copyright (c) 2015 Ansible, Inc. -# All Rights Reserved. - -import os -import glob -import sys -from setuptools import setup -from setuptools.command.egg_info import egg_info as _egg_info - - -# Paths we'll use later -etcpath = "/etc/tower" -homedir = "/var/lib/awx" -bindir = "/usr/bin" -sharedir = "/usr/share/awx" -docdir = "/usr/share/doc/awx" - - -def use_scm_version(): - return False if version_file() else True - - -def get_version_from_file(): - vf = version_file() - if vf: - with open(vf, 'r') as file: - return file.read().strip() - - -def version_file(): - current_dir = os.path.dirname(os.path.abspath(__file__)) - version_file = os.path.join(current_dir, 'VERSION') - - if os.path.exists(version_file): - return version_file - - -def setup_requires(): - if version_file(): - return [] - else: - return ['setuptools_scm'] - - -extra_setup_args = {} -if not version_file(): - extra_setup_args.update(dict(use_scm_version=use_scm_version(), setup_requires=setup_requires())) - -if os.path.exists("/etc/debian_version"): - sysinit = "/etc/init.d" - webconfig = "/etc/nginx" - siteconfig = "/etc/nginx/sites-enabled" - # sosreport-3.1 (and newer) look in '/usr/share/sosreport/sos/plugins' - # sosreport-3.0 looks in '/usr/lib/python2.7/dist-packages/sos/plugins' - # debian/<package>.links will create symlinks to support both versions - sosconfig = "/usr/share/sosreport/sos/plugins" -else: - sysinit = "/etc/rc.d/init.d" - webconfig = "/etc/nginx" - siteconfig = "/etc/nginx/sites-enabled" - # The .spec will create symlinks to support multiple versions of sosreport - sosconfig = "/usr/share/sosreport/sos/plugins" - -##################################################################### -# Helper Functions - - -def explode_glob_path(path): - """Take a glob and hand back the full recursive expansion, - ignoring links. - """ - - result = [] - includes = glob.glob(path) - for item in includes: - if os.path.isdir(item) and not os.path.islink(item): - result.extend(explode_glob_path(os.path.join(item, "*"))) - else: - result.append(item) - return result - - -def proc_data_files(data_files): - """Because data_files doesn't natively support globs... - let's add them. - """ - - result = [] - - # If running in a virtualenv, don't return data files that would install to - # system paths (mainly useful for running tests via tox). - if hasattr(sys, 'real_prefix'): - return result - - for dir, files in data_files: - includes = [] - for item in files: - includes.extend(explode_glob_path(item)) - result.append((dir, includes)) - return result - - -class egg_info_dev(_egg_info): - def find_sources(self): - # when we generate a .egg-info for the development - # environment, it's not really critical that we - # parse the MANIFEST.in (which is actually quite expensive - # in Docker for Mac) - pass - - -##################################################################### - - -setup( - name=os.getenv('NAME', 'awx'), - version=get_version_from_file(), - author='Ansible, Inc.', - author_email='info@ansible.com', - description='awx: API, UI and Task Engine for Ansible', - long_description='AWX provides a web-based user interface, REST API and ' 'task engine built on top of Ansible', - license='Apache License 2.0', - keywords='ansible', - url='http://github.com/ansible/awx', - packages=['awx'], - include_package_data=True, - zip_safe=False, - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Web Environment', - 'Framework :: Django', - 'Intended Audience :: Developers', - 'Intended Audience :: Information Technology', - 'Intended Audience :: System Administrators' 'License :: Apache License 2.0', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Operating System :: POSIX', - 'Programming Language :: Python', - 'Topic :: System :: Installation/Setup', - 'Topic :: System :: Systems Administration', - ], - entry_points={ - 'console_scripts': [ - 'awx-manage = awx:manage', - ], - 'awx.credential_plugins': [ - 'conjur = awx.main.credential_plugins.conjur:conjur_plugin', - 'hashivault_kv = awx.main.credential_plugins.hashivault:hashivault_kv_plugin', - 'hashivault_ssh = awx.main.credential_plugins.hashivault:hashivault_ssh_plugin', - 'azure_kv = awx.main.credential_plugins.azure_kv:azure_keyvault_plugin', - 'aim = awx.main.credential_plugins.aim:aim_plugin', - 'centrify_vault_kv = awx.main.credential_plugins.centrify_vault:centrify_plugin', - 'thycotic_dsv = awx.main.credential_plugins.dsv:dsv_plugin', - 'thycotic_tss = awx.main.credential_plugins.tss:tss_plugin', - ], - }, - data_files=proc_data_files( - [ - ("%s" % homedir, ["awx/static/favicon.ico"]), - ("%s" % siteconfig, ["config/awx-nginx.conf"]), - # ("%s" % webconfig, ["config/uwsgi_params"]), - ("%s" % sharedir, ["tools/scripts/request_tower_configuration.sh", "tools/scripts/request_tower_configuration.ps1"]), - ( - "%s" % docdir, - [ - "docs/licenses/*", - ], - ), - ( - "%s" % bindir, - [ - "tools/scripts/automation-controller-service", - "tools/scripts/failure-event-handler", - "tools/scripts/awx-python", - ], - ), - ("%s" % sosconfig, ["tools/sosreport/controller.py"]), - ] - ), - options={ - 'aliases': {'dev_build': 'clean --all egg_info sdist', 'release_build': 'clean --all egg_info -b "" sdist'}, - 'build_scripts': { - 'executable': '/usr/bin/awx-python', - }, - }, - cmdclass={'egg_info_dev': egg_info_dev}, - **extra_setup_args, -) diff --git a/tools/ansible/build.yml b/tools/ansible/build.yml index 51b2b81c3b..81a69cf443 100644 --- a/tools/ansible/build.yml +++ b/tools/ansible/build.yml @@ -5,7 +5,7 @@ tasks: - name: Get version from SCM if not explicitly provided shell: | - python setup.py --version | cut -d + -f -1 + python3 -m setuptools_scm | cut -d + -f -1 args: chdir: '../../' register: setup_py_version diff --git a/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 b/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 index 4659288024..79c5448548 100644 --- a/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 +++ b/tools/ansible/roles/dockerfile/templates/Dockerfile.j2 @@ -43,7 +43,7 @@ RUN dnf -y update && dnf install -y 'dnf-command(config-manager)' && \ xmlsec1-devel \ xmlsec1-openssl-devel -RUN pip3 install virtualenv +RUN pip3 install virtualenv setuptools_scm build # Install & build requirements diff --git a/tools/scripts/scm_version.py b/tools/scripts/scm_version.py new file mode 100644 index 0000000000..78a24f87e6 --- /dev/null +++ b/tools/scripts/scm_version.py @@ -0,0 +1,4 @@ +from setuptools_scm import get_version + +version = get_version(root='../..', relative_to=__file__) +print(version) diff --git a/tools/scripts/setup.py b/tools/scripts/setup.py new file mode 100755 index 0000000000..ea8167166d --- /dev/null +++ b/tools/scripts/setup.py @@ -0,0 +1,20 @@ +# This file only exists for the purposes of generating the development environment's awx.egg-info file +# because pip install -e is painfully slow. If anyone finds a better way to do this, I'll buy you a drink. + +import setuptools +from setuptools.command.egg_info import egg_info as _egg_info + + +class egg_info_dev(_egg_info): + def find_sources(self): + # when we generate a .egg-info for the development + # environment, it's not really critical that we + # parse the MANIFEST.in (which is actually quite expensive + # in Docker for Mac) + pass + + +if __name__ == "__main__": + setuptools.setup( + cmdclass={'egg_info_dev': egg_info_dev}, + ) @@ -1,12 +1,17 @@ +[tox] +isolated_build = True + [testenv:linters] deps = make black flake8 + setuptools-scm yamllint allowlist_externals = make setenv = BLACK_ARGS = --check + PYTHON = python3 commands = make black flake8 awx awxkit awx_collection |