Skip to content

Commit

Permalink
🚨 Apply automatic formatting (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Feb 29, 2024
1 parent 3aa3f7c commit 53843c0
Show file tree
Hide file tree
Showing 62 changed files with 555 additions and 669 deletions.
12 changes: 6 additions & 6 deletions .docstr.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
skip_magic: True
skip_file_doc: True
skip_init: True
skip_private: True
ignore_setter: True
fail-under: 100
skip_magic: true
skip_file_doc: true
skip_init: true
skip_private: true
ignore_setter: true
fail-under: 100
14 changes: 7 additions & 7 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ "main", "v1" ]
branches: ["main", "v1"]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main", "v1" ]
branches: ["main", "v1"]
schedule:
- cron: '25 22 * * 1'
- cron: '25 22 * * 1'

jobs:
analyze:
Expand All @@ -32,7 +32,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: ['python']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

Expand All @@ -48,11 +48,11 @@ jobs:
# 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.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,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
Expand All @@ -61,7 +61,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
48 changes: 15 additions & 33 deletions .github/workflows/linting_and_unittests.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
name: "Linting and unittests"
name: "unittests"

on:
push:
paths:
- '**.py'
- '**.py'
pull_request:
branches: ["main"]

jobs:
lint:
runs-on: ubuntu-latest
container:
image: python:3.8

steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[lint]
- name: Lint format with `black`
run: black bibtexparser tests setup.py --check
- name: Lint imports with `isort`
run: isort bibtexparser tests setup.py --check-only --profile black
- name: Check docstr-coverage with `docstr-coverage`
run: docstr-coverage bibtexparser

build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
- name: Test with pytest
run: |
pytest tests
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test]
- name: Test with pytest
run: |
pytest tests
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: pre-commit

