Skip to content

Commit 3ac9aad

Browse files
authored
wrapper.get_account_statistics: レスポンスヘッダに'Location'がなくても、エラーにならないようにする。 (#344)
* locationヘッダがないときでも、エラーが発生しないようにする * update dockerfile * update README.md * 名前変更。拡張子ymlは非推奨なため * poetry update * add setting * version up * update README
1 parent 42e62bd commit 3ac9aad

File tree

11 files changed

+112
-187
lines changed

11 files changed

+112
-187
lines changed

.devcontainer/Dockerfile

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM ubuntu:18.04 as devcontainer
22

3+
RUN set -x \
4+
&& sed -i.bak -r 's!(deb|deb-src) \S+!\1 mirror://mirrors.ubuntu.com/mirrors.txt!' /etc/apt/sources.list
5+
36
RUN set -x \
47
&& apt-get update \
58
&& apt-get install -y --no-install-recommends \
@@ -50,6 +53,7 @@ RUN set -x \
5053
iputils-ping \
5154
jq \
5255
less \
56+
make \
5357
net-tools \
5458
openssh-client \
5559
tar \
@@ -91,33 +95,31 @@ RUN set -x \
9195
# docker / docker-compose in devcontainer
9296
RUN set -x \
9397
&& mkdir -p /usr/local/devcontainer-tool/bin \
94-
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker https://github.com/thamaji/devcontainer-docker/releases/download/v1.0.1/docker \
98+
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker https://github.com/thamaji/devcontainer-docker/releases/download/v1.0.2/docker \
9599
&& chmod +x /usr/local/devcontainer-tool/bin/docker \
96-
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker-compose https://github.com/thamaji/devcontainer-compose/releases/download/v1.0.2/docker-compose \
100+
&& curl -fsSL -o /usr/local/devcontainer-tool/bin/docker-compose https://github.com/thamaji/devcontainer-compose/releases/download/v1.0.3/docker-compose \
97101
&& chmod +x /usr/local/devcontainer-tool/bin/docker-compose
98102
ENV PATH=/usr/local/devcontainer-tool/bin:${PATH}
99103

100-
101-
# python3.8, make
104+
# python3.8
102105
RUN set -x \
103106
&& apt-get update \
104107
&& apt-get install -y --no-install-recommends \
105108
python3.8 \
106109
python3-distutils \
107-
make \
108110
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/* \
109111
&& ln -s $(which python3.8) /usr/local/bin/python
110112

111113
# pip
112114
RUN set -x \
113115
&& curl -sSL https://bootstrap.pypa.io/get-pip.py | sudo -u vscode -i python -
116+
ENV PIP_DEFAULT_TIMEOUT=100
114117

115118
# poetry
116119
RUN set -x \
117120
&& curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | sudo -u vscode -i python - \
118121
&& sudo -u vscode -i /home/vscode/.local/bin/poetry config virtualenvs.in-project true
119-
ENV PATH=$PATH:/home/vscode/.local/bin \
120-
PIP_DEFAULT_TIMEOUT=100
122+
ENV PATH=$PATH:/home/vscode/.local/bin
121123

122124
# fix poetry issue (see: https://github.com/python-poetry/poetry/issues/221)
123125
RUN set -x \
@@ -127,7 +129,6 @@ RUN set -x \
127129
&& apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
128130
ENV LC_ALL=C.UTF-8
129131

130-
131132
USER vscode
132133

133134
ADD entrypoint.sh /entrypoint.sh
File renamed without changes.

.vscode/cspell.json

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"astimezone",
2020
"asyncio",
2121
"dateutil",
22+
"favicon",
2223
"giveup",
24+
"pydata",
2325
"pylint",
2426
"tzlocal"
2527
]

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"python.linting.ignorePatterns": [
3333
"generate/**/*.py",
3434
".vscode/*.py",
35-
"**/site-packages/**/*.py"
35+
"**/site-packages/**/*.py",
36+
"docs/**/*.py"
3637
],
3738
"python.analysis.extraPaths": [
3839
".venv/lib/python3.8/site-packages/"

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![CodeQL](https://github.com/kurusugawa-computer/annofab-api-python-client/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/kurusugawa-computer/annofab-api-python-client/actions/workflows/codeql-analysis.yml)
66
[![PyPI version](https://badge.fury.io/py/annofabapi.svg)](https://badge.fury.io/py/annofabapi)
77
[![Python Versions](https://img.shields.io/pypi/pyversions/annofabapi.svg)](https://pypi.org/project/annofabapi/)
8+
[![Documentation Status](https://readthedocs.org/projects/annofab-api-python-client/badge/?version=latest)](https://annofab-api-python-client.readthedocs.io/en/latest/?badge=latest)
89

910

1011

@@ -32,6 +33,9 @@
3233
* `annofabapi.models.JobType` を廃止します。替わりに`annofabapi.models.ProjectJobType`を使用してください。
3334
* `annofabapi.dataclass.job.JobInfo`を廃止します。替わりに`annofabapi.models.ProjectJobInfo`を使用してください。
3435

36+
### 2022-01-01 以降
37+
* Python3.6のサポートを停止し、対応するPythonバージョンを3.7以上にします。
38+
3539
# Features
3640
cURLやPostmanなどよりも簡単にAnnoFab Web APIにアクセスできます。
3741

annofabapi/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.46.3"
1+
__version__ = "0.46.4"

annofabapi/wrapper.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -916,18 +916,23 @@ def put_input_data_from_file(
916916
# Public Method : Statistics
917917
#########################################
918918
@my_backoff
919-
def _request_location_header_url(self, response: requests.Response) -> Any:
919+
def _request_location_header_url(self, response: requests.Response) -> Optional[Any]:
920920
"""
921921
Location headerに記載されているURLの中身を返す。
922922
923923
Args:
924924
response:
925925
926926
Returns:
927-
Location headerに記載されているURLの中身
927+
Location headerに記載されているURLの中身。
928+
レスポンスヘッダにLocationがない場合は、Noneを返す。
928929
929930
"""
930-
url = response.headers["Location"]
931+
url = response.headers.get("Location")
932+
if url is None:
933+
# プロジェクト作成直後などが該当する
934+
logger.warning(f"レスポンスヘッダに'Location'がありません。method={response.request.method}, url={response.request.url}")
935+
return None
931936

932937
response = self.api.session.get(url)
933938
_log_error_response(logger, response)
@@ -949,7 +954,11 @@ def get_task_statistics(self, project_id: str) -> List[Any]:
949954
950955
"""
951956
_, response = self.api.get_task_statistics(project_id)
952-
return self._request_location_header_url(response)
957+
result = self._request_location_header_url(response)
958+
if result is not None:
959+
return result
960+
else:
961+
return []
953962

954963
def get_account_statistics(self, project_id: str) -> List[Any]:
955964
"""
@@ -962,7 +971,11 @@ def get_account_statistics(self, project_id: str) -> List[Any]:
962971
963972
"""
964973
_, response = self.api.get_account_statistics(project_id)
965-
return self._request_location_header_url(response)
974+
result = self._request_location_header_url(response)
975+
if result is not None:
976+
return result
977+
else:
978+
return []
966979

967980
def get_inspection_statistics(self, project_id: str) -> List[Any]:
968981
"""
@@ -975,7 +988,11 @@ def get_inspection_statistics(self, project_id: str) -> List[Any]:
975988
976989
"""
977990
_, response = self.api.get_inspection_statistics(project_id)
978-
return self._request_location_header_url(response)
991+
result = self._request_location_header_url(response)
992+
if result is not None:
993+
return result
994+
else:
995+
return []
979996

980997
def get_task_phase_statistics(self, project_id: str) -> List[Any]:
981998
"""
@@ -988,7 +1005,11 @@ def get_task_phase_statistics(self, project_id: str) -> List[Any]:
9881005
9891006
"""
9901007
_, response = self.api.get_task_phase_statistics(project_id)
991-
return self._request_location_header_url(response)
1008+
result = self._request_location_header_url(response)
1009+
if result is not None:
1010+
return result
1011+
else:
1012+
return []
9921013

9931014
def get_label_statistics(self, project_id: str) -> List[Any]:
9941015
"""
@@ -1001,7 +1022,11 @@ def get_label_statistics(self, project_id: str) -> List[Any]:
10011022
10021023
"""
10031024
_, response = self.api.get_label_statistics(project_id)
1004-
return self._request_location_header_url(response)
1025+
result = self._request_location_header_url(response)
1026+
if result is not None:
1027+
return result
1028+
else:
1029+
return []
10051030

10061031
def get_worktime_statistics(self, project_id: str) -> List[Any]:
10071032
"""
@@ -1016,7 +1041,11 @@ def get_worktime_statistics(self, project_id: str) -> List[Any]:
10161041
10171042
"""
10181043
_, response = self.api.get_worktime_statistics(project_id)
1019-
return self._request_location_header_url(response)
1044+
result = self._request_location_header_url(response)
1045+
if result is not None:
1046+
return result
1047+
else:
1048+
return []
10201049

10211050
#########################################
10221051
# Public Method : Supplementary

docs/_statistics/.gitkeep

Whitespace-only changes.

docs/conf.py

+10-134
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Configuration file for the Sphinx documentation builder.
42
#
5-
# This file does only contain a selection of the most common options. For a
6-
# full list see the documentation:
7-
# http://www.sphinx-doc.org/en/master/config
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
86

97
# -- Path setup --------------------------------------------------------------
108

119
# If extensions (or modules to document with autodoc) are in another directory,
1210
# add these directories to sys.path here. If the directory is relative to the
1311
# documentation root, use os.path.abspath to make it absolute, like shown here.
1412
#
15-
import os
16-
import sys
17-
import annofabapi
18-
19-
sys.path.insert(0, os.path.abspath("../"))
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
2016

2117

2218
# -- Project information -----------------------------------------------------
@@ -25,17 +21,9 @@
2521
copyright = "2019, yuji38kwmt"
2622
author = "yuji38kwmt"
2723

28-
# The short X.Y version.
29-
version = annofabapi.__version__
30-
# The full version, including alpha/beta/rc tags.
31-
release = annofabapi.__version__
3224

3325
# -- General configuration ---------------------------------------------------
3426

35-
# If your documentation needs a minimal Sphinx version, state it here.
36-
#
37-
# needs_sphinx = '1.0'
38-
3927
# Add any Sphinx extension module names here, as strings. They can be
4028
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4129
# ones.
@@ -44,30 +32,11 @@
4432
# Add any paths that contain templates here, relative to this directory.
4533
templates_path = ["_templates"]
4634

47-
# The suffix(es) of source filenames.
48-
# You can specify multiple suffix as a list of string:
49-
#
50-
# source_suffix = ['.rst', '.md']
51-
source_suffix = ".rst"
52-
53-
# The master toctree document.
54-
master_doc = "index"
55-
56-
# The language for content autogenerated by Sphinx. Refer to documentation
57-
# for a list of supported languages.
58-
#
59-
# This is also used if you do content translation via gettext catalogs.
60-
# Usually you set "language" from the command line for these cases.
61-
language = None
62-
6335
# List of patterns, relative to source directory, that match files and
6436
# directories to ignore when looking for source files.
6537
# This pattern also affects html_static_path and html_extra_path.
6638
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
6739

68-
# The name of the Pygments (syntax highlighting) style to use.
69-
pygments_style = None
70-
7140

7241
# -- Options for HTML output -------------------------------------------------
7342

@@ -76,106 +45,13 @@
7645
#
7746
html_theme = "pydata_sphinx_theme"
7847

79-
# Theme options are theme-specific and customize the look and feel of a theme
80-
# further. For a list of options available for each theme, see the
81-
# documentation.
82-
#
83-
html_theme_options = {
84-
"github_url": "https://github.com/kurusugawa-computer/annofab-api-python-client",
85-
}
86-
8748
# Add any paths that contain custom static files (such as style sheets) here,
8849
# relative to this directory. They are copied after the builtin static files,
8950
# so a file named "default.css" will overwrite the builtin "default.css".
90-
# html_static_path = ['_static']
91-
92-
# Custom sidebar templates, must be a dictionary that maps document names
93-
# to template names.
94-
#
95-
# The default sidebars (for documents that don't match any pattern) are
96-
# defined by theme itself. Builtin themes are using these templates by
97-
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
98-
# 'searchbox.html']``.
99-
#
100-
html_sidebars = {"**": ["localtoc.html", "relations.html", "links.html", "searchbox.html"]}
101-
102-
html_copy_source = True
103-
104-
html_show_sourcelink = True
105-
106-
html_logo = "img/logo_landscape.png"
51+
html_static_path = ["_static"]
10752

108-
# html_favicon = "img/favicon.ico"
109-
110-
# -- Options for HTMLHelp output ---------------------------------------------
111-
112-
# Output file base name for HTML help builder.
113-
htmlhelp_basename = "annofabapidoc"
114-
115-
116-
# -- Options for LaTeX output ------------------------------------------------
117-
118-
latex_elements = {
119-
# The paper size ('letterpaper' or 'a4paper').
120-
#
121-
# 'papersize': 'letterpaper',
122-
# The font size ('10pt', '11pt' or '12pt').
123-
#
124-
# 'pointsize': '10pt',
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
# Latex figure (float) alignment
129-
#
130-
# 'figure_align': 'htbp',
53+
html_theme_options = {
54+
"github_url": "https://github.com/kurusugawa-computer/annofab-api-python-client",
13155
}
13256

133-
# Grouping the document tree into LaTeX files. List of tuples
134-
# (source start file, target name, title,
135-
# author, documentclass [howto, manual, or own class]).
136-
latex_documents = [
137-
(master_doc, "annofabapi.tex", "annofabapi Documentation", "yuji38kwmt", "manual"),
138-
]
139-
140-
141-
# -- Options for manual page output ------------------------------------------
142-
143-
# One entry per manual page. List of tuples
144-
# (source start file, name, description, authors, manual section).
145-
man_pages = [(master_doc, "annofabapi", "annofabapi Documentation", [author], 1)]
146-
147-
148-
# -- Options for Texinfo output ----------------------------------------------
149-
150-
# Grouping the document tree into Texinfo files. List of tuples
151-
# (source start file, target name, title, author,
152-
# dir menu entry, description, category)
153-
texinfo_documents = [
154-
(
155-
master_doc,
156-
"annofabapi",
157-
"annofabapi Documentation",
158-
author,
159-
"annofabapi",
160-
"One line description of project.",
161-
"Miscellaneous",
162-
),
163-
]
164-
165-
166-
# -- Options for Epub output -------------------------------------------------
167-
168-
# Bibliographic Dublin Core info.
169-
epub_title = project
170-
171-
# The unique identifier of the text. This can be a ISBN number
172-
# or the project homepage.
173-
#
174-
# epub_identifier = ''
175-
176-
# A unique identification for the text.
177-
#
178-
# epub_uid = ''
179-
180-
# A list of files that should not be packed into the epub file.
181-
epub_exclude_files = ["search.html"]
57+
html_logo = "img/logo_landscape.png"

0 commit comments

Comments
 (0)