Skip to content

Commit 41a3bcc

Browse files
vedanujapsdehal
authored andcommitted
[enhancement] Cache CircleCI tests, add isort, black tests (#60)
1 parent ec1c81d commit 41a3bcc

File tree

31 files changed

+190
-115
lines changed

31 files changed

+190
-115
lines changed

.circleci/config.yml

+95-28
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,105 @@
1+
# Python CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-python/ for more details
4+
#
5+
# Adopted from
6+
# https://github.com/facebookresearch/detectron2/blob/master/.circleci/config.yml
7+
18
version: 2
9+
10+
# -------------------------------------------------------------------------------------
11+
# Environments to run the jobs in
12+
# -------------------------------------------------------------------------------------
13+
cpu: &cpu
14+
docker:
15+
- image: circleci/python:3.7
16+
resource_class: medium
17+
18+
# -------------------------------------------------------------------------------------
19+
# Re-usable commands
20+
# -------------------------------------------------------------------------------------
21+
setup_venv: &setup_venv
22+
- run:
23+
name: Setup Virtual Env
24+
working_directory: ~/
25+
command: |
26+
python -m venv ~/venv
27+
echo ". ~/venv/bin/activate" >> $BASH_ENV
28+
. ~/venv/bin/activate
29+
python --version
30+
which python
31+
which pip
32+
pip install --upgrade pip
33+
34+
install_dep: &install_dep
35+
- run:
36+
name: Install Dependencies
37+
command: |
38+
pip install --progress-bar off -r requirements.txt
39+
pip install --progress-bar off flake8
40+
pip install --progress-bar off black
41+
pip install --progress-bar off isort
42+
43+
install_repo: &install_repo
44+
- run:
45+
name: Install Repository
46+
command: |
47+
python setup.py build develop
48+
49+
run_unittests: &run_unittests
50+
- run:
51+
name: Run Unit Tests
52+
command: |
53+
cd tests
54+
pytest -v .
55+
56+
run_flake8: &run_flake8
57+
- run:
58+
name: Run Linter (flake8)
59+
command: |
60+
# stop the build if there are Python syntax errors or undefined names
61+
flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
62+
# exit-zero treats all errors as warnings
63+
flake8 . --count --exit-zero --max-complexity=18 --max-line-length=88 --statistics
64+
65+
# -------------------------------------------------------------------------------------
66+
# Jobs to run
67+
# -------------------------------------------------------------------------------------
68+
269
jobs:
370
build:
4-
docker:
5-
- image: circleci/python:3.7
71+
<<: *cpu
72+
673
working_directory: ~/pythia
74+
775
steps:
876
- checkout
77+
- <<: *setup_venv
78+
79+
# Cache the venv directory that contains dependencies
80+
- restore_cache:
81+
keys:
82+
- cache-key-{{ checksum "requirements.txt"}}-{{ checksum "setup.py"}}
83+
84+
- <<: *install_dep
85+
86+
- save_cache:
87+
paths:
88+
- ~/venv
89+
key: cache-key-{{ checksum "requirements.txt"}}-{{ checksum "setup.py"}}
90+
91+
- <<: *install_repo
92+
993
- run:
10-
name: Install Dependencies
94+
name: Run Linter (isort)
1195
command: |
12-
python3 -m venv venv
13-
. venv/bin/activate
14-
pip install --upgrade pip
15-
python setup.py develop
96+
isort -c -sp .
97+
1698
- run:
17-
name: Run linter (flake8)
99+
name: Run Linter (black)
18100
command: |
19-
. venv/bin/activate
20-
pip install flake8
21-
# stop the build if there are Python syntax errors or undefined names
22-
flake8 . --count --exclude=./venv --select=E9,F63,F72,F82 --show-source --statistics
23-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
24-
flake8 . --count --exclude=./venv --exit-zero --max-complexity=10 --max-line-length=127 --statistics
25-
- run:
26-
name: Download required data
27-
command: |
28-
mkdir data
29-
cd data
30-
wget http://dl.fbaipublicfiles.com/pythia/data/vocab.tar.gz
31-
tar xf vocab.tar.gz
32-
cd ..
33-
- run:
34-
name: Run Tests
35-
command: |
36-
. venv/bin/activate
37-
cd tests
38-
pytest -v .
101+
black --check -l 88 .
102+
103+
- <<: *run_flake8
104+
105+
- <<: *run_unittests

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ indent_style = space
99
indent_size = 4
1010

1111
[*.md]
12-
trim_trailing_whitespace = false
12+
trim_trailing_whitespace = false

docs/source/conf.py

+54-44
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,47 @@
3232
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3333
# ones.
3434

35-
import sphinx_rtd_theme
3635
import recommonmark
36+
import sphinx_rtd_theme
3737
from recommonmark.transform import AutoStructify
3838

39-
40-
extensions = ['sphinx.ext.autodoc',
41-
'sphinx.ext.doctest',
42-
'sphinx.ext.todo',
43-
'sphinx.ext.coverage',
44-
'sphinx.ext.mathjax',
45-
'sphinx.ext.ifconfig',
46-
'sphinx.ext.viewcode',
47-
'sphinx.ext.napoleon',
48-
'sphinx.ext.intersphinx',
49-
'recommonmark']
39+
extensions = [
40+
"sphinx.ext.autodoc",
41+
"sphinx.ext.doctest",
42+
"sphinx.ext.todo",
43+
"sphinx.ext.coverage",
44+
"sphinx.ext.mathjax",
45+
"sphinx.ext.ifconfig",
46+
"sphinx.ext.viewcode",
47+
"sphinx.ext.napoleon",
48+
"sphinx.ext.intersphinx",
49+
"recommonmark",
50+
]
5051

5152
# Add any paths that contain templates here, relative to this directory.
52-
templates_path = ['_templates']
53+
templates_path = ["_templates"]
5354

5455
# The suffix(es) of source filenames.
5556
# You can specify multiple suffix as a list of string:
56-
source_suffix = ['.rst', '.md']
57+
source_suffix = [".rst", ".md"]
5758
# source_suffix = '.rst'
5859

5960
# The master toctree document.
60-
master_doc = 'index'
61+
master_doc = "index"
6162

6263
# General information about the project.
63-
project = 'Pythia'
64-
copyright = '2019, Facebook AI Research'
65-
author = 'Facebook AI Research'
64+
project = "Pythia"
65+
copyright = "2019, Facebook AI Research"
66+
author = "Facebook AI Research"
6667

6768
# The version info for the project you're documenting, acts as replacement for
6869
# |version| and |release|, also used in various other places throughout the
6970
# built documents.
7071
#
7172
# The short X.Y version.
72-
version = '0.3'
73+
version = "0.3"
7374
# The full version, including alpha/beta/rc tags.
74-
release = '0.3'
75+
release = "0.3"
7576

7677
# The language for content autogenerated by Sphinx. Refer to documentation
7778
# for a list of supported languages.
@@ -83,10 +84,10 @@
8384
# List of patterns, relative to source directory, that match files and
8485
# directories to ignore when looking for source files.
8586
# This patterns also effect to html_static_path and html_extra_path
86-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
87+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
8788

8889
# The name of the Pygments (syntax highlighting) style to use.
89-
pygments_style = 'sphinx'
90+
pygments_style = "sphinx"
9091

9192
# If true, `todo` and `todoList` produce output, else they produce nothing.
9293
todo_include_todos = True
@@ -97,7 +98,7 @@
9798
# The theme to use for HTML and HTML Help pages. See the documentation for
9899
# a list of builtin themes.
99100
#
100-
html_theme = 'sphinx_rtd_theme'
101+
html_theme = "sphinx_rtd_theme"
101102
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
102103

103104
# Theme options are theme-specific and customize the look and feel of a theme
@@ -109,25 +110,25 @@
109110
# Add any paths that contain custom static files (such as style sheets) here,
110111
# relative to this directory. They are copied after the builtin static files,
111112
# so a file named "default.css" will overwrite the builtin "default.css".
112-
html_static_path = ['_static']
113+
html_static_path = ["_static"]
113114

114115
# Custom sidebar templates, must be a dictionary that maps document names
115116
# to template names.
116117
#
117118
# This is required for the alabaster theme
118119
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
119120
html_sidebars = {
120-
'**': [
121-
'relations.html', # needs 'show_related': True theme option to display
122-
'searchbox.html',
121+
"**": [
122+
"relations.html", # needs 'show_related': True theme option to display
123+
"searchbox.html",
123124
]
124125
}
125126

126127

127128
# -- Options for HTMLHelp output ------------------------------------------
128129

129130
# Output file base name for HTML help builder.
130-
htmlhelp_basename = 'pythiadoc'
131+
htmlhelp_basename = "pythiadoc"
131132

132133

133134
# -- Options for LaTeX output ---------------------------------------------
@@ -136,15 +137,12 @@
136137
# The paper size ('letterpaper' or 'a4paper').
137138
#
138139
# 'papersize': 'letterpaper',
139-
140140
# The font size ('10pt', '11pt' or '12pt').
141141
#
142142
# 'pointsize': '10pt',
143-
144143
# Additional stuff for the LaTeX preamble.
145144
#
146145
# 'preamble': '',
147-
148146
# Latex figure (float) alignment
149147
#
150148
# 'figure_align': 'htbp',
@@ -154,19 +152,21 @@
154152
# (source start file, target name, title,
155153
# author, documentclass [howto, manual, or own class]).
156154
latex_documents = [
157-
(master_doc, 'pythia.tex', 'Pythia Documentation',
158-
'Facebook AI Research', 'manual'),
155+
(
156+
master_doc,
157+
"pythia.tex",
158+
"Pythia Documentation",
159+
"Facebook AI Research",
160+
"manual",
161+
),
159162
]
160163

161164

162165
# -- Options for manual page output ---------------------------------------
163166

164167
# One entry per manual page. List of tuples
165168
# (source start file, name, description, authors, manual section).
166-
man_pages = [
167-
(master_doc, 'pythia', 'Pythia Documentation',
168-
[author], 1)
169-
]
169+
man_pages = [(master_doc, "pythia", "Pythia Documentation", [author], 1)]
170170

171171

172172
# -- Options for Texinfo output -------------------------------------------
@@ -175,17 +175,27 @@
175175
# (source start file, target name, title, author,
176176
# dir menu entry, description, category)
177177
texinfo_documents = [
178-
(master_doc, 'pythia', 'pythia Documentation',
179-
author, 'pythia', 'One line description of project.',
180-
'Miscellaneous'),
178+
(
179+
master_doc,
180+
"pythia",
181+
"pythia Documentation",
182+
author,
183+
"pythia",
184+
"One line description of project.",
185+
"Miscellaneous",
186+
),
181187
]
182188

183189
github_doc_root = "https://github.com/facebookresearch/pythia/blob/v0.3/"
184190

185191
# At the bottom of conf.py
186192
def setup(app):
187-
app.add_config_value('recommonmark_config', {
188-
'url_resolver': lambda url: github_doc_root + url,
189-
'auto_toc_tree_section': 'Contents',
190-
}, True)
193+
app.add_config_value(
194+
"recommonmark_config",
195+
{
196+
"url_resolver": lambda url: github_doc_root + url,
197+
"auto_toc_tree_section": "Contents",
198+
},
199+
True,
200+
)
191201
app.add_transform(AutoStructify)

docs/source/utils/text_utils.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ utils.text_utils
22
===============
33

44
.. automodule:: pythia.utils.text_utils
5-
:members:
5+
:members:

pythia/datasets/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Facebook, Inc. and its affiliates.
2+
from .base_dataset import BaseDataset
23
from .base_dataset_builder import BaseDatasetBuilder
34
from .multi_dataset import MultiDataset
4-
from .base_dataset import BaseDataset
55

66
__all__ = ["BaseDataset", "BaseDatasetBuilder", "MultiDataset"]

pythia/datasets/builders/clevr/builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import zipfile
55
from collections import Counter
66

7-
from pythia.common.registry import registry
87
from pythia.common.constants import CLEVR_DOWNLOAD_URL
8+
from pythia.common.registry import registry
99
from pythia.datasets.base_dataset_builder import BaseDatasetBuilder
1010
from pythia.datasets.builders.clevr.dataset import CLEVRDataset
1111
from pythia.utils.general import download_file, get_pythia_root

pythia/datasets/builders/coco/masked_builder.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pythia.common.registry import registry
22
from pythia.datasets.builders.coco.builder import COCOBuilder
33

4-
54
from .masked_dataset import MaskedCOCODataset
65

76

pythia/datasets/builders/conceptual_captions/masked_builder.py

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pythia.common.registry import registry
33
from pythia.datasets.builders.coco import MaskedCOCOBuilder
44

5-
65
from .masked_dataset import MaskedConceptualCaptionsDataset
76

87

pythia/datasets/builders/mmimdb/builder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77

88
from pythia.common.registry import registry
9-
from pythia.datasets.builders.vqa2.builder import VQA2Builder
109
from pythia.datasets.builders.mmimdb.dataset import MMIMDbDataset
10+
from pythia.datasets.builders.vqa2.builder import VQA2Builder
1111

1212

1313
@registry.register_builder("mmimdb")

0 commit comments

Comments
 (0)