amol- commented on a change in pull request #10650:
URL: https://github.com/apache/arrow/pull/10650#discussion_r672359949
##########
File path: dev/archery/archery/crossbow/cli.py
##########
@@ -233,6 +234,31 @@ def latest_prefix(obj, prefix, fetch):
click.echo(latest.branch)
[email protected]()
[email protected]('job-name', required=True)
[email protected]('--fetch/--no-fetch', default=True,
+ help='Fetch references (branches and tags) from the remote')
[email protected]_obj
+def save_report_data(obj, job_name, fetch):
+ """
+ Just print there the state of the job
+ """
+ output = obj['output']
+
+ queue = obj['queue']
+ print(dir(queue))
+
+ if fetch:
+ queue.fetch()
+
+ job = queue.get(job_name)
+ report = JsonReport(job=job)
+
+ with tempfile.NamedTemporaryFile(delete=False) as temp:
+ temp.write(report.show(output))
+ temp.flush()
Review comment:
You don't need to flush here, closing the file will already flush it.
##########
File path: dev/archery/archery/crossbow/reports.py
##########
@@ -121,6 +124,32 @@ def show(self, outstream, asset_callback=None):
asset))
+class JsonReport(Report):
+
+ def url(self, query):
+ repo_url = self.job.queue.remote_url.strip('.git')
+ return '{}/branches/all?query={}'.format(repo_url, query)
+
+ def today_str(self):
+ date = datetime.utcnow()
+ return "{}-{}-{}".format(date.year, date.month, date.day)
+
+ def tasks_to_dict(self, date, tasks):
+ json_tasks = []
+ for task_name, task in tasks.items():
+ json_tasks.append({
+ "build": task_name,
+ "link": self.url(task.branch),
+ "status": task.status().combined_state.upper(),
+ "timestamp": date})
+
+ return json_tasks
+
+ def get_json_tasks(self):
+ tasks = self.tasks_to_dict(self.today_str(), self.job.tasks.items())
+ json_str = json.dump(tasks)
Review comment:
I think this wants to be `json.dumps(tasks)` as `json.dump` wants a
target file, while your goal here is to return as tring.
##########
File path: dev/archery/archery/crossbow/cli.py
##########
@@ -233,6 +234,31 @@ def latest_prefix(obj, prefix, fetch):
click.echo(latest.branch)
[email protected]()
[email protected]('job-name', required=True)
[email protected]('--fetch/--no-fetch', default=True,
+ help='Fetch references (branches and tags) from the remote')
[email protected]_obj
+def save_report_data(obj, job_name, fetch):
+ """
+ Just print there the state of the job
+ """
+ output = obj['output']
+
+ queue = obj['queue']
+ print(dir(queue))
+
+ if fetch:
+ queue.fetch()
+
+ job = queue.get(job_name)
+ report = JsonReport(job=job)
+
+ with tempfile.NamedTemporaryFile(delete=False) as temp:
+ temp.write(report.show(output))
Review comment:
I still don't get where `report.show` should come from. I don't see any
`show` method implemented in `JsonReporter` and I guess you actually wanted to
invoke `report.get_json_tasks()` here as that's what gives you back the json of
the report as a string that you can write back to file..
##########
File path: dev/archery/archery/crossbow/reports.py
##########
@@ -121,6 +124,32 @@ def show(self, outstream, asset_callback=None):
asset))
+class JsonReport(Report):
+
+ def url(self, query):
+ repo_url = self.job.queue.remote_url.strip('.git')
+ return '{}/branches/all?query={}'.format(repo_url, query)
+
+ def today_str(self):
+ date = datetime.utcnow()
+ return "{}-{}-{}".format(date.year, date.month, date.day)
+
+ def tasks_to_dict(self, date, tasks):
+ json_tasks = []
+ for task_name, task in tasks.items():
+ json_tasks.append({
+ "build": task_name,
+ "link": self.url(task.branch),
+ "status": task.status().combined_state.upper(),
+ "timestamp": date})
+
+ return json_tasks
+
+ def get_json_tasks(self):
+ tasks = self.tasks_to_dict(self.today_str(), self.job.tasks.items())
+ json_str = json.dump(tasks)
Review comment:
```
>>> tasks = [{
... "build": "TASK_NAME",
... "link": "HTTP://LINK",
... "status": "STATUS",
... "timestamp": "DATE"
... }]
>>> import json
>>> json.dump(tasks)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: dump() missing 1 required positional argument: 'fp'
```
while instead...
```
>>> json.dumps(tasks)
'[{"build": "TASK_NAME", "link": "HTTP://LINK", "status": "STATUS",
"timestamp": "DATE"}]'
```
##########
File path: dev/archery/archery/crossbow/reports.py
##########
@@ -121,6 +124,32 @@ def show(self, outstream, asset_callback=None):
asset))
+class JsonReport(Report):
+
+ def url(self, query):
+ repo_url = self.job.queue.remote_url.strip('.git')
+ return '{}/branches/all?query={}'.format(repo_url, query)
+
+ def today_str(self):
+ date = datetime.utcnow()
+ return "{}-{}-{}".format(date.year, date.month, date.day)
+
+ def tasks_to_dict(self, date, tasks):
+ json_tasks = []
+ for task_name, task in tasks.items():
+ json_tasks.append({
+ "build": task_name,
+ "link": self.url(task.branch),
+ "status": task.status().combined_state.upper(),
+ "timestamp": date})
+
+ return json_tasks
+
+ def get_json_tasks(self):
+ tasks = self.tasks_to_dict(self.today_str(), self.job.tasks.items())
+ json_str = json.dump(tasks)
Review comment:
I think this wants to be `json.dumps(tasks)` as `json.dump` wants a
target file, while your goal here is to return a string.
##########
File path: dev/archery/archery/crossbow/reports.py
##########
@@ -121,6 +124,32 @@ def show(self, outstream, asset_callback=None):
asset))
+class JsonReport(Report):
+
+ def url(self, query):
+ repo_url = self.job.queue.remote_url.strip('.git')
+ return '{}/branches/all?query={}'.format(repo_url, query)
+
+ def today_str(self):
+ date = datetime.utcnow()
+ return "{}-{}-{}".format(date.year, date.month, date.day)
+
+ def tasks_to_dict(self, date, tasks):
+ json_tasks = []
+ for task_name, task in tasks.items():
+ json_tasks.append({
+ "build": task_name,
+ "link": self.url(task.branch),
+ "status": task.status().combined_state.upper(),
+ "timestamp": date})
+
+ return json_tasks
+
+ def get_json_tasks(self):
+ tasks = self.tasks_to_dict(self.today_str(), self.job.tasks.items())
+ json_str = json.dump(tasks)
Review comment:
```
>>> tasks = [{
... "build": "TASK_NAME",
... "link": "HTTP://LINK",
... "status": "STATUS",
... "timestamp": "DATE"
... }]
>>> import json
>>> json.dump(tasks)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: dump() missing 1 required positional argument: 'fp'
```
while instead...
```
>>> json.dumps(tasks)
'[{"build": "TASK_NAME", "link": "HTTP://LINK", "status": "STATUS",
"timestamp": "DATE"}]'
```
The first `json.dump` wants a file where to write to, the second
`json.dumps` returns a string
##########
File path: dev/archery/archery/crossbow/reports.py
##########
@@ -121,6 +124,32 @@ def show(self, outstream, asset_callback=None):
asset))
+class JsonReport(Report):
+
+ def url(self, query):
+ repo_url = self.job.queue.remote_url.strip('.git')
+ return '{}/branches/all?query={}'.format(repo_url, query)
+
+ def today_str(self):
+ date = datetime.utcnow()
+ return "{}-{}-{}".format(date.year, date.month, date.day)
+
+ def tasks_to_dict(self, date, tasks):
+ json_tasks = []
+ for task_name, task in tasks.items():
+ json_tasks.append({
+ "build": task_name,
+ "link": self.url(task.branch),
+ "status": task.status().combined_state.upper(),
+ "timestamp": date})
+
+ return json_tasks
+
+ def get_json_tasks(self):
+ tasks = self.tasks_to_dict(self.today_str(), self.job.tasks.items())
+ json_str = json.dump(tasks)
Review comment:
```
>>> tasks = [{
... "build": "TASK_NAME",
... "link": "HTTP://LINK",
... "status": "STATUS",
... "timestamp": "DATE"
... }]
```
```
>>> import json
>>> json.dump(tasks)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: dump() missing 1 required positional argument: 'fp'
```
while instead...
```
>>> json.dumps(tasks)
'[{"build": "TASK_NAME", "link": "HTTP://LINK", "status": "STATUS",
"timestamp": "DATE"}]'
```
The first `json.dump` wants a file where to write to, the second
`json.dumps` returns a string
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]