From dcabd7d17adfd62374ce1e4caf81f9bc89671d74 Mon Sep 17 00:00:00 2001 From: Brad Williams Date: Tue, 21 Apr 2020 11:03:32 -0400 Subject: [PATCH] Adding setup.py for pypi distribution --- readme.md => README.md | 24 ++++++++++---------- setup.py | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 12 deletions(-) rename readme.md => README.md (97%) create mode 100644 setup.py diff --git a/readme.md b/README.md similarity index 97% rename from readme.md rename to README.md index 1dc4410..cbb61ea 100644 --- a/readme.md +++ b/README.md @@ -62,7 +62,7 @@ the CLI documentation to find the pass-through arguments a given interaction req Setup-Prerequisites 1. You will require certain pip packages, use the following command to install them when at the root folder of the repository. - ```editorconfig + ```bash sudo pip install -r requirements.txt ``` 2. Download and install the OpenShift [command-line Tools](https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/) needed to access your OpenShift cluster. @@ -111,7 +111,7 @@ with oc.project('openshift-infra'), oc.timeout(10*60): for owner in pod_model.metadata.ownerReferences: # ownerReferences == oc.Missing if not present in resource # elements of a Model are also instances of Model or ListModel if owner.kind is not oc.Missing: # Compare as singleton - print ' pod owned by a {}'.format(owner.kind) # e.g. pod was created by a StatefulSet + print(' pod owned by a {}'.format(owner.kind)) # e.g. pod was created by a StatefulSet ``` @@ -127,10 +127,10 @@ used again and again to select rows from a database. project_selector = oc.selector("projects") # Print the qualified name (i.e. "kind/name") of each resource selected. -print "Project names: " + str(project_selector.qnames()) +print("Project names: " + project_selector.qnames()) # Count the number of projects on the server. -print "Number of projects: " + str(project_selector.count_existing()) +print("Number of projects: " + project_selector.count_existing()) # Selectors can also be created with a list of names. sa_selector = oc.selector(["serviceaccount/deployer", "serviceaccount/builder"]) @@ -143,7 +143,7 @@ sa_selector.label({"mylabel" : "myvalue"}) sa_label_selector = oc.selector("sa", labels={"mylabel":"myvalue"}) # We should find the service accounts we just labeled. -print("Found labeled serviceaccounts: " + str(sa_label_selector.names())) +print("Found labeled serviceaccounts: " + sa_label_selector.names()) # Create a selector for a set of kinds. print(oc.selector(['dc', 'daemonset']).describe()) @@ -169,7 +169,7 @@ projects_sel = oc.selector("projects") # which model the selected resources. projects = projects_sel.objects() -print("Selected " + str(len(projects)) + " projects") +print("Selected " + len(projects) + " projects") # Let's store one of the project APIObjects for easy access. project = projects[0] @@ -306,7 +306,7 @@ with oc.tracking() as tracker: print('Error acquiring current username') # Print out details about the invocations made within this context. - print tracker.get_result() + print(tracker.get_result()) ``` In this case, the tracking output would look something like: @@ -385,10 +385,10 @@ def node_is_ready(node): return ready -print "Waiting for up to 15 minutes for at least 6 nodes to be ready..." +print("Waiting for up to 15 minutes for at least 6 nodes to be ready...") with oc.timeout(15 * 60): oc.selector('nodes').until_all(6, success_func=node_is_ready) - print "All detected nodes are reporting ready" + print("All detected nodes are reporting ready") ``` You will be able to see in `tracking` context results that a timeout occurred for an affected @@ -404,10 +404,10 @@ context information. with oc.api_server('https:///....'): # use the specified api server for nested oc invocations. with oc.token('abc..'): # --server=... --token=abc... will be included in inner oc invocations. - print "Current project: " + oc.get_project_name() + print("Current project: " + oc.get_project_name()) with oc.token('def..'): # --server=... --token=def... will be included in inner oc invocations. - print "Current project: " + oc.get_project_name() + print("Current project: " + oc.get_project_name()) ``` You can control the loglevel specified for `oc` invocations. @@ -443,7 +443,7 @@ appropriate to the target client host. ```python with openshift.client_host(hostname="my.cluster.com", username="root", auto_add_host=True): # oc invocations will take place on my.cluster.com host as the root user. - print "Current project: " + oc.get_project_name() + print("Current project: " + oc.get_project_name()) ``` Using this model, your Python script will run exactly where you launch it, but all oc invocations will diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d969ed6 --- /dev/null +++ b/setup.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + +from setuptools import setup, find_packages + + +def get_requirements(filename="requirements.txt"): + """Extract requirements from a pip formatted requirements file.""" + + with open(filename, "r") as requirements_file: + return requirements_file.read().splitlines() + + +def get_long_description(): + """Returns README.md content.""" + return open("README.md", "r").read() + + +setup( + name="openshift-client", + version="0.1.0", + author="Justin Pierce", + author_email="jupierce@redhat.com", + maintainer="Brad Williams", + maintainer_email="brawilli@redhat.com", + url="https://github.com/openshift/openshift-client-python", + description="OpenShift python client", + packages=find_packages(include="openshift"), + package_dir={"": "packages"}, + install_requires=get_requirements(), + keywords=["OpenShift"], + include_package_data=True, + data_files=[ + ("requirements.txt", ["requirements.txt"]), + ], + long_description=get_long_description(), + long_description_content_type="text/markdown", + classifiers=[ + "Development Status :: 4 - Beta", + "Topic :: Utilities", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.5", + ], +)