Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Black to pre-commit #361

Merged
merged 4 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .flake8

This file was deleted.

10 changes: 9 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.10
python: python3.7
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
Expand All @@ -16,6 +16,14 @@ repos:
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.3
hooks:
- id: pyupgrade
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.0
hooks:
Expand Down
87 changes: 44 additions & 43 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
on_rtd = os.environ.get("READTHEDOCS", None) == "True"

# -*- coding: utf-8 -*-
#
Expand Down Expand Up @@ -34,46 +34,46 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
]
if not on_rtd:
extensions += [
'sphinx.ext.githubpages',
"sphinx.ext.githubpages",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The encoding of source files.
#
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'Graphene Django'
copyright = u'Graphene 2016'
author = u'Syrus Akbary'
project = "Graphene Django"
copyright = "Graphene 2016"
author = "Syrus Akbary"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'1.0'
version = "1.0"
# The full version, including alpha/beta/rc tags.
release = u'1.0.dev'
release = "1.0.dev"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -94,7 +94,7 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The reST default role (used for this markup: `text`) to use for all
# documents.
Expand All @@ -116,7 +116,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand Down Expand Up @@ -175,7 +175,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -255,34 +255,30 @@
# html_search_scorer = 'scorer.js'

# Output file base name for HTML help builder.
htmlhelp_basename = 'Graphenedoc'
htmlhelp_basename = "Graphenedoc"

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Graphene.tex', u'Graphene Documentation',
u'Syrus Akbary', 'manual'),
(master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -323,8 +319,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'graphene_django', u'Graphene Django Documentation',
[author], 1)
(master_doc, "graphene_django", "Graphene Django Documentation", [author], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -338,9 +333,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Graphene-Django', u'Graphene Django Documentation',
author, 'Graphene Django', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"Graphene-Django",
"Graphene Django Documentation",
author,
"Graphene Django",
"One line description of project.",
"Miscellaneous",
),
]

# Documents to append as an appendix to all manuals.
Expand Down Expand Up @@ -414,7 +415,7 @@
# epub_post_files = []

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']
epub_exclude_files = ["search.html"]

# The depth of the table of contents in toc.ncx.
#
Expand Down Expand Up @@ -446,4 +447,4 @@


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}
23 changes: 12 additions & 11 deletions examples/flask_sqlalchemy/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker

engine = create_engine('sqlite:///database.sqlite3', convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
engine = create_engine("sqlite:///database.sqlite3", convert_unicode=True)
db_session = scoped_session(
sessionmaker(autocommit=False, autoflush=False, bind=engine)
)
Base = declarative_base()
Base.query = db_session.query_property()

Expand All @@ -15,24 +15,25 @@ def init_db():
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
from models import Department, Employee, Role

Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

# Create the fixtures
engineering = Department(name='Engineering')
engineering = Department(name="Engineering")
db_session.add(engineering)
hr = Department(name='Human Resources')
hr = Department(name="Human Resources")
db_session.add(hr)

manager = Role(name='manager')
manager = Role(name="manager")
db_session.add(manager)
engineer = Role(name='engineer')
engineer = Role(name="engineer")
db_session.add(engineer)

peter = Employee(name='Peter', department=engineering, role=engineer)
peter = Employee(name="Peter", department=engineering, role=engineer)
db_session.add(peter)
roy = Employee(name='Roy', department=engineering, role=engineer)
roy = Employee(name="Roy", department=engineering, role=engineer)
db_session.add(roy)
tracy = Employee(name='Tracy', department=hr, role=manager)
tracy = Employee(name="Tracy", department=hr, role=manager)
db_session.add(tracy)
db_session.commit()
22 changes: 9 additions & 13 deletions examples/flask_sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,31 @@


class Department(Base):
__tablename__ = 'department'
__tablename__ = "department"
id = Column(Integer, primary_key=True)
name = Column(String)


class Role(Base):
__tablename__ = 'roles'
__tablename__ = "roles"
role_id = Column(Integer, primary_key=True)
name = Column(String)


class Employee(Base):
__tablename__ = 'employee'
__tablename__ = "employee"
id = Column(Integer, primary_key=True)
name = Column(String)
# Use default=func.now() to set the default hiring time
# of an Employee to be the current time when an
# Employee record was created
hired_on = Column(DateTime, default=func.now())
department_id = Column(Integer, ForeignKey('department.id'))
role_id = Column(Integer, ForeignKey('roles.role_id'))
department_id = Column(Integer, ForeignKey("department.id"))
role_id = Column(Integer, ForeignKey("roles.role_id"))
# Use cascade='delete,all' to propagate the deletion of a Department onto its Employees
department = relationship(
Department,
backref=backref('employees',
uselist=True,
cascade='delete,all'))
Department, backref=backref("employees", uselist=True, cascade="delete,all")
)
role = relationship(
Role,
backref=backref('roles',
uselist=True,
cascade='delete,all'))
Role, backref=backref("roles", uselist=True, cascade="delete,all")
)
9 changes: 5 additions & 4 deletions examples/flask_sqlalchemy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@
class Department(SQLAlchemyObjectType):
class Meta:
model = DepartmentModel
interfaces = (relay.Node, )
interfaces = (relay.Node,)


class Employee(SQLAlchemyObjectType):
class Meta:
model = EmployeeModel
interfaces = (relay.Node, )
interfaces = (relay.Node,)


class Role(SQLAlchemyObjectType):
class Meta:
model = RoleModel
interfaces = (relay.Node, )
interfaces = (relay.Node,)


class Query(graphene.ObjectType):
node = relay.Node.Field()
# Allow only single column sorting
all_employees = SQLAlchemyConnectionField(
Employee.connection, sort=Employee.sort_argument())
Employee.connection, sort=Employee.sort_argument()
)
# Allows sorting over multiple columns, by default over the primary key
all_roles = SQLAlchemyConnectionField(Role.connection)
# Disable sorting over this field
Expand Down
Loading