Skip to content

Commit c994803

Browse files
committed
Black, linters and pre-commit. Fix all the things!
1 parent 6833d2c commit c994803

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2659
-1922
lines changed

.github/workflows/pythonpackage.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ jobs:
5656
- uses: actions/cache@v2
5757
with:
5858
path: ~/.cache/pip
59-
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements-linters.txt') }}
59+
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-linters.txt') }}
6060
- name: Install deps
6161
run: |
6262
python -m pip install --upgrade pip
63-
pip install -r tests/requirements-linters.txt
63+
pip install -r requirements-linters.txt
6464
- name: Run isort
6565
run: |
6666
isort --version

.pre-commit-config.yaml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
repos:
2+
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- repo: 'https://gitlab.com/pycqa/flake8'
8+
rev: 4.0.1
9+
hooks:
10+
- id: flake8
11+
- repo: 'https://github.com/pre-commit/mirrors-isort'
12+
rev: v5.10.1
13+
hooks:
14+
- id: isort
15+
- repo: 'https://github.com/mgedmin/check-manifest'
16+
rev: '0.46'
17+
hooks:
18+
- id: check-manifest
19+
- repo: 'https://github.com/myint/autoflake'
20+
rev: v1.4
21+
hooks:
22+
- id: autoflake
23+
args:
24+
- '--remove-all-unused-imports'
25+
- '-i'
26+
language_version: python3.9
27+
- repo: 'https://github.com/pre-commit/mirrors-autopep8'
28+
rev: v1.5.7
29+
hooks:
30+
- id: autopep8
31+
language_version: python3.9
32+
- repo: https://github.com/psf/black
33+
rev: 22.3.0
34+
hooks:
35+
- id: black
36+
language_version: python3.9
37+
- repo: https://github.com/ikamensh/flynt/
38+
rev: '0.76'
39+
hooks:
40+
- id: flynt
41+
language_version: python3.9
42+
- repo: https://github.com/asottile/pyupgrade
43+
rev: v2.31.1
44+
hooks:
45+
- id: pyupgrade
46+
entry: pyupgrade --py3-plus --py36-plus --keep-runtime-typing
47+
language_version: python3.9

CONTRIBUTING.rst

+15
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ To contribute fixes and features, you'll need to get set up for development:
3131

3232
If all that is successful, you are in good shape to start developing!
3333

34+
We also have several linters and code formatters that we require use of,
35+
including `flake8 <http://flake8.pycqa.org/en/latest/>`_, `isort
36+
<https://github.com/timothycrosley/isort#readme>`_ and `black
37+
<https://github.com/psf/black>`_. These are most easily add by using `pre-commit
38+
<https://pre-commit.com/>`_:
39+
40+
* Install pre-commit globally e.g. ``pipx install pre-commit`` if you already
41+
have `pipx <https://github.com/pypa/pipx>`_.
42+
43+
* Do ``pre-commit install`` in the repo.
44+
45+
Now all the linters will run when you commit changes.
46+
47+
To run tests on multiple Python versions locally you can also install and use
48+
``tox``.
3449

3550

3651
Fixes and features

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fluent-compiler
88
:target: https://fluent-compiler.readthedocs.io
99

1010
.. image:: https://github.com/django-ftl/fluent-compiler/workflows/Python%20package/badge.svg
11-
:target: https://github.com/django-ftl/fluent-compiler/actions?query=workflow%3A%22Python+package%22
11+
:target: https://github.com/django-ftl/fluent-compiler/actions?query=workflow%3A%22Python+package%22
1212

1313
This is a Python implementation of `Project Fluent <https://www.projectfluent.org/>`_, a localization
1414
framework designed to unleash the entire expressive power of natural
@@ -77,5 +77,5 @@ master branch. It has now been pulled out as a separate package. This is why
7777
the repo's history contains `fluent.syntax` and early versions of `fluent.runtime`,
7878
but the parts that are left in this repo all derive from the original version
7979
of `fluent.runtime` contributed by @spookylukey from `a540993a085e36a9679e12f1ee7317ddc1ece5ad <https://github.com/django-ftl/fluent-compiler/commit/a540993a085e36a9679e12f1ee7317ddc1ece5ad>`_ onwards and the new compiler implementation in `d1481d61e0bc1a28a228a4b6d5258350d436e765 <https://github.com/django-ftl/fluent-compiler/commit/d1481d61e0bc1a28a228a4b6d5258350d436e765>`_ (which is squashed version of work done over a much longer period). Thats why
80-
we also `corrected <https://github.com/django-ftl/fluent-compiler/commit/33c1b5b586858132d3ab7af749c2bde1bb5205b5>`_
80+
we also `corrected <https://github.com/django-ftl/fluent-compiler/commit/33c1b5b586858132d3ab7af749c2bde1bb5205b5>`_
8181
the copyright notice from Mozilla to Luke Plant.