on:
workflow_dispatch:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-python@main
with:
python-version: '<3.12' # https://github.com/HunterMcGushion/docstr_coverage/issues/137
- uses: pre-commit/action@main
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
Expand All @@ -37,7 +37,7 @@ jobs:
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
61 changes: 61 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: debug-statements
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-yaml
args: [--preserve-quotes, --autofix, --indent, '2']
- id: pretty-format-toml
args: [--autofix, --indent, '4', --trailing-commas]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-no-log-warn
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
args: [--safe, --quiet, --line-length=100]
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.0
hooks:
- id: autoflake
args: [--in-place, --remove-unused-variable]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort
args: ["--force-single-line", "--line-length=100", "--profile=black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: ["--ignore=E722,W503,E203", --max-line-length=110, "--per-file-ignores=*/__init__.py:F401"]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/HunterMcGushion/docstr_coverage
rev: v2.3.0
hooks:
- id: docstr-coverage
args: ["bibtexparser"]
13 changes: 7 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Contributing
## Contributing

Thanks heaps for being interested in contributing to python-bibtexparser.

Expand All @@ -8,15 +8,16 @@ We are always looking for people to improve the library. Contributions include,
2. Providing bugfixing PRs
3. Implementing any of the issues or continuing any of the PRs labelled with `needs help` or `good first issue`.

### Some guidelines:
### Some guidelines

1. Be nice! Were all doing this in our free time; no one is obligated to do anything.
2. Add sufficient tests to your PRs
2. Add sufficient tests to your PRs.
3. Document your code.
4. Don't hesitate to ask questions.

### Version 1 vs version 2
Also note that there are currently two independent "default" branches:

Also note that there are currently two independent "default" branches:
First, `main`, where we maintain the `v2` of bibtexparser, which is a complete re-write and currently still in beta and not feature complete.
Second, `v1` where we maintain the stable `v1` version of bibtexparser. Note that on `v1` we accept only small, non-breaking changes and are planning to stop support as soon as `v2` reaches reasonable stability.
The two branches are never going to be merged anymore, thus if you want to change something for both versions, you will have to open two PRs.
Expand All @@ -25,8 +26,8 @@ Issues are labelled `v1` and `v2`, correspondingly.

### Dev-Dependencies, testing and linting on v2.

To install the dev dependencies, run `pip install -e .[test,lint,docs]` from within the cloned repository. Then:
To install the dev dependencies, run `pip install -e .[test,docs]` from within the cloned repository. Then:

- To test your code, run `pytest .`
- To lint your code (required for CI/CD to pass), run: `black bibtexparser tests docs && isort bibtexparser tests docs --profile black`
- To lint your code (enforces code style), run: `pre-commit run --all-files` (if you need to install pre-commit, run `pip install pre-commit`).
- To build and preview the docs, navigate into `docs` and run `make html`. Then open the `index.html` file in the `docs/build/html` folder.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ If instead, you want to use v1, install it using:
pip install bibtexparser~=1.0
```

Note that all development and maintenance effort is focussed on v2.
Note that all development and maintenance effort is focussed on v2.
Small PRs for v1 are still accepted, but only as long as they are backwards compatible and don't introduce much additional technical debt.
Development of version one happens on the dedicated [v1 branch](https://github.com/sciunto-org/python-bibtexparser/tree/v1).
Development of version one happens on the dedicated [v1 branch](https://github.com/sciunto-org/python-bibtexparser/tree/v1).

The remainder of this README is specific to v2.
The remainder of this README is specific to v2.

## Documentation
Go check out our documentation on [https://bibtexparser.readthedocs.io/en/main/](https://bibtexparser.readthedocs.io/en/main/).
Expand Down Expand Up @@ -66,7 +66,7 @@ new_bibtex_string = bibtexparser.write_string(bib_database,
)
```

These examples really only show the bare minimum.
These examples really only show the bare minimum.
Consult the documentation for a list of available middleware, parsing options and write-formatting options.

## V2 Architecture and Terminology
Expand All @@ -76,21 +76,21 @@ Consult the documentation for a list of available middleware, parsing options an
The architecture consists of the following components:

#### Library
Reflects the contents of a parsed bibtex files, including all comments, entries, strings, preamples and their metadata (e.g. order).
Reflects the contents of a parsed bibtex files, including all comments, entries, strings, preamples and their metadata (e.g. order).

#### A Splitter
Splits a bibtex string into basic blocks (Entry, String, Preamble, ...), with correspondingly split content (e.g. fields on Entry, key-value on String, ...).
The splitter aims to be forgiving when facing invalid bibtex: A line starting with a block definition (`@....`) ends the previous block, even if not yet every bracket is closed, failing the parsing of the previous block. Correspondingly, one block type is "ParsingFailedBlock".
The splitter aims to be forgiving when facing invalid bibtex: A line starting with a block definition (``@....``) ends the previous block, even if not yet every bracket is closed, failing the parsing of the previous block. Correspondingly, one block type is "ParsingFailedBlock".

#### Middleware
Middleware layers transform a library and its blocks, for example by decoding latex special characters, interpolating string references, resoling crossreferences or re-ordering blocks. Thus, the choice of middleware allows to customize parsing and writing to ones specific usecase. Note: Middlewares, by default, no not mutate their input, but return a modified copy.
Middleware layers transform a library and its blocks, for example by decoding latex special characters, interpolating string references, resoling crossreferences or re-ordering blocks. Thus, the choice of middleware allows to customize parsing and writing to ones specific usecase. Note: Middlewares, by default, no not mutate their input, but return a modified copy.

#### Writer
Writes the content of a bibtex library to a `.bib` file. Optional formatting parameters can be passed using a corresponding dedicated data structure.
Writes the content of a bibtex library to a ``.bib`` file. Optional formatting parameters can be passed using a corresponding dedicated data structure.

## About

Since 2022, `bibtexparser` is primarily written and maintained by Michael Weiss ([@MiWeiss](https://github.com/MiWeiss/)). In 2024, Tom de Geus ([@tdegeus](https://github.com/tdegeus)) joined as co-maintainer.
Since 2022, `bibtexparser` is primarily written and maintained by Michael Weiss ([@MiWeiss](https://github.com/MiWeiss/)). In 2024, Tom de Geus ([@tdegeus](https://github.com/tdegeus)) joined as co-maintainer.

Credits and thanks to the many contributors who helped creating this library, including
François Boulogne ([@sciunto](https://github.com/sciunto/), creator of the first version) and Olivier Mangin ([@omangin](https://github.com/omangin/), long-term contributor).
3 changes: 1 addition & 2 deletions RELEASE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Tagged version are automatically released to pypi using github actions.
Tagged version are automatically released to pypi using github actions.

Oder/Manual release instructions:

Expand All @@ -17,4 +17,3 @@ Oder/Manual release instructions:
twine upload dist/*
* Create release on Github
* Verify docs are automatically updated

5 changes: 4 additions & 1 deletion bibtexparser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import bibtexparser.exceptions
import bibtexparser.middlewares
import bibtexparser.model
from bibtexparser.entrypoint import parse_file, parse_string, write_file, write_string
from bibtexparser.entrypoint import parse_file
from bibtexparser.entrypoint import parse_string
from bibtexparser.entrypoint import write_file
from bibtexparser.entrypoint import write_string
from bibtexparser.library import Library
from bibtexparser.writer import BibtexFormat

Expand Down
16 changes: 11 additions & 5 deletions bibtexparser/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import warnings
from typing import Iterable, List, Optional, TextIO, Union
from typing import Iterable
from typing import List
from typing import Optional
from typing import TextIO
from typing import Union

from .library import Library
from .middlewares.middleware import Middleware
from .middlewares.parsestack import default_parse_stack, default_unparse_stack
from .middlewares.parsestack import default_parse_stack
from .middlewares.parsestack import default_unparse_stack
from .splitter import Splitter
from .writer import BibtexFormat, write
from .writer import BibtexFormat
from .writer import write


def _build_parse_stack(
Expand All @@ -27,7 +33,7 @@ def _build_parse_stack(
return list(parse_stack)

parse_stack_types = [type(m) for m in parse_stack]
append_stack_types = set([type(m) for m in append_middleware])
append_stack_types = {type(m) for m in append_middleware}
stack_types_intersect = set(parse_stack_types).intersection(append_stack_types)
if len(stack_types_intersect) > 0:
warnings.warn(
Expand Down Expand Up @@ -57,7 +63,7 @@ def _build_unparse_stack(
return list(unparse_stack)

parse_stack_types = [type(m) for m in unparse_stack]
append_stack_types = set([type(m) for m in prepend_middleware])
append_stack_types = {type(m) for m in prepend_middleware}
stack_types_intersect = set(parse_stack_types).intersection(append_stack_types)
if len(stack_types_intersect) > 0:
warnings.warn(
Expand Down
3 changes: 2 additions & 1 deletion bibtexparser/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List, Optional
from typing import List
from typing import Optional


class ParsingException(Exception):
Expand Down
Loading

0 comments on commit 53843c0

Please sign in to comment.