Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Better dynamic enum generation, with support for docs and introspecti…
Browse files Browse the repository at this point in the history
…on (#207)
  • Loading branch information
ysimonson authored Jul 29, 2020
1 parent 822ab2b commit bbf2d25
Show file tree
Hide file tree
Showing 9 changed files with 743 additions and 77 deletions.
773 changes: 721 additions & 52 deletions docs/python_pachyderm.m.html

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/python_pachyderm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ def import_item(g, module, key):

if isinstance(value, _EnumTypeWrapper):
# Dynamically define an enum class that is exported
enum_values = _enum._EnumDict()
enum_values.update(dict(value.items()))
enum_class = type(key, (_enum.IntEnum,), enum_values)
g[key] = enum_class
g[key] = _enum.Enum(key, {k: v for (k, v) in value.items()})
else:
# Export the value
g[key] = value
Expand Down
8 changes: 4 additions & 4 deletions src/python_pachyderm/mixin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def authorize(self, repo, scope):
* `repo`: A string specifying the repo name that the caller wants
access to.
* `scope`: A `Scope` object specifying the access level that the
caller needs to perform an action.
* `scope`: An int specifying the access level that the caller needs to
perform an action. See the `Scope` enum for variants.
"""
return self._req(Service.AUTH, "Authorize", repo=repo, scope=scope).authorized

Expand Down Expand Up @@ -184,8 +184,8 @@ def set_scope(self, username, repo, scope):
no ":"), then it's assumed to be a github user's principal.
* `repo`: A string specifying the object to which `username`s access
level is being granted/revoked.
* `scope`: A `Scope` object specifying the access level that
`username` will now have.
* `scope`: An int specifying the access level that `username` will now
have. See the `Scope` enum for variants.
"""
return self._req(Service.AUTH, "SetScope", username=username, repo=repo, scope=scope)

Expand Down
4 changes: 2 additions & 2 deletions src/python_pachyderm/mixin/pfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def inspect_commit(self, commit, block_state=None):
* `commit`: A tuple, string, or `Commit` object representing the
commit.
* `block_state`: Causes inspect commit to block until the commit is in
the desired commit state.
* An optional int that causes this method to block until the commit is
in the desired commit state. See the `CommitState` enum.
"""
return self._req(Service.PFS, "InspectCommit", commit=commit_from(commit), block_state=block_state)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_one_time_password():
@util.skip_if_no_enterprise()
def test_authorize():
with sandbox() as client:
assert client.authorize("foobar", python_pachyderm.Scope.READER)
assert client.authorize("foobar", python_pachyderm.Scope.READER.value)

@util.skip_if_no_enterprise()
def test_who_am_i():
Expand All @@ -70,10 +70,10 @@ def test_scope():
with sandbox() as client:
repo = util.create_test_repo(client, "test_scope")
scopes = client.get_scope("robot:root", repo)
assert all(s == python_pachyderm.Scope.NONE for s in scopes)
client.set_scope("robot:root", repo, python_pachyderm.Scope.READER)
assert all(s == python_pachyderm.Scope.NONE.value for s in scopes)
client.set_scope("robot:root", repo, python_pachyderm.Scope.READER.value)
scopes = client.get_scope("robot:root", repo)
assert all(s == python_pachyderm.Scope.NONE for s in scopes)
assert all(s == python_pachyderm.Scope.NONE.value for s in scopes)

@util.skip_if_no_enterprise()
def test_acl():
Expand All @@ -82,7 +82,7 @@ def verify_acl(client, repo):
assert len(acl.entries) == 1
assert len(acl.robot_entries) == 0
assert acl.entries[0].username == "robot:root"
assert acl.entries[0].scope == python_pachyderm.Scope.OWNER
assert acl.entries[0].scope == python_pachyderm.Scope.OWNER.value
return acl

with sandbox() as client:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
def test_enterprise():
client = python_pachyderm.Client()
client.activate_enterprise(os.environ["PACH_PYTHON_ENTERPRISE_CODE"])
assert client.get_enterprise_state().state == python_pachyderm.State.ACTIVE
assert client.get_enterprise_state().state == python_pachyderm.State.ACTIVE.value
client.deactivate_enterprise()
10 changes: 5 additions & 5 deletions tests/test_pfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ def test_list_file():
files = list(client.list_file(c, '/'))
assert len(files) == 2
assert files[0].size_bytes == 4
assert files[0].file_type == python_pachyderm.FileType.FILE
assert files[0].file_type == python_pachyderm.FileType.FILE.value
assert files[0].file.path == "/file1.dat"
assert files[1].size_bytes == 4
assert files[1].file_type == python_pachyderm.FileType.FILE
assert files[1].file_type == python_pachyderm.FileType.FILE.value
assert files[1].file.path == "/file2.dat"

def test_walk_file():
Expand Down Expand Up @@ -430,16 +430,16 @@ def test_glob_file():
files = list(client.glob_file(c, '/*.dat'))
assert len(files) == 2
assert files[0].size_bytes == 4
assert files[0].file_type == python_pachyderm.FileType.FILE
assert files[0].file_type == python_pachyderm.FileType.FILE.value
assert files[0].file.path == "/file1.dat"
assert files[1].size_bytes == 4
assert files[1].file_type == python_pachyderm.FileType.FILE
assert files[1].file_type == python_pachyderm.FileType.FILE.value
assert files[1].file.path == "/file2.dat"

files = list(client.glob_file(c, '/*1.dat'))
assert len(files) == 1
assert files[0].size_bytes == 4
assert files[0].file_type == python_pachyderm.FileType.FILE
assert files[0].file_type == python_pachyderm.FileType.FILE.value
assert files[0].file.path == "/file1.dat"

def test_delete_file():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pps.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ def test_stop_job():
except:
# if it failed, it should be because the job already finished
job = sandbox.client.inspect_job(job_id)
assert job.state == python_pachyderm.JobState.JOB_SUCCESS
assert job.state == python_pachyderm.JobState.JOB_SUCCESS.value
else:
# This is necessary because `StopJob` does not wait for the job to be
# killed before returning a result.
# TODO: remove once this is fixed:
# https://github.com/pachyderm/pachyderm/issues/3856
time.sleep(1)
job = sandbox.client.inspect_job(job_id)
assert job.state == python_pachyderm.JobState.JOB_KILLED
assert job.state == python_pachyderm.JobState.JOB_KILLED.value

def test_delete_job():
sandbox = Sandbox("delete_job")
Expand All @@ -86,7 +86,7 @@ def test_datums():
datums = list(sandbox.client.list_datum(job_id))
assert len(datums) == 1
datum = sandbox.client.inspect_datum(job_id, datums[0].datum_info.datum.id)
assert datum.state == python_pachyderm.DatumState.SUCCESS
assert datum.state == python_pachyderm.DatumState.SUCCESS.value

# Skip this check in >=1.11.0, due to a bug:
# https://github.com/pachyderm/pachyderm/issues/5123
Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def create_test_pipeline(client, test_name):

def wait_for_job(client, commit):
# block until the commit is ready
client.inspect_commit(commit, block_state=python_pachyderm.CommitState.READY)
client.inspect_commit(commit, block_state=python_pachyderm.CommitState.READY.value)

# while the commit is ready, the job might not be listed on the first
# call, so repeatedly list jobs until it's available
Expand Down

0 comments on commit bbf2d25

Please sign in to comment.