Skip to content

Commit b607475

Browse files
kumaabSanket-Shelar
authored andcommitted
RANGER-5653: Updates to apache-ranger Python client with Python 3 support only (#1034)
1 parent f7950da commit b607475

7 files changed

Lines changed: 450 additions & 668 deletions

File tree

.cursor/rules/ranger-python.mdc

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
description: Apache Ranger Python client and test conventions (apache-ranger on PyPI)
3+
globs: intg/**/*.py,ranger-examples/sample-client/**/*.py
4+
alwaysApply: false
5+
---
6+
7+
<!--
8+
Licensed to the Apache Software Foundation (ASF) under one
9+
or more contributor license agreements. See the NOTICE file
10+
distributed with this work for additional information
11+
regarding copyright ownership. The ASF licenses this file
12+
to you under the Apache License, Version 2.0 (the
13+
"License"); you may not use this file except in compliance
14+
with the License. You may obtain a copy of the License at
15+
16+
http://www.apache.org/licenses/LICENSE-2.0
17+
18+
Unless required by applicable law or agreed to in writing, software
19+
distributed under the License is distributed on an "AS IS" BASIS,
20+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
See the License for the specific language governing permissions and
22+
limitations under the License.
23+
-->
24+
25+
# Ranger Python client (`apache-ranger`)
26+
27+
**Authoritative package root:** `intg/src/main/python/` — packaging via `setup.py` there only. Do not add duplicate `setup.py` scripts elsewhere.
28+
29+
**Python version:** `apache-ranger` targets **Python 3.13+** (`python_requires` in `setup.py`).
30+
31+
## Style and structure
32+
33+
- Preserve the ASF license header on new files (match neighboring modules).
34+
- Match existing layout: `apache_ranger/client/` for HTTP clients, `apache_ranger/model/` for typed models, `utils.py` for coercion helpers.
35+
- Reuse `type_coerce` / `type_coerce_attrs()` — accept dict-like input and coerce to model types; do not duplicate parsing logic.
36+
- Keep changes minimal; follow naming, imports, and spacing of the file you edit.
37+
38+
## Vertical alignment
39+
40+
Within a **consecutive block** of related lines, align `=` (and dict values after `:` where keys share one dict):
41+
42+
```python
43+
self.status_code = status_code
44+
self.response = response
45+
self.content = content
46+
47+
from apache_ranger.exceptions import RangerServiceException
48+
from apache_ranger.model.ranger_service import RangerService
49+
50+
RangerAuthzRequest({
51+
"requestId": "req-1",
52+
"user": RangerUserInfo({"name": "alice"}),
53+
"access": RangerAccessInfo({...}),
54+
"context": RangerAccessContext({...}),
55+
})
56+
```
57+
58+
Apply alignment only within the block; do not pad unrelated single assignments. Reference points: `exceptions.py`, `sample_pdp_client.py`, `test_ranger_client.py`.
59+
60+
## Model and sample data
61+
62+
Use **compact dict literals** — one line per top-level field when still readable (`sample_pdp_client.py`). Avoid verbose nesting when a flat line is clear.
63+
64+
## Unit tests
65+
66+
Primary test file: `intg/src/test/python/test_ranger_client.py`
67+
68+
Run from `intg/`:
69+
70+
```bash
71+
PYTHONPATH=src/main/python python -B src/test/python/test_ranger_client.py
72+
```
73+
74+
Split tests **by client** — one `unittest.TestCase` per area (`TestRangerClient`, `TestGDSClient`, `TestPDPClient`).
75+
76+
Fixtures: shared data as **class-level constants** (`URL`, `AUTH`, `AUTHZ_REQUEST`); single-use data inline in the test method.
77+
78+
Assertions and mocking:
79+
80+
- Prefer `assertRaises`, `assertIsNone`, `assertIsInstance` over bare `try/except`.
81+
- Assert **current** client behavior — not obsolete error text or exceptions.
82+
- Mock at the boundary: `Session` for Admin HTTP, `client_http.call_api` for GDS/PDP.
83+
- Only add tests for real coercion, exports, or API wiring.
84+
85+
## References
86+
87+
- `intg/src/main/python/README.md` — published API surface and quickstarts
88+
- `ranger-examples/sample-client/src/main/python/` — Admin, GDS, PDP, KMS usage examples

intg/scripts/setup.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)