Skip to content

Commit

Permalink
fix(python): support python3.13 and drop python3.8 (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
manawasp authored Nov 27, 2024
1 parent ef7cf0d commit 063410e
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 237 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
shell: bash
run: npm install
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Release
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.1.1
rev: v3.6.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
Expand Down
24 changes: 17 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Contributing
# Contributing

Contributions are more than welcome! Don't hesitate to open an incomplete PR to ask for help!

## Python versions

The library currently supports Python versions 3.7+
The library currently supports Python versions 3.9+

## Install dependencies

Expand All @@ -16,9 +16,11 @@ Then run
## Testing

### With Tox

`tox`

### With pytest directly

`poetry run pytest tests`

## Adding a new template
Expand All @@ -27,42 +29,50 @@ Copy one of the existing template, change the name and start modifying.
If you are looking for examples, you can run `poetry run python docs/generate_examples.py` from the root folder.

The examples will be in:
* `docs/examples/examples_flat_default`
* `docs/examples/examples_js_default`
* `docs/examples/examples_md_default`
* `docs/examples/examples_js_with_bagdes`

- `docs/examples/examples_flat_default`
- `docs/examples/examples_js_default`
- `docs/examples/examples_md_default`
- `docs/examples/examples_js_with_bagdes`

## Optional stuff

The maintainer will take care of the following for you if you don't want to bother with it :)

### Formatting with black

Running with tox will ensure the code has been formatted with [black](https://github.com/psf/black)

It is recommended to run black [from your IDE](https://github.com/psf/black/blob/master/docs/editor_integration.md) or as a pre-commit hook

### Modifying Javascript

`schema_doc.js` is not minified automatically, you are responsible for doing it yourself

### Generating doc

The documentation is served by `index.html` deployed on GitHub Pages automatically.
The documentation is using [docsify](https://docsify.js.org/) to render.

#### Adding examples

- Run `poetry run python docs/generate_examples.py`. This will get all examples from `docs/examples/cases`, render the resulting HTML and
include it in the appropriate folders.
include it in the appropriate folders.
- (optional) If you have added an example, add the file name (without `.json`), the display name and description in `docs/cases_description.yaml`

#### Generating locally

Execute following script from root dir of the repository

```bash
poetry run python docs/generate_examples.py
```

You can check it locally using:

```bash
npm i docsify-cli -g
docsify serve docs
```

Then you can check [generated doc](http://localhost:3000).
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Quickly generate a beautiful static HTML or Markdown page documenting a JSON sch
- Support for references (even circular!)

## Installation
```

```sh
pip install json-schema-for-humans
```

Expand All @@ -25,6 +26,7 @@ pip install json-schema-for-humans
Options for generation of the doc are documented using the library itself: [HTML version](https://coveooss.github.io/json-schema-for-humans/examples/examples_js_default/Configuration.html) - [Markdown version](https://github.com/coveooss/json-schema-for-humans/blob/main/docs/examples/examples_md_default/Configuration.md)

They can be supplied in various ways:

- Using a JSON or YAML configuration file with the CLI option `--config-file`
- Using the CLI option `--config`
- Using the `ConfigurationOption` object from code
Expand All @@ -38,20 +40,23 @@ generate-schema-doc [OPTIONS] SCHEMA_FILES_OR_DIR [RESULT_FILE_OR_DIR]
```

`SCHEMA_FILES_OR_DIR` can be:

- a path to a single schema file;
- a path to a directory, in this case all files with extensions json, yaml, or yml will be used;
- a path to a directory, in this case all files with extensions json, yaml, or yml will be used;
- a [glob pattern](https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob) (starts from the current working directory); or
- a comma-separated list of the above

All schemas provided must be a valid JSON Schema (in JSON or YAML format)

Examples:

- `my_schema.json`
- `my_folder`
- `my_folder/my_schema.yaml,another_schema.json`
- `**/*.yaml.*`

The default value for `RESULT_FILE_OR_DIR` depends on the context:

- the current working directory if more than one schema as been provided as input
- `schema_doc.html` if rendering a single schema as HTML
- `schema_doc.md` if rendering a single schema as Markdown
Expand All @@ -67,13 +72,15 @@ The list of available templates is [documented here](https://coveooss.github.io/
#### CLI options

#### --config

Supply generation config parameters. The parameters are documented in the JSON schema `config_schema.json` at the root of the repo or see the generated doc: [HTML version](https://coveooss.github.io/json-schema-for-humans/examples/examples_js_default/Configuration.html) - [Markdown version](https://github.com/coveooss/json-schema-for-humans/blob/main/docs/examples/examples_md_default/Configuration.md).

Each parameter is in the format `--config parameter_name=parameter_value`. Example: `--config expand_buttons=true`. The parameter value must be valid JSON.

For flags, you can also omit the value for `true` or prefix the parameter name with `no_` for `false`. Example: `--config expand_buttons` or `--config no_expand_buttons`.

#### --config-file

Path to a JSON or YAML configuration file respecting the schema `config_schema.json`.

Example: `--config-file jsfh-conf.yaml` where `jsfh-conf.yaml` is in the current directory and contains the following:
Expand All @@ -88,18 +95,20 @@ copy_js: false
The following methods are available to import from `json_schema_for_humans.generate`

Method Name | Schema input | Output | CSS and JS copied?
--- | --- | --- | ---
generate_from_schema | `schema_file` as str or `pathlib.Path` | Rendered doc as a str | No
generate_from_filename | `schema_file_name` as str or `pathlib.Path` | Rendered doc written to the file at path `result_file_name` | Yes
generate_from_file_object | `schema_file` as an open file object (read mode) | Rendered doc written to the file at `result_file`, which must be an open file object (in write mode) | Yes
| Method Name | Schema input | Output | CSS and JS copied? |
| ------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------------------- | ------------------ |
| generate_from_schema | `schema_file` as str or `pathlib.Path` | Rendered doc as a str | No |
| generate_from_filename | `schema_file_name` as str or `pathlib.Path` | Rendered doc written to the file at path `result_file_name` | Yes |
| generate_from_file_object | `schema_file` as an open file object (read mode) | Rendered doc written to the file at `result_file`, which must be an open file object (in write mode) | Yes |

Notes:

- When using file objects, it is assumed that files are opened with encoding "utf-8"
- CSS and JS files are copied to the current working directory with names "schema_doc.css" and "schema_doc.min.js" respectively, if necessary
- Other parameters of these methods are analogous to the CLI parameters documented above.

#### The GenerationConfiguration object

To reduce the number of parameters to pass from function to function in the code, there is a `GenerationConfiguration` object that should be used for providing options.

Example:
Expand All @@ -114,10 +123,10 @@ generate_from_filename("my_schema.json", "schema_doc.html", config=config)
# Your doc is now in a file named "schema_doc.html". Next to it, "schema_doc.min.js" was copied, but not "schema_doc.css"
# Your doc will contain a "Expand all" and a "Collapse all" button at the top
```

#### Pre-load schemas

`generate_from_schema` has a `loaded_schemas` parameter that can be used to pre-load schemas. This must be a dict with the key being the real path of the schema file and the value being the result of loading the schema (with `json.load` or `yaml.safe_load`, for example).

This should not be necessary in normal scenarios.
Expand All @@ -127,6 +136,7 @@ This should not be necessary in normal scenarios.
See the excellent [Understanding JSON Schema](https://json-schema.org/understanding-json-schema) to understand what are those checks

The following are supported:

- Types
- Regular expressions
- String length
Expand All @@ -142,6 +152,7 @@ The following are supported:
- Conditional subschemas

These are **not** supported at the moment (PRs welcome!):

- Property names and size
- Property dependencies
- Media
Expand All @@ -154,7 +165,6 @@ References are supported:
- To a local file, `{"$ref": "references.json"}`, `{"$ref": "references.json#/definitions/something"}`, `{"$ref": "file:references.json"}`, `{"$ref": "file:references.json#/definitions/something}`
- To a URL, `{"$ref": "http://example.com/schema.json"}`, `{"$ref": "http://example.com/schema.json#/definitions/something"}`


You _can_ have a `description` next to a `$ref`, it will be displayed in priority to the description from the referenced element.

If you have several attributes using the same definition, the definition will only be rendered once.
Expand All @@ -171,7 +181,7 @@ This is the default template. It uses Bootstrap along with minimal Javascript to

- Properties are in expandable dynamic sections. You can include a button to expand or collapse all. (See doc: [HTML version](https://coveooss.github.io/json-schema-for-humans/examples/examples_js_default/Configuration.html#expand_buttons) - [Markdown version](https://github.com/coveooss/json-schema-for-humans/blob/main/docs/examples/examples_md_default/Configuration.md#expand_buttons))
- Conditional subschemas (`anyOf`, `oneOf`, `allOf`) are in tabbed sections
- Anchor links will scroll to, expand, and animate the target section
- Anchor links will scroll to, expand, and animate the target section
- Long descriptions are collapsed by default

When using this template, you need to include the Javascript file (`schema_doc.min.js`) that is automatically copied next to the output HTML file (`schema_doc.html` by default).
Expand All @@ -182,15 +192,15 @@ This schema is identical to the js template, but all CSS and JavaScript resource

### flat

*Note*: This template is a work in progress
_Note_: This template is a work in progress

It is sometimes not possible or desirable to include custom Javascript in documentation. This template addresses this issue by removing interactive elements in favor of simpler HTML.

At the moment, this means the whole documentation is generated without any collapsible sections, which may make it hard to understand the schema structure. Contributions are welcomed to improve it!

### MD (Markdown)

*Note*: This template is a work in progress
_Note_: This template is a work in progress

This template allows users to publish the generated documentation without hosting an HTTP server.

Expand All @@ -203,6 +213,6 @@ See doc: [HTML version](https://coveooss.github.io/json-schema-for-humans/exampl

Contributions are welcomed to improve it!


## Contributing

[See CONTRIBUTING.md](https://github.com/coveooss/json-schema-for-humans/blob/main/CONTRIBUTING.md)
Loading

0 comments on commit 063410e

Please sign in to comment.