Spaces:
Configuration error
Configuration error
Add python, markdown and github action linter (#5)
Browse filesto ensure the code maintenance. Thanks to docling
project- took some good bits around python linting
from the project.
These checks are also added in the markdown, so that
user can run these checks locally to recreate the
errors.
Signed-off-by: Anil Vishnoi <[email protected]>
- .github/actions/setup-poetry/action.yml +19 -0
- .github/workflows/actionlint.yml +23 -0
- .github/workflows/checks.yml +34 -0
- .gitignore +1 -0
- .markdownlint-cli2.yaml +6 -0
- CODE_OF_CONDUCT.md +2 -2
- CONTRIBUTING.md +12 -16
- Makefile +24 -2
- README.md +0 -1
.github/actions/setup-poetry/action.yml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: 'Set up Poetry and install'
|
2 |
+
description: 'Set up a specific version of Poetry and install dependencies using caching.'
|
3 |
+
inputs:
|
4 |
+
python-version:
|
5 |
+
description: "Version range or exact version of Python or PyPy to use, using SemVer's version range syntax."
|
6 |
+
default: '3.11'
|
7 |
+
runs:
|
8 |
+
using: 'composite'
|
9 |
+
steps:
|
10 |
+
- name: Install poetry
|
11 |
+
run: pipx install poetry==1.8.3
|
12 |
+
shell: bash
|
13 |
+
- uses: actions/setup-python@v4
|
14 |
+
with:
|
15 |
+
python-version: ${{ inputs.python-version }}
|
16 |
+
cache: 'poetry'
|
17 |
+
- name: Install dependencies
|
18 |
+
run: poetry install --all-extras
|
19 |
+
shell: bash
|
.github/workflows/actionlint.yml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Lint GitHub Actions workflows
|
2 |
+
on:
|
3 |
+
push:
|
4 |
+
branches: ["main"]
|
5 |
+
paths:
|
6 |
+
- '.github/**'
|
7 |
+
pull_request:
|
8 |
+
branches: ["main"]
|
9 |
+
paths:
|
10 |
+
- '.github/**'
|
11 |
+
|
12 |
+
jobs:
|
13 |
+
actionlint:
|
14 |
+
runs-on: ubuntu-latest
|
15 |
+
steps:
|
16 |
+
- uses: actions/checkout@v4
|
17 |
+
- name: Download actionlint
|
18 |
+
id: get_actionlint
|
19 |
+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
|
20 |
+
shell: bash
|
21 |
+
- name: Check workflow files
|
22 |
+
run: PATH=".:$PATH" make action-lint
|
23 |
+
shell: bash
|
.github/workflows/checks.yml
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run linter checks
|
2 |
+
on:
|
3 |
+
push:
|
4 |
+
branches: ["main"]
|
5 |
+
pull_request:
|
6 |
+
branches: ["main"]
|
7 |
+
|
8 |
+
concurrency:
|
9 |
+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
10 |
+
cancel-in-progress: true
|
11 |
+
|
12 |
+
jobs:
|
13 |
+
py-lint:
|
14 |
+
runs-on: ubuntu-latest
|
15 |
+
strategy:
|
16 |
+
matrix:
|
17 |
+
python-version: ['3.11']
|
18 |
+
steps:
|
19 |
+
- uses: actions/checkout@v3
|
20 |
+
- uses: ./.github/actions/setup-poetry
|
21 |
+
with:
|
22 |
+
python-version: ${{ matrix.python-version }}
|
23 |
+
- name: Run styling check
|
24 |
+
run: poetry run pre-commit run --all-files
|
25 |
+
|
26 |
+
markdown-lint:
|
27 |
+
runs-on: ubuntu-latest
|
28 |
+
steps:
|
29 |
+
- uses: actions/checkout@v4
|
30 |
+
- name: markdownlint-cli2-action
|
31 |
+
uses: DavidAnson/markdownlint-cli2-action@v16
|
32 |
+
with:
|
33 |
+
globs: "**/*.md"
|
34 |
+
|
.gitignore
CHANGED
@@ -441,3 +441,4 @@ pip-selfcheck.json
|
|
441 |
|
442 |
# Makefile
|
443 |
.action-lint
|
|
|
|
441 |
|
442 |
# Makefile
|
443 |
.action-lint
|
444 |
+
.markdown-lint
|
.markdownlint-cli2.yaml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
config:
|
2 |
+
line-length: false
|
3 |
+
no-emphasis-as-header: false
|
4 |
+
first-line-heading: false
|
5 |
+
globs:
|
6 |
+
- "**/*.md"
|
CODE_OF_CONDUCT.md
CHANGED
@@ -115,7 +115,7 @@ the community.
|
|
115 |
|
116 |
## Attribution
|
117 |
|
118 |
-
This Code of Conduct is adapted from the [Contributor Covenant]
|
119 |
version 2.0, available at
|
120 |
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
|
121 |
|
@@ -126,4 +126,4 @@ Homepage: [https://www.contributor-covenant.org](https://www.contributor-covenan
|
|
126 |
|
127 |
For answers to common questions about this code of conduct, see the FAQ at
|
128 |
[https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at
|
129 |
-
[https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations).
|
|
|
115 |
|
116 |
## Attribution
|
117 |
|
118 |
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org)],
|
119 |
version 2.0, available at
|
120 |
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
|
121 |
|
|
|
126 |
|
127 |
For answers to common questions about this code of conduct, see the FAQ at
|
128 |
[https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at
|
129 |
+
[https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations).
|
CONTRIBUTING.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
## Contributing In General
|
|
|
2 |
Our project welcomes external contributions. If you have an itch, please feel
|
3 |
free to scratch it.
|
4 |
|
@@ -34,14 +35,13 @@ maintainers of each component affected.
|
|
34 |
|
35 |
For a list of the maintainers, see the [MAINTAINERS.md](MAINTAINERS.md) page.
|
36 |
|
37 |
-
|
38 |
## Legal
|
39 |
|
40 |
Each source file must include a license header for the MIT
|
41 |
Software. Using the SPDX format is the simplest approach.
|
42 |
e.g.
|
43 |
|
44 |
-
```
|
45 |
/*
|
46 |
Copyright IBM Inc. All rights reserved.
|
47 |
|
@@ -60,54 +60,54 @@ must include a sign-off statement in the commit message.
|
|
60 |
Here is an example Signed-off-by line, which indicates that the
|
61 |
submitter accepts the DCO:
|
62 |
|
63 |
-
```
|
64 |
Signed-off-by: John Doe <[email protected]>
|
65 |
```
|
66 |
|
67 |
You can include this automatically when you commit a change to your
|
68 |
local git repository using the following command:
|
69 |
|
70 |
-
```
|
71 |
git commit -s
|
72 |
```
|
73 |
|
74 |
-
|
75 |
## Communication
|
76 |
|
77 |
Please feel free to connect with us using the [discussion section](https://github.com/DS4SD/docling-serve/discussions).
|
78 |
|
79 |
-
|
80 |
-
|
81 |
## Developing
|
82 |
|
83 |
### Usage of Poetry
|
84 |
|
85 |
We use Poetry to manage dependencies.
|
86 |
|
87 |
-
|
88 |
#### Install
|
89 |
|
90 |
-
To install, see the documentation here: https://python-poetry.org/docs/master/#installing-with-the-official-installer
|
91 |
|
92 |
1. Install the Poetry globally in your machine
|
|
|
93 |
```bash
|
94 |
curl -sSL https://install.python-poetry.org | python3 -
|
95 |
```
|
|
|
96 |
The installation script will print the installation bin folder `POETRY_BIN` which you need in the next steps.
|
97 |
|
98 |
2. Make sure Poetry is in your `$PATH`
|
99 |
- for `zsh`
|
|
|
100 |
```sh
|
101 |
echo 'export PATH="POETRY_BIN:$PATH"' >> ~/.zshrc
|
102 |
```
|
|
|
103 |
- for `bash`
|
|
|
104 |
```sh
|
105 |
echo 'export PATH="POETRY_BIN:$PATH"' >> ~/.bashrc
|
106 |
```
|
107 |
|
108 |
3. The official guidelines linked above include useful details on the configuration of autocomplete for most shell environments, e.g. Bash and Zsh.
|
109 |
|
110 |
-
|
111 |
#### Create a Virtual Environment and Install Dependencies
|
112 |
|
113 |
To activate the Virtual Environment, run:
|
@@ -122,7 +122,7 @@ To spawn a shell with the Virtual Environment activated. If the Virtual Environm
|
|
122 |
poetry install
|
123 |
```
|
124 |
|
125 |
-
|
126 |
|
127 |
If for whatever reason you need to work in a specific (older) version of Python, run:
|
128 |
|
@@ -132,7 +132,6 @@ poetry env use $(which python3.10)
|
|
132 |
|
133 |
This creates a Virtual Environment with Python 3.10. For other versions, replace `$(which python3.10)` by the path to the interpreter (e.g., `/usr/bin/python3.8`) or use `$(which pythonX.Y)`.
|
134 |
|
135 |
-
|
136 |
#### Add a new dependency
|
137 |
|
138 |
```bash
|
@@ -146,7 +145,6 @@ We use the following tools to enforce code style:
|
|
146 |
- iSort, to sort imports
|
147 |
- Black, to format code
|
148 |
|
149 |
-
|
150 |
We run a series of checks on the code base on every commit, using `pre-commit`. To install the hooks, run:
|
151 |
|
152 |
```bash
|
@@ -155,10 +153,8 @@ pre-commit install
|
|
155 |
|
156 |
To run the checks on-demand, run:
|
157 |
|
158 |
-
```
|
159 |
pre-commit run --all-files
|
160 |
```
|
161 |
|
162 |
Note: Checks like `Black` and `isort` will "fail" if they modify files. This is because `pre-commit` doesn't like to see files modified by their Hooks. In these cases, `git add` the modified files and `git commit` again.
|
163 |
-
|
164 |
-
|
|
|
1 |
## Contributing In General
|
2 |
+
|
3 |
Our project welcomes external contributions. If you have an itch, please feel
|
4 |
free to scratch it.
|
5 |
|
|
|
35 |
|
36 |
For a list of the maintainers, see the [MAINTAINERS.md](MAINTAINERS.md) page.
|
37 |
|
|
|
38 |
## Legal
|
39 |
|
40 |
Each source file must include a license header for the MIT
|
41 |
Software. Using the SPDX format is the simplest approach.
|
42 |
e.g.
|
43 |
|
44 |
+
```text
|
45 |
/*
|
46 |
Copyright IBM Inc. All rights reserved.
|
47 |
|
|
|
60 |
Here is an example Signed-off-by line, which indicates that the
|
61 |
submitter accepts the DCO:
|
62 |
|
63 |
+
```text
|
64 |
Signed-off-by: John Doe <[email protected]>
|
65 |
```
|
66 |
|
67 |
You can include this automatically when you commit a change to your
|
68 |
local git repository using the following command:
|
69 |
|
70 |
+
```text
|
71 |
git commit -s
|
72 |
```
|
73 |
|
|
|
74 |
## Communication
|
75 |
|
76 |
Please feel free to connect with us using the [discussion section](https://github.com/DS4SD/docling-serve/discussions).
|
77 |
|
|
|
|
|
78 |
## Developing
|
79 |
|
80 |
### Usage of Poetry
|
81 |
|
82 |
We use Poetry to manage dependencies.
|
83 |
|
|
|
84 |
#### Install
|
85 |
|
86 |
+
To install, see the documentation here: <https://python-poetry.org/docs/master/#installing-with-the-official-installer>
|
87 |
|
88 |
1. Install the Poetry globally in your machine
|
89 |
+
|
90 |
```bash
|
91 |
curl -sSL https://install.python-poetry.org | python3 -
|
92 |
```
|
93 |
+
|
94 |
The installation script will print the installation bin folder `POETRY_BIN` which you need in the next steps.
|
95 |
|
96 |
2. Make sure Poetry is in your `$PATH`
|
97 |
- for `zsh`
|
98 |
+
|
99 |
```sh
|
100 |
echo 'export PATH="POETRY_BIN:$PATH"' >> ~/.zshrc
|
101 |
```
|
102 |
+
|
103 |
- for `bash`
|
104 |
+
|
105 |
```sh
|
106 |
echo 'export PATH="POETRY_BIN:$PATH"' >> ~/.bashrc
|
107 |
```
|
108 |
|
109 |
3. The official guidelines linked above include useful details on the configuration of autocomplete for most shell environments, e.g. Bash and Zsh.
|
110 |
|
|
|
111 |
#### Create a Virtual Environment and Install Dependencies
|
112 |
|
113 |
To activate the Virtual Environment, run:
|
|
|
122 |
poetry install
|
123 |
```
|
124 |
|
125 |
+
#### (Advanced) Use a Specific Python Version
|
126 |
|
127 |
If for whatever reason you need to work in a specific (older) version of Python, run:
|
128 |
|
|
|
132 |
|
133 |
This creates a Virtual Environment with Python 3.10. For other versions, replace `$(which python3.10)` by the path to the interpreter (e.g., `/usr/bin/python3.8`) or use `$(which pythonX.Y)`.
|
134 |
|
|
|
135 |
#### Add a new dependency
|
136 |
|
137 |
```bash
|
|
|
145 |
- iSort, to sort imports
|
146 |
- Black, to format code
|
147 |
|
|
|
148 |
We run a series of checks on the code base on every commit, using `pre-commit`. To install the hooks, run:
|
149 |
|
150 |
```bash
|
|
|
153 |
|
154 |
To run the checks on-demand, run:
|
155 |
|
156 |
+
```shell
|
157 |
pre-commit run --all-files
|
158 |
```
|
159 |
|
160 |
Note: Checks like `Black` and `isort` will "fail" if they modify files. This is because `pre-commit` doesn't like to see files modified by their Hooks. In these cases, `git add` the modified files and `git commit` again.
|
|
|
|
Makefile
CHANGED
@@ -18,9 +18,12 @@ endif
|
|
18 |
|
19 |
TAG=$(shell git rev-parse HEAD)
|
20 |
|
21 |
-
lint:
|
22 |
$(CMD_PREFIX) touch .action-lint
|
23 |
|
|
|
|
|
|
|
24 |
.PHONY: docling-serve-cpu-image
|
25 |
docling-serve-cpu-image: Containerfile ## Build docling-serve "cpu only" continaer image
|
26 |
$(ECHO_PREFIX) printf " %-12s Containerfile\n" "[docling-serve CPU ONLY]"
|
@@ -37,7 +40,7 @@ docling-serve-gpu-image: Containerfile ## Build docling-serve continaer image wi
|
|
37 |
|
38 |
.PHONY: action-lint
|
39 |
action-lint: .action-lint ## Lint GitHub Action workflows
|
40 |
-
.action-lint: $(shell find .github -type f) | lint
|
41 |
$(ECHO_PREFIX) printf " %-12s .github/...\n" "[ACTION LINT]"
|
42 |
$(CMD_PREFIX) if ! which actionlint $(PIPE_DEV_NULL) ; then \
|
43 |
echo "Please install actionlint." ; \
|
@@ -51,3 +54,22 @@ action-lint: .action-lint ## Lint GitHub Action workflows
|
|
51 |
fi
|
52 |
$(CMD_PREFIX) actionlint -color
|
53 |
$(CMD_PREFIX) touch $@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
TAG=$(shell git rev-parse HEAD)
|
20 |
|
21 |
+
action-lint-file:
|
22 |
$(CMD_PREFIX) touch .action-lint
|
23 |
|
24 |
+
md-lint-file:
|
25 |
+
$(CMD_PREFIX) touch .markdown-lint
|
26 |
+
|
27 |
.PHONY: docling-serve-cpu-image
|
28 |
docling-serve-cpu-image: Containerfile ## Build docling-serve "cpu only" continaer image
|
29 |
$(ECHO_PREFIX) printf " %-12s Containerfile\n" "[docling-serve CPU ONLY]"
|
|
|
40 |
|
41 |
.PHONY: action-lint
|
42 |
action-lint: .action-lint ## Lint GitHub Action workflows
|
43 |
+
.action-lint: $(shell find .github -type f) | action-lint-file
|
44 |
$(ECHO_PREFIX) printf " %-12s .github/...\n" "[ACTION LINT]"
|
45 |
$(CMD_PREFIX) if ! which actionlint $(PIPE_DEV_NULL) ; then \
|
46 |
echo "Please install actionlint." ; \
|
|
|
54 |
fi
|
55 |
$(CMD_PREFIX) actionlint -color
|
56 |
$(CMD_PREFIX) touch $@
|
57 |
+
|
58 |
+
.PHONY: md-lint
|
59 |
+
md-lint: .md-lint ## Lint markdown files
|
60 |
+
.md-lint: $(wildcard */**/*.md) | md-lint-file
|
61 |
+
$(ECHO_PREFIX) printf " %-12s ./...\n" "[MD LINT]"
|
62 |
+
$(CMD_PREFIX) docker run --rm -v $$(pwd):/workdir davidanson/markdownlint-cli2:v0.14.0 "**/*.md"
|
63 |
+
$(CMD_PREFIX) touch $@
|
64 |
+
|
65 |
+
|
66 |
+
.PHONY: py-Lint
|
67 |
+
py-lint: ## Lint Python files
|
68 |
+
$(ECHO_PREFIX) printf " %-12s ./...\n" "[PY LINT]"
|
69 |
+
$(CMD_PREFIX) if ! which poetry $(PIPE_DEV_NULL) ; then \
|
70 |
+
echo "Please install poetry." ; \
|
71 |
+
echo "pip install poetry" ; \
|
72 |
+
exit 1 ; \
|
73 |
+
fi
|
74 |
+
$(CMD_PREFIX) poetry install --all-extras
|
75 |
+
$(CMD_PREFIX) poetry run pre-commit run --all-files
|
README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5 |
> [!NOTE]
|
6 |
> This is an unstable draft implementation which will quickly evolve.
|
7 |
|
8 |
-
|
9 |
## Development
|
10 |
|
11 |
Install the dependencies
|
|
|
5 |
> [!NOTE]
|
6 |
> This is an unstable draft implementation which will quickly evolve.
|
7 |
|
|
|
8 |
## Development
|
9 |
|
10 |
Install the dependencies
|