docs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ help:
1616
# Catch-all target: route all unknown targets to Sphinx using the new
1717
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1818
%: Makefile
19-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/api/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ API documentation
88
bundle
99
compiler
1010
resource
11-

docs/conf.py

+34-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# Configuration file for the Sphinx documentation builder.
43
#
@@ -15,19 +14,19 @@
1514
import os
1615
import sys
1716

18-
sys.path.insert(0, os.path.abspath('..'))
17+
sys.path.insert(0, os.path.abspath(".."))
1918

2019

2120
# -- Project information -----------------------------------------------------
2221

23-
project = 'fluent_compiler'
24-
copyright = '2019, Luke Plant'
25-
author = 'Luke Plant'
22+
project = "fluent_compiler"
23+
copyright = "2019, Luke Plant"
24+
author = "Luke Plant"
2625

2726
# The short X.Y version
28-
version = '0.3'
27+
version = "0.3"
2928
# The full version, including alpha/beta/rc tags
30-
release = '0.3'
29+
release = "0.3"
3130

3231

3332
# -- General configuration ---------------------------------------------------
@@ -40,21 +39,21 @@
4039
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4140
# ones.
4241
extensions = [
43-
'sphinx.ext.intersphinx',
44-
'sphinx.ext.viewcode',
42+
"sphinx.ext.intersphinx",
43+
"sphinx.ext.viewcode",
4544
]
4645

4746
# Add any paths that contain templates here, relative to this directory.
48-
templates_path = ['_templates']
47+
templates_path = ["_templates"]
4948

5049
# The suffix(es) of source filenames.
5150
# You can specify multiple suffix as a list of string:
5251
#
5352
# source_suffix = ['.rst', '.md']
54-
source_suffix = '.rst'
53+
source_suffix = ".rst"
5554

5655
# The master toctree document.
57-
master_doc = 'index'
56+
master_doc = "index"
5857

5958
# The language for content autogenerated by Sphinx. Refer to documentation
6059
# for a list of supported languages.
@@ -66,7 +65,7 @@
6665
# List of patterns, relative to source directory, that match files and
6766
# directories to ignore when looking for source files.
6867
# This pattern also affects html_static_path and html_extra_path.
69-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
68+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7069

7170
# The name of the Pygments (syntax highlighting) style to use.
7271
pygments_style = None
@@ -77,7 +76,7 @@
7776
# The theme to use for HTML and HTML Help pages. See the documentation for
7877
# a list of builtin themes.
7978
#
80-
html_theme = 'default'
79+
html_theme = "default"
8180

8281
# Theme options are theme-specific and customize the look and feel of a theme
8382
# further. For a list of options available for each theme, see the
@@ -88,7 +87,7 @@
8887
# Add any paths that contain custom static files (such as style sheets) here,
8988
# relative to this directory. They are copied after the builtin static files,
9089
# so a file named "default.css" will overwrite the builtin "default.css".
91-
html_static_path = ['_static']
90+
html_static_path = ["_static"]
9291

9392
# Custom sidebar templates, must be a dictionary that maps document names
9493
# to template names.
@@ -104,7 +103,7 @@
104103
# -- Options for HTMLHelp output ---------------------------------------------
105104

106105
# Output file base name for HTML help builder.
107-
htmlhelp_basename = 'fluentcompilerdoc'
106+
htmlhelp_basename = "fluentcompilerdoc"
108107

109108

110109
# -- Options for LaTeX output ------------------------------------------------
@@ -113,15 +112,12 @@
113112
# The paper size ('letterpaper' or 'a4paper').
114113
#
115114
# 'papersize': 'letterpaper',
116-
117115
# The font size ('10pt', '11pt' or '12pt').
118116
#
119117
# 'pointsize': '10pt',
120-
121118
# Additional stuff for the LaTeX preamble.
122119
#
123120
# 'preamble': '',
124-
125121
# Latex figure (float) alignment
126122
#
127123
# 'figure_align': 'htbp',
@@ -131,19 +127,21 @@
131127
# (source start file, target name, title,
132128
# author, documentclass [howto, manual, or own class]).
133129
latex_documents = [
134-
(master_doc, 'fluentcompiler.tex', 'fluent_compiler Documentation',
135-
'Luke Plant', 'manual'),
130+
(
131+
master_doc,
132+
"fluentcompiler.tex",
133+
"fluent_compiler Documentation",
134+
"Luke Plant",
135+
"manual",
136+
),
136137
]
137138

138139

139140
# -- Options for manual page output ------------------------------------------
140141

141142
# One entry per manual page. List of tuples
142143
# (source start file, name, description, authors, manual section).
143-
man_pages = [
144-
(master_doc, 'fluentcompiler', 'fluent_compiler Documentation',
145-
[author], 1)
146-
]
144+
man_pages = [(master_doc, "fluentcompiler", "fluent_compiler Documentation", [author], 1)]
147145

148146

