Skip to content

Commit e7d4bdc

Browse files
author
Jon Duckworth
authored
Merge pull request #401 from l0b0/introduce-pre-commit
Introduce pre-commit
2 parents 4a6a564 + 87bfa42 commit e7d4bdc

10 files changed

+119
-211
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
**PR Checklist:**
88

9-
- [ ] Code is formatted (run `scripts/format`)
9+
- [ ] Code is formatted (run `pre-commit run --all-files`)
1010
- [ ] Tests pass (run `scripts/test`)
1111
- [ ] This PR maintains or improves overall codebase code coverage.
1212
- [ ] Changes are added to the [CHANGELOG](https://github.com/stac-utils/pystac/blob/develop/CHANGELOG.md). See [the docs](https://pystac.readthedocs.io/en/latest/contributing.html#changelog) for information about adding to the changelog.

.github/workflows/continuous-integration.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858

5959
- name: Install dependencies
6060
run: |
61+
pip install --upgrade pip
6162
pip install -r requirements-test.txt
6263
pip install -e ".[validation]"
6364
@@ -103,10 +104,11 @@ jobs:
103104

104105
- name: Install dependencies
105106
run: |
107+
pip install --upgrade pip
106108
pip install -r requirements-test.txt
107109
108110
- name: Execute linters & type checkers
109-
run: ./scripts/lint
111+
run: pre-commit run --all-files
110112

111113
vanilla:
112114
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Configuration file for pre-commit (https://pre-commit.com/).
2+
# Please run `pre-commit run --all-files` when adding or changing entries.
3+
4+
repos:
5+
- repo: local
6+
hooks:
7+
- id: black
8+
name: black
9+
entry: black
10+
language: system
11+
stages: [commit]
12+
types: [python]
13+
14+
- id: codespell
15+
name: codespell
16+
entry: codespell
17+
args: [--ignore-words=.codespellignore]
18+
language: system
19+
stages: [commit]
20+
types_or: [jupyter, markdown, python, shell]
21+
22+
- id: doc8
23+
name: doc8
24+
entry: doc8
25+
language: system
26+
files: \.rst$
27+
require_serial: true
28+
29+
- id: flake8
30+
name: flake8
31+
entry: flake8
32+
language: system
33+
stages: [commit]
34+
types: [python]
35+
36+
- id: mypy
37+
name: mypy
38+
entry: mypy
39+
args: [--no-incremental]
40+
language: system
41+
stages: [commit]
42+
types: [python]
43+
require_serial: true

README.md

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -55,79 +55,7 @@ See the [documentation page](https://pystac.readthedocs.io/en/latest/) for the l
5555

5656
## Developing
5757

58-
To ensure development libraries are installed, install everything in `requirements-dev.txt`:
59-
60-
```
61-
> pip install -r requirements-dev.txt
62-
```
63-
64-
### Unit Tests
65-
66-
Unit tests are in the `tests` folder. To run unit tests, use `unittest`:
67-
68-
```
69-
> python -m unittest discover tests
70-
```
71-
72-
To run linters, code formatters, and test suites all together, use `test`:
73-
74-
```
75-
> ./scripts/test
76-
```
77-
78-
### Code quality checks
79-
80-
PySTAC uses [flake8](http://flake8.pycqa.org/en/latest/) and [yapf](https://github.com/google/yapf) for code formatting and style checks.
81-
82-
To run the flake8 style checks:
83-
84-
```
85-
> flake8 pystac tests
86-
```
87-
88-
To format code:
89-
90-
```
91-
> yapf -ipr pystac tests
92-
```
93-
94-
Note that you may have to use `yapf3` explicitly depending on your environment.
95-
96-
To check for spelling mistakes in modified files:
97-
98-
```
99-
> git diff --name-only | xargs codespell -I .codespellignore -f
100-
```
101-
102-
You can also run the `./scripts/test` script to check for linting, spelling, and run unit tests.
103-
104-
### Continuous Integration
105-
106-
CI will run the `scripts/test` script to check for code quality. If you have a Pull Request that fails CI, make sure to fix any linting, spelling or test issues reported by `scripts/test`.
107-
108-
### Documentation
109-
110-
To build and develop the documentation locally, make sure sphinx is available (which is installed with `requirements-dev.txt`), and use the Makefile in the docs folder:
111-
112-
```
113-
> cd docs
114-
> make html
115-
> make livehtml
116-
```
117-
118-
> Note: You will see some warnings along the lines of
119-
> ```
120-
> WARNING: duplicate object description of pystac.Collection.id,
121-
> other instance in api, use :noindex: for one of them
122-
> ```
123-
> for some of the
124-
> classes. This is expected due to [sphinx-doc/sphinx#8664](https://github.com/sphinx-doc/sphinx/issues/8664).
125-
126-
Use 'make' without arguments to see a list of available commands.
127-
128-
__Note__: `nbsphinx` requires that a local `pystac` is installed; use `pip install -e .`.
129-
130-
58+
See [contributing docs](docs/contributing.rst)
13159

13260
## Running the quickstart and tutorials
13361

docs/conf.py

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@
1717
import subprocess
1818
from typing import Any, Dict
1919

20-
sys.path.insert(0, os.path.abspath('.'))
21-
sys.path.insert(0, os.path.abspath('../'))
22-
from pystac.version import __version__, STACVersion
20+
sys.path.insert(0, os.path.abspath("."))
21+
sys.path.insert(0, os.path.abspath("../"))
22+
from pystac.version import __version__, STACVersion # noqa:E402
2323

24-
git_branch = subprocess.check_output(['git',
25-
'rev-parse',
26-
'--abbrev-ref',
27-
'HEAD']) \
28-
.decode("utf-8") \
29-
.strip()
24+
git_branch = (
25+
subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
26+
.decode("utf-8")
27+
.strip()
28+
)
3029

3130
# -- Project information -----------------------------------------------------
3231

33-
project = 'pystac'
34-
copyright = '2019, Azavea'
35-
author = 'stac-utils'
32+
project = "pystac"
33+
copyright = "2019, Azavea"
34+
author = "stac-utils"
3635

3736
# The short X.Y version
3837
version = __version__
@@ -50,35 +49,41 @@
5049
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
5150
# ones.
5251
extensions = [
53-
'sphinx.ext.autodoc',
54-
'sphinx.ext.viewcode',
55-
'sphinx.ext.intersphinx',
56-
'sphinx.ext.napoleon',
57-
'sphinx.ext.githubpages',
58-
'sphinx.ext.extlinks',
59-
'sphinxcontrib.fulltoc',
60-
'nbsphinx'
52+
"sphinx.ext.autodoc",
53+
"sphinx.ext.viewcode",
54+
"sphinx.ext.intersphinx",
55+
"sphinx.ext.napoleon",
56+
"sphinx.ext.githubpages",
57+
"sphinx.ext.extlinks",
58+
"sphinxcontrib.fulltoc",
59+
"nbsphinx",
6160
]
6261

6362
extlinks = {
64-
'tutorial': ('https://github.com/stac-utils/pystac/'
65-
'tree/{}/docs/tutorials/%s'.format(git_branch), 'tutorial'),
66-
'stac-spec': ('https://github.com/radiantearth/stac-spec/tree/'
67-
'v{}/%s'.format(STACVersion.DEFAULT_STAC_VERSION), 'path'),
68-
'stac-ext': ('https://github.com/stac-extensions/%s', '%s extension')
63+
"tutorial": (
64+
"https://github.com/stac-utils/pystac/"
65+
"tree/{}/docs/tutorials/%s".format(git_branch),
66+
"tutorial",
67+
),
68+
"stac-spec": (
69+
"https://github.com/radiantearth/stac-spec/tree/"
70+
"v{}/%s".format(STACVersion.DEFAULT_STAC_VERSION),
71+
"path",
72+
),
73+
"stac-ext": ("https://github.com/stac-extensions/%s", "%s extension"),
6974
}
7075

7176
# Add any paths that contain templates here, relative to this directory.
72-
templates_path = ['_templates']
77+
templates_path = ["_templates"]
7378

7479
# The suffix(es) of source filenames.
7580
# You can specify multiple suffix as a list of string:
7681
#
7782
# source_suffix = ['.rst', '.md']
78-
source_suffix = '.rst'
83+
source_suffix = ".rst"
7984

8085
# The master toctree document.
81-
master_doc = 'index'
86+
master_doc = "index"
8287

8388
# The language for content autogenerated by Sphinx. Refer to documentation
8489
# for a list of supported languages.
@@ -90,7 +95,7 @@
9095
# List of patterns, relative to source directory, that match files and
9196
# directories to ignore when looking for source files.
9297
# This pattern also affects html_static_path and html_extra_path.
93-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '**.ipynb_checkpoints']
98+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]
9499

95100
# The name of the Pygments (syntax highlighting) style to use.
96101
pygments_style = None
@@ -101,7 +106,7 @@
101106
# The theme to use for HTML and HTML Help pages. See the documentation for
102107
# a list of builtin themes.
103108
#
104-
html_theme = 'alabaster'
109+
html_theme = "alabaster"
105110

106111
# Theme options are theme-specific and customize the look and feel of a theme
107112
# further. For a list of options available for each theme, see the
@@ -119,7 +124,7 @@
119124
# Add any paths that contain custom static files (such as style sheets) here,
120125
# relative to this directory. They are copied after the builtin static files,
121126
# so a file named "default.css" will overwrite the builtin "default.css".
122-
#html_static_path = ['_static']
127+
# html_static_path = ['_static']
123128

124129
# Custom sidebar templates, must be a dictionary that maps document names
125130
# to template names.
@@ -135,7 +140,7 @@
135140
# -- Options for HTMLHelp output ---------------------------------------------
136141

137142
# Output file base name for HTML help builder.
138-
htmlhelp_basename = 'pystacdoc'
143+
htmlhelp_basename = "pystacdoc"
139144

140145

141146
# -- Options for LaTeX output ------------------------------------------------
@@ -144,15 +149,12 @@
144149
# The paper size ('letterpaper' or 'a4paper').
145150
#
146151
# 'papersize': 'letterpaper',
147-
148152
# The font size ('10pt', '11pt' or '12pt').
149153
#
150154
# 'pointsize': '10pt',
151-
152155
# Additional stuff for the LaTeX preamble.
153156
#
154157
# 'preamble': '',
155-
156158
# Latex figure (float) alignment
157159
#
158160
# 'figure_align': 'htbp',
@@ -162,19 +164,15 @@
162164
# (source start file, target name, title,
163165
# author, documentclass [howto, manual, or own class]).
164166
latex_documents = [
165-
(master_doc, 'pystac.tex', 'pystac Documentation',
166-
'stac-utils', 'manual'),
167+
(master_doc, "pystac.tex", "pystac Documentation", "stac-utils", "manual"),
167168
]
168169

169170

170171
# -- Options for manual page output ------------------------------------------
171172

172173
# One entry per manual page. List of tuples
173174
# (source start file, name, description, authors, manual section).
174-
man_pages = [
175-
(master_doc, 'pystac', 'pystac Documentation',
176-
[author], 1)
177-
]
175+
man_pages = [(master_doc, "pystac", "pystac Documentation", [author], 1)]
178176

179177

180178
# -- Options for Texinfo output ----------------------------------------------
@@ -183,9 +181,15 @@
183181
# (source start file, target name, title, author,
184182
# dir menu entry, description, category)
185183
texinfo_documents = [
186-
(master_doc, 'pystac', 'pystac Documentation',
187-
author, 'pystac', 'Python library for SpatioTemporal Asset Catalogs (STAC).',
188-
'Miscellaneous'),
184+
(
185+
master_doc,
186+
"pystac",
187+
"pystac Documentation",
188+
author,
189+
"pystac",
190+
"Python library for SpatioTemporal Asset Catalogs (STAC).",
191+
"Miscellaneous",
192+
),
189193
]
190194

191195

@@ -204,11 +208,11 @@
204208
# epub_uid = ''
205209

206210
# A list of files that should not be packed into the epub file.
207-
epub_exclude_files = ['search.html']
211+
epub_exclude_files = ["search.html"]
208212

209213

210214
# -- Extension configuration -------------------------------------------------
211215

212216
intersphinx_mapping = {
213-
'python': ('https://docs.python.org/3', None),
217+
"python": ("https://docs.python.org/3", None),
214218
}

0 commit comments

Comments
 (0)