Skip to content

Commit a1cf31a

Browse files
Merge pull request #59 from bradmwilliams/version-bump
Creating the correct version that corresponds with github
2 parents 28e589a + ef705ec commit a1cf31a

File tree

8 files changed

+166
-29
lines changed

8 files changed

+166
-29
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
*.pyc
33
*.zip
44
examples/dumps
5+
dist/
6+
packages/openshift_client.egg-info/
7+
build/

ansible/rebuild_module.digest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14fd6a307ac3c1c78d0a1e69452ae072 -
1+
5989e72fd25bf177445364381d4ad2dd -

ansible/roles/openshift_client_python/library/openshift_client_python.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/PACKAGING.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Openshift Python Client Packaging
2+
3+
## Introduction
4+
This document primarily serves as a reference for us to publish the openshift-client module to PyPI for general consumption by our consumers. It can also be used by anyone interested in getting started with Python Packaging as all the documented steps and configurations can easily be migrated to any other package/module.
5+
6+
## Recommended Setup
7+
### Create User Accounts
8+
To work with packaging, you will need to create user accounts on one or both of the following sites:
9+
10+
#### PyPI - The Python Package Index
11+
For **official** releases that are available for installation
12+
* https://pypi.org/
13+
14+
#### TestPyPI - The Test Python Package Index
15+
For **testing** python packaging without impacting the official index
16+
* https://test.pypi.org/
17+
18+
### Generate API Tokens
19+
For each account that you create, you can generate API Tokens that make publishing your packages/modules easier. Once the tokens have been generated, you can add them to your `~/.pypirc` file:
20+
21+
```text
22+
[pypi]
23+
username = __token__
24+
password = pypi-<API TOKEN>
25+
26+
[testpypi]
27+
repository: https://test.pypi.org/legacy/
28+
username = __token__
29+
password = pypi-<API TOKEN>
30+
```
31+
32+
### setup.cfg
33+
The openshift-client module has been tested to support both python2 and python3. Therefore, elect to build a `univeral` wheel instead of platform specific wheels. To do so, we have added the necessary flags to our `setup.cfg` file:
34+
```text
35+
[bdist_wheel]
36+
universal = 1
37+
38+
[metadata]
39+
license_file = LICENSE
40+
```
41+
42+
The alternative is to add the necessary flag to the commandline when building your packages:
43+
44+
```bash
45+
python setup.py build bdist_wheel --universal
46+
```
47+
48+
## Building
49+
For openshift-client, build both a source distribution and a universal wheel:
50+
```bash
51+
python setup.py build sdist bdist_wheel
52+
```
53+
54+
## Publishing
55+
Publishing to either package index is accomplished by using [Twine](https://pypi.org/project/twine/). Because we setup our local `~/.pypirc` above, we can reference the repository by the name defined therein instead of passing the full URL on the commandline.
56+
57+
### TestPyPI
58+
```bash
59+
twine upload --repository testpypi dist/*
60+
```
61+
62+
### PyPI
63+
```bash
64+
twine upload --repository pypi dist/*
65+
```
66+
67+
## Installation
68+
69+
### TestPyPI
70+
Installation from TestPyPI must be performed using one of the following methods:
71+
72+
1. Latest version
73+
```bash
74+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple openshift-client
75+
```
76+
2. Specific version
77+
```bash
78+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple openshift-client==1.0.2
79+
```
80+
81+
### PyPI
82+
1. Latest version
83+
```bash
84+
pip install openshift-client
85+
```
86+
87+
2. Specific version
88+
```bash
89+
pip install openshift-client==1.0.2
90+
```
91+
92+
## Cleanup
93+
If you're working on changes, you'll need to bump the version string for every publish to either index (releases are unique). To cleanup the artifacts from previous builds, you can execute the following:
94+
```bash
95+
rm -rf dist/ packages/openshift_client.egg-info/ build/
96+
```
97+
98+
## Helpful Links
99+
* https://packaging.python.org/guides/distributing-packages-using-setuptools/
100+
* https://setuptools.readthedocs.io/en/latest/index.html
101+
* https://packaging.python.org/guides/single-sourcing-package-version/
102+
* https://packaging.python.org/guides/using-testpypi/
103+
* https://packaging.python.org/tutorials/packaging-projects/
104+
* https://github.com/pypa/sampleproject
105+
* https://realpython.com/pypi-publish-python-package/
106+
* https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/index.html

examples/coverage.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@
22

33
from __future__ import print_function
44
from __future__ import absolute_import
5-
from openshift import *
5+
6+
import openshift as oc
7+
from openshift import null, Missing, OpenShiftPythonException
68

79
try:
810

9-
print("Projects created by users:", \
10-
oc.selector("projects").narrow(
11-
lambda project: project.metadata.annotations["openshift.io/requester"] is not Missing
11+
print("Projects created by users:", oc.selector("projects").narrow(
12+
lambda prj: prj.metadata.annotations["openshift.io/requester"] is not Missing
1213
).qnames())
1314

1415
oc.selector("projects").narrow(
1516
# Eliminate any projects created by the system
16-
lambda project: project.metadata.annotations["openshift.io/requester"] is not Missing
17+
lambda prj: prj.metadata.annotations["openshift.io/requester"] is not Missing
1718
).narrow(
1819
# Select from user projects any which violate privileged naming convention
19-
lambda project:
20-
project.metadata.qname == "openshift" or
21-
project.metadata.qname.startswith("openshift-") or
22-
project.metadata.qname == "kubernetes" or
23-
project.metadata.qname.startswith("kube-") or
24-
project.metadata.qname.startswith("kubernetes-")
20+
lambda prj:
21+
prj.metadata.qname == "openshift" or
22+
prj.metadata.qname.startswith("openshift-") or
23+
prj.metadata.qname == "kubernetes" or
24+
prj.metadata.qname.startswith("kube-") or
25+
prj.metadata.qname.startswith("kubernetes-")
2526
).for_each(
26-
lambda project: error("Invalid project: %s" % project.metadata.qname)
27+
lambda prj: oc.error("Invalid project: %s" % prj.metadata.qname)
2728
)
2829

29-
with timeout(5):
30+
with oc.timeout(5):
3031
success, obj = oc.selector("pods").until_any(lambda pod: pod.status.phase == "Succeeded")
3132
if success:
3233
print("Found one pod was successful: " + str(obj))
3334

34-
with timeout(5):
35+
with oc.timeout(5):
3536
success, obj = oc.selector("pods").narrow("pod").until_any(
3637
lambda pod: pod.status.conditions.can_match({"type": "Ready", "status": False, "reason": "PodCompleted"}))
3738
if success:
3839
print("Found one pod was successful: " + str(obj))
3940

41+
with oc.project("myproject") as project:
4042

41-
42-
with project("myproject"):
43-
44-
oc.create_if_absent(
43+
project.create_if_absent(
4544
{
4645
"apiVersion": "v1",
4746
"kind": "User",
@@ -56,7 +55,7 @@
5655
}
5756
)
5857

59-
oc.create_if_absent(
58+
project.create_if_absent(
6059
{
6160
"apiVersion": "v1",
6261
"kind": "User",
@@ -71,7 +70,6 @@
7170
}
7271
)
7372

74-
7573
pods = oc.selector("pod")
7674
print("Pods: " + str(pods.qnames()))
7775

@@ -84,7 +82,7 @@
8482
print(str(user))
8583

8684
john = oc.selector("user/john")
87-
john.label({"mylabel": None}) # remove a label
85+
john.label({"mylabel": null}) # remove a label
8886

8987
label_selector = oc.selector("users", labels={"mylabel": "myvalue"})
9088

@@ -98,7 +96,7 @@
9896

9997
users.label({"another_label": "another_value"})
10098

101-
john.patch({
99+
john.object().patch({
102100
"groups": null,
103101
"identities": [
104102
"github: 19783215"
@@ -117,7 +115,7 @@
117115
if user.notthere.dontcare.wontbreak is not Missing:
118116
print("Should see this, but also shouldn't see exception")
119117

120-
oc.delete_if_present("user/bark", "user/bite")
118+
project.delete_if_present("user/bark", "user/bite")
121119

122120
bark_obj = {
123121
"apiVersion": "v1",
@@ -157,7 +155,5 @@
157155

158156
bark_bite_sel.until_any(lambda obj: obj.metadata.qname == "bite")
159157

160-
161-
162158
except OpenShiftPythonException as e:
163159
print("An exception occurred: " + str(e))

packages/openshift/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010
from . import status
1111
from . import config
1212
from .ansible import ansible
13+
14+
# Single source for module version
15+
__VERSION__ = '1.0.2'
16+
1317
null = None # Allow scripts to specify null in object definitions
1418

1519

1620
# Allows modules to trigger errors
1721
def error(msg, **kwargs):
1822
raise OpenShiftPythonException(msg, **kwargs)
23+
24+
25+
# Convenience method for accessing the module version
26+
def get_module_version():
27+
return __VERSION__

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[bdist_wheel]
2+
universal = 1
3+
4+
[metadata]
5+
license_file = LICENSE

setup.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python
22

3+
import os
34
from setuptools import setup, find_packages
45

56

@@ -15,16 +16,33 @@ def get_long_description():
1516
return open("README.md", "r").read()
1617

1718

19+
def read(rel_path):
20+
"""Returns the contents of the file at the specified relative path."""
21+
here = os.path.abspath(os.path.dirname(__file__))
22+
with open(os.path.join(here, rel_path), 'r') as fp:
23+
return fp.read()
24+
25+
26+
def get_version(rel_path):
27+
"""Returns the semantic version for the openshift-client module."""
28+
for line in read(rel_path).splitlines():
29+
if line.startswith('__VERSION__'):
30+
delim = '"' if '"' in line else "'"
31+
return line.split(delim)[1]
32+
else:
33+
raise RuntimeError("Unable to find version string.")
34+
35+
1836
setup(
1937
name="openshift-client",
20-
version="0.1.0",
38+
version=get_version('packages/openshift/__init__.py'),
2139
author="Justin Pierce",
2240
author_email="[email protected]",
2341
maintainer="Brad Williams",
2442
maintainer_email="[email protected]",
2543
url="https://github.com/openshift/openshift-client-python",
2644
description="OpenShift python client",
27-
packages=find_packages(include="openshift"),
45+
packages=find_packages(where='packages'),
2846
package_dir={"": "packages"},
2947
install_requires=get_requirements(),
3048
keywords=["OpenShift"],

0 commit comments

Comments
 (0)