149147
# -- Options for Texinfo output ----------------------------------------------
@@ -152,9 +150,15 @@
152150
# (source start file, target name, title, author,
153151
# dir menu entry, description, category)
154152
texinfo_documents = [
155-
(master_doc, 'fluentcompiler', 'fluent_compiler Documentation',
156-
author, 'fluentcompiler', 'One line description of project.',
157-
'Miscellaneous'),
153+
(
154+
master_doc,
155+
"fluentcompiler",
156+
"fluent_compiler Documentation",
157+
author,
158+
"fluentcompiler",
159+
"One line description of project.",
160+
"Miscellaneous",
161+
),
158162
]
159163

160164

@@ -173,12 +177,12 @@
173177
# epub_uid = ''
174178

175179
# A list of files that should not be packed into the epub file.
176-
epub_exclude_files = ['search.html']
180+
epub_exclude_files = ["search.html"]
177181

178182

179183
# -- Extension configuration -------------------------------------------------
180184

181185
# -- Options for intersphinx extension ---------------------------------------
182186

183187
# Example configuration for intersphinx: refer to the Python standard library.
184-
intersphinx_mapping = {'python': ('https://docs.python.org/3', None)}
188+
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}

pyproject.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tool.black]
2+
line-length = 120
3+
# required-version = '22.3.0' # see https://github.com/psf/black/issues/2493
4+
target-version = ['py39']
5+
6+
[tool.isort]
7+
profile = "black"
8+
line_length = 120
9+
known_first_party = ["fluent_compiler"]
10+
default_section= "THIRDPARTY"
11+
skip = [".tox", "dist", "build", ".git"]

requirements-linters.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
isort==5.10.1
2+
flake8==4.0.1
3+
check-manifest

requirements-test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ hypothesis>=4.9.0
44
Markdown>=3.0.1
55
MarkupSafe>=1.1.1
66
pytest
7+
six

setup.cfg

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,5 @@
22

33
[flake8]
44
exclude=.tox,build,.eggs
5-
ignore=D100,D101,W504
5+
ignore=D100,D101,W504,W503
66
max-line-length=120
7-
8-
[isort]
9-
line_length=120
10-
skip_glob=.tox
11-
known_first_party=fluent_compiler

setup.py

+33-32
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
#!/usr/bin/env python
22
from setuptools import find_packages, setup
33

4-
setup(name='fluent_compiler',
5-
version='0.3',
6-
description='Blazing fast implementation of Fluent localization language.',
7-
long_description=open('README.rst').read() +
8-
'\n\nSee https://github.com/django-ftl/fluent-compiler/ for more info.',
9-
long_description_content_type='text/x-rst',
10-
author='Luke Plant',
11-
author_email='[email protected]',
12-
license='APL 2',
13-
url='https://github.com/django-ftl/fluent-compiler',
14-
keywords=['fluent', 'localization', 'l10n', 'compiler'],
15-
classifiers=[
16-
'Development Status :: 4 - Beta',
17-
'Intended Audience :: Developers',
18-
'License :: OSI Approved :: Apache Software License',
19-
'Programming Language :: Python :: 3.6',
20-
'Programming Language :: Python :: 3.7',
21-
'Programming Language :: Python :: 3.8',
22-
'Programming Language :: Python :: 3.9',
23-
'Programming Language :: Python :: 3.10',
24-
'Programming Language :: Python :: 3.11',
25-
],
26-
packages=find_packages('src'),
27-
package_dir={'': 'src'},
28-
# These should also be duplicated in tox.ini and ../.travis.yml
29-
install_requires=[
30-
'fluent.syntax>=0.14',
31-
'attrs>=19.3.0',
32-
'babel>=2.8.0',
33-
'pytz',
34-
],
35-
)
4+
setup(
5+
name="fluent_compiler",
6+
version="0.3",
7+
description="Blazing fast implementation of Fluent localization language.",
8+
long_description=open("README.rst").read()
9+
+ "\n\nSee https://github.com/django-ftl/fluent-compiler/ for more info.",
10+
long_description_content_type="text/x-rst",
11+
author="Luke Plant",
12+
author_email="[email protected]",
13+
license="APL 2",
14+
url="https://github.com/django-ftl/fluent-compiler",
15+
keywords=["fluent", "localization", "l10n", "compiler"],
16+
classifiers=[
17+
"Development Status :: 4 - Beta",
18+
"Intended Audience :: Developers",
19+
"License :: OSI Approved :: Apache Software License",
20+
"Programming Language :: Python :: 3.6",
21+
"Programming Language :: Python :: 3.7",
22+
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Programming Language :: Python :: 3.11",
26+
],
27+
packages=find_packages("src"),
28+
package_dir={"": "src"},
29+
# These should also be duplicated in tox.ini and ../.travis.yml
30+
install_requires=[
31+
"fluent.syntax>=0.14",
32+
"attrs>=19.3.0",
33+
"babel>=2.8.0",
34+
"pytz",
35+
],
36+
)

src/fluent_compiler/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from __future__ import absolute_import, unicode_literals

0 commit comments

Comments
 (0)