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

Set up pre-commit #255

Merged
merged 4 commits into from Apr 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
@@ -0,0 +1,2 @@
# Initial pre-commit reformat
d6a8168b9f6b8a28bba5f7cca3d6a9c31da041b6
64 changes: 32 additions & 32 deletions .github/workflows/codeql-analysis.yml
Expand Up @@ -14,16 +14,16 @@ name: "CodeQL"

on:
push:
branches: [ master ]
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
branches: [master]
schedule:
- cron: '41 6 * * 6'
# Make a pass every Saturday at 06:41 UTC
- cron: "41 6 * * 6"
blink1073 marked this conversation as resolved.
Show resolved Hide resolved

permissions:
security-events:
write
security-events: write

jobs:
analyze:
Expand All @@ -33,41 +33,41 @@ jobs:
strategy:
fail-fast: false
matrix:
language: ['python' ]
language: ["python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
queries: security-and-quality
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
queries: security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
60 changes: 31 additions & 29 deletions .github/workflows/test.yml
Expand Up @@ -5,13 +5,11 @@ name: Python package

on:
push:
branches: '*'
pull_request:
branches: [ master ]
branches: ["master"]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -23,29 +21,33 @@ jobs:
- os: windows-latest
python-version: 3.10-dev
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('dev-requirements.txt', 'setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel
pip install -r dev-requirements.txt .
- name: Test with pytest
run: |
pytest -vv jupyter_core --timeout 60 --cov jupyter_core --cov-report term-missing:skip-covered
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
- name: pip cache
uses: actions/cache@v2
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: |
${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('dev-requirements.txt', 'setup.cfg') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel
pip install -r dev-requirements.txt .
- name: Test with pytest
run: |
pytest -vv jupyter_core --timeout 60 --cov jupyter_core --cov-report term-missing:skip-covered
- name: Check manifest
run: |
pip install check-manifest
check-manifest -v
74 changes: 74 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,74 @@
ci:
skip: [check-jsonschema]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: debug-statements
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- id: check-added-large-files
- id: check-case-conflict
- id: check-toml
- id: check-yaml
- id: forbid-new-submodules
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
hooks:
- id: prettier

- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/doc8
rev: 0.11.1
hooks:
- id: doc8
args: [--max-line-length=200]

# - repo: https://github.com/pycqa/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies:
# [
# "flake8-bugbear==20.1.4",
# "flake8-logging-format==0.6.0",
# "flake8-implicit-str-concat==0.2.0",
# ]

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.942
# hooks:
# - id: mypy

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.14.2
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
8 changes: 4 additions & 4 deletions COPYING.md
Expand Up @@ -24,7 +24,7 @@ software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Expand All @@ -35,7 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## About the Jupyter Development Team

The Jupyter Development Team is the set of all contributors to the Jupyter
project. This includes all of the Jupyter subprojects. A full list with
project. This includes all of the Jupyter subprojects. A full list with
details is kept in the documentation directory, in the file
`about/credits.txt`.

Expand All @@ -48,8 +48,8 @@ Jupyter uses a shared copyright model. Each contributor maintains copyright
over their contributions to Jupyter. It is important to note that these
contributions are typically only changes to the repositories. Thus, the Jupyter
source code in its entirety is not the copyright of any single person or
institution. Instead, it is the collective copyright of the entire Jupyter
Development Team. If individual contributors want to maintain a record of what
institution. Instead, it is the collective copyright of the entire Jupyter
Development Team. If individual contributors want to maintain a record of what
changes/contributions they have specific copyright on, they should indicate
their copyright in the commit message of the change, when they commit the
change to one of the Jupyter repositories.
Expand Down
7 changes: 6 additions & 1 deletion MANIFEST.in
Expand Up @@ -3,6 +3,10 @@ include CONTRIBUTING.md
include README.md
include dev-requirements.txt

exclude .pre-commit-config.yaml
exclude .git-blame-ignore-revs
exclude readthedocs.yml

# Documentation
graft docs
graft examples
Expand All @@ -11,7 +15,8 @@ graft examples
graft jupyter_core/tests/dotipython
graft jupyter_core/tests/dotipython_empty

# docs subdirs we want to skip
# dirs we want to skip
prune scripts
prune docs/_build

# Patterns to exclude from any directory
Expand Down
36 changes: 33 additions & 3 deletions README.md
Expand Up @@ -5,7 +5,6 @@ Core common functionality of Jupyter projects.
This package contains base application classes and configuration inherited by other projects.
It doesn't do much on its own.


# Development Setup

The [Jupyter Contributor Guides](http://jupyter.readthedocs.io/en/latest/contributor/content-contributor.html) provide extensive information on contributing code or documentation to Jupyter projects. The limited instructions below for setting up a development environment are for your convenience.
Expand All @@ -23,6 +22,38 @@ and download the dependencies of code and test suite by executing:

The last command runs the test suite to verify the setup. During development, you can pass filenames to `py.test`, and it will execute only those tests.

## Code Styling

`jupyter_core` has adopted automatic code formatting so you shouldn't
need to worry too much about your code style.
As long as your code is valid,
the pre-commit hook should take care of how it should look.
`pre-commit` and its associated hooks will automatically be installed when
you run `pip install -e ".[test]"`

To install `pre-commit` manually, run the following:

```bash
pip install pre-commit
pre-commit install
```

You can invoke the pre-commit hook by hand at any time with:

```bash
pre-commit run
```

which should run any autoformatting on your code
and tell you about any errors it couldn't fix automatically.
You may also install [black integration](https://github.com/psf/black#editor-integration)
into your text editor to format code automatically.

If you have already committed files before setting up the pre-commit
hook with `pre-commit install`, you can fix everything up using
`pre-commit run --all-files`. You need to make the fixing commit
yourself after that.

## Documentation

The documentation of Jupyter Core is generated from the files in `docs/` using Sphinx. Instructions for setting up Sphinx with a selection of optional modules are in the [Documentation Guide](http://jupyter.readthedocs.io/en/latest/contrib_docs/index.html). You'll also need the `make` command.
Expand All @@ -37,5 +68,4 @@ The following commands build the documentation in HTML format and check for brok

Point your browser to the following URL to access the generated documentation:

_file:///my/projects/jupyter\_core/docs/\_build/html/index.html_

_file:///my/projects/jupyter_core/docs/\_build/html/index.html_
1 change: 1 addition & 0 deletions dev-requirements.txt
@@ -1,4 +1,5 @@
ipykernel
pre-commit
pytest
pytest-cov
pytest-timeout
19 changes: 16 additions & 3 deletions docs/changelog.rst
Expand Up @@ -33,7 +33,11 @@ See the `jupyter_core
4.9 <https://github.com/jupyter/jupyter_core/milestone/21?closed=1>`__
milestone on GitHub for the full list of pull requests and issues closed.

- Add Python site user base subdirectories to config and data user-level paths if ``site.ENABLE_USER_SITE`` is True. One way to disable these directory additions is to set the ``PYTHONNOUSERSITE`` environment variable. These locations can be customized by setting the ``PYTHONUSERBASE`` environment variable. (:ghpull:`242`)
- Add Python site user base subdirectories to config and data user-level paths
if ``site.ENABLE_USER_SITE`` is True. One way to disable these directory
additions is to set the ``PYTHONNOUSERSITE`` environment variable. These
locations can be customized by setting the ``PYTHONUSERBASE`` environment
variable. (:ghpull:`242`)


4.8
Expand All @@ -44,7 +48,10 @@ milestone on GitHub for the full list of pull requests and issues closed.
`on
GitHub <https://github.com/jupyter/jupyter_core/releases/tag/4.8.2>`__

jupyter_core 4.8.1 was released the same day as 4.8.0 and also included the fix below for the Windows tests. Unfortunately, the 4.8.1 release commit and tag were not pushed to GitHub. We are releasing 4.8.2 so we have a commit and tag in version control.
jupyter_core 4.8.1 was released the same day as 4.8.0 and also included the fix
below for the Windows tests. Unfortunately, the 4.8.1 release commit and tag
were not pushed to GitHub. We are releasing 4.8.2 so we have a commit and tag
in version control.

- Fix windows test regression (:ghpull:`240`)

Expand Down Expand Up @@ -89,7 +96,13 @@ See the `jupyter_core
4.7 <https://github.com/jupyter/jupyter_core/milestone/19?closed=1>`__
milestone on GitHub for the full list of pull requests and issues closed.

- Add a new ``JUPYTER_PREFER_ENV_PATH`` variable, which can be set to switch the order of the environment-level path and the user-level path in the Jupyter path hierarchy (e.g., ``jupyter --paths``). It is considered set if it is a value that is not one of 'no', 'n', 'off', 'false', '0', or '0.0' (case insensitive). If you are running Jupyter in multiple virtual environments as the same user, you will likely want to set this environment variable.
- Add a new ``JUPYTER_PREFER_ENV_PATH`` variable, which can be set to switch
the order of the environment-level path and the user-level path in the
Jupyter path hierarchy (e.g., ``jupyter --paths``). It is considered set if
it is a value that is not one of 'no', 'n', 'off', 'false', '0', or '0.0'
(case insensitive). If you are running Jupyter in multiple virtual
environments as the same user, you will likely want to set this environment
variable.
- Drop Python 2.x and 3.5 support, as they have reached end of life.
- Add Python 3.9 builds to testing, and expand testing to cover Windows, macOS, and Linux platforms.
- ``jupyter --paths --debug`` now explains the environment variables that affect the current path list.
Expand Down