Skip to content

Commit

Permalink
introduced markdown linter
Browse files Browse the repository at this point in the history
  • Loading branch information
mbway committed Feb 29, 2024
1 parent 2cda00f commit 2f9bd84
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 80 deletions.
19 changes: 19 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
default: true

MD003:
style: atx
MD004:
style: dash
MD007:
indent: 4
MD013:
line_length: 120
code_block_line_length: 120
MD046:
style: fenced
MD048:
style: backtick
MD049:
style: asterisk
MD050:
style: asterisk
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ repos:
rev: v2.2.6
hooks:
- id: codespell
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.39.0
hooks:
- id: markdownlint-fix
24 changes: 12 additions & 12 deletions Code-of-Conduct.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities
Expand All @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at konstin@mailbox.org. All
reported by contacting the project team at <konstin@mailbox.org>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand All @@ -68,6 +68,6 @@ members of the project's leadership.
## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>

[homepage]: https://www.contributor-covenant.org
35 changes: 26 additions & 9 deletions Contributing.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
# Contributing

Thank you for your interest in contributing to maturin_import_hook. All are welcome! Please consider reading
the [Code of Conduct](https://github.com/PyO3/maturin-import-hook/blob/main/Code-of-Conduct.md) to keep our community
positive and inclusive.

## Getting Started Contributing
- we use the [github issue tracker](https://github.com/PyO3/maturin-import-hook/issues) and [discussions](https://github.com/PyO3/maturin-import-hook/discussions) to keep track of bugs and ideas

- we use the [github issue tracker](https://github.com/PyO3/maturin-import-hook/issues) and
[discussions](https://github.com/PyO3/maturin-import-hook/discussions) to keep track of bugs and ideas

### Setting up a development environment

1. Install rust (eg using `rustup`) and maturin (eg `pipx install maturin`)
2. Clone the repository
- if you are looking to submit a PR, create a fork on github and clone your fork
3. Install [pre-commit](https://pre-commit.com/) (eg `pipx install pre-commit`) then run `pre-commit install` in the repo root
4. See [tests/README.md](https://github.com/PyO3/maturin-import-hook/blob/main/tests/README.md) for instructions on how best to run the test suite and some other miscellaneous instructions for debugging and carrying out maintenance tasks.
3. Install [pre-commit](https://pre-commit.com/) (eg `pipx install pre-commit`)
then run `pre-commit install` in the repo root
4. See [tests/README.md](https://github.com/PyO3/maturin-import-hook/blob/main/tests/README.md) for instructions
on how best to run the test suite and some other miscellaneous instructions for debugging and
carrying out maintenance tasks.

Tips:

- [pyenv](https://github.com/pyenv/pyenv) may be useful for installing a specific python interpreter
- Virtual machines such as [VirtualBox](https://www.virtualbox.org/) and [OSX-KVM](https://github.com/kholia/OSX-KVM) are useful for running tests on specific platforms locally. Or you can use the test pipeline on github actions.
- Virtual machines such as [VirtualBox](https://www.virtualbox.org/) and [OSX-KVM](https://github.com/kholia/OSX-KVM)
are useful for running tests on specific platforms locally. Or you can use the test pipeline on github actions.

## Continuous Integration

## Writing Pull Requests
The maturin_import_hook repo uses [GitHub actions](https://github.com/PyO3/maturin-import-hook/actions).
PRs are blocked from merging if the CI is not successful.

### Continuous Integration
The maturin_import_hook repo uses [GitHub actions](https://github.com/PyO3/maturin-import-hook/actions). PRs are blocked from merging if the CI is not successful.
You can run the test pipeline on your fork from the 'Actions' tab of your fork. The pipeline takes several arguments
when run manually that you can use to narrow down what is run so you can iterate faster when trying to solve a
particular issue. The pipeline uploads the test results as html reports that can be downloaded and examined.
This is generally easier than sifting through the raw logs.

You can run the test pipeline on your fork from the 'Actions' tab of your fork. The pipeline takes several arguments when run manually that you can use to narrow down what is run so you can iterate faster when trying to solve a particular issue. The pipeline uploads the test results as html reports that can be downloaded and examined. This is generally easier than sifting through the raw logs.
Linting and type-checking is enforced in the repo using [pre-commit](https://pre-commit.com/).
See `.pre-commit-config.yaml` for the checks that are performed and `pyproject.toml` for the configuration
of those linters.

Linting and type-checking is enforced in the repo using [pre-commit](https://pre-commit.com/). See `.pre-commit-config.yaml` for the checks that are performed and `pyproject.toml` for the configuration of those linters. The configuration starts with all `ruff` lints enabled with a list of specifically disabled lints. If you are writing new code that is triggering a lint that you think ought to be disabled, you can suggest this in a PR, but generally stick to conforming to the suggested linter rules.
The configuration starts with all `ruff` lints enabled with a list of specifically disabled lints.
If you are writing new code that is triggering a lint that you think ought to be disabled, you can suggest this in
a PR, but generally stick to conforming to the suggested linter rules.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ A python import hook to automatically rebuild [maturin](https://www.maturin.rs/)
Using this import hook reduces friction when developing mixed python/rust codebases because changes made to rust
components take effect automatically like changes to python components do.

The import hook also provides conveniences such as [importlib.reload()](https://docs.python.org/3/library/importlib.html#importlib.reload) support for maturin projects.
The import hook also provides conveniences such as
[importlib.reload()](https://docs.python.org/3/library/importlib.html#importlib.reload) support for maturin projects.

## Usage

After installing `maturin`, install the import hook into a python virtual environment with:

```shell
$ pip install maturin_import_hook
pip install maturin_import_hook
```

Then, optionally make the hook activate automatically with:

```shell
$ python -m maturin_import_hook site install
python -m maturin_import_hook site install
```

This only has to be run once for each virtual environment.

Alternatively, put the following at the top of each python script where you want to use the hook:

```python
import maturin_import_hook

Expand All @@ -41,16 +48,19 @@ Once the hook is active, any `import` statement that imports an editable-install
automatically rebuilt if necessary before it is imported.

## CLI

The package provides a CLI interface for getting information such as the location and size of the build cache and
managing the installation into `sitecustomize.py`. For details, run:

```shell
$ python -m maturin_import_hook --help
python -m maturin_import_hook --help
```


## Debugging

If you encounter a problem, a good way to learn more about what is going on is to enable the debug logging for the
import hook. This can be done by putting the following lines above the import that is causing an issue:

```python
# configure logging if you haven't already (make sure DEBUG level is visible)
logging.basicConfig(format="%(name)s [%(levelname)s] %(message)s", level=logging.DEBUG)
Expand All @@ -63,7 +73,9 @@ import some_package

Licensed under either of:

* Apache License, Version 2.0, ([LICENSE-APACHE](https://github.com/PyO3/maturin-import-hook/blob/main/license-apache) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](https://github.com/PyO3/maturin-import-hook/blob/main/license-mit) or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, ([LICENSE-APACHE](https://github.com/PyO3/maturin-import-hook/blob/main/license-apache)
or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](https://github.com/PyO3/maturin-import-hook/blob/main/license-mit)
or <http://opensource.org/licenses/MIT>)

at your option.
1 change: 1 addition & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

The import hook classes can be subclassed to further customize to specific use cases.
For example settings can be configured per-project or loaded from configuration files.

```python
import sys
from pathlib import Path
Expand Down
19 changes: 12 additions & 7 deletions docs/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ layouts as well as importing standalone `.rs` files.
## Installation

Install into a virtual environment then install so that the import hook is always active.

```shell
$ pip install maturin_import_hook
$ python -m maturin_import_hook site install # install into the active environment
pip install maturin_import_hook
python -m maturin_import_hook site install # install into the active environment
```

Alternatively, instead of using `site install`, put calls to `maturin_import_hook.install()` into any script where you
Expand All @@ -40,6 +41,7 @@ import subpackage.my_rust_script
```

The maturin project importer and the rust file importer can be used separately

```python
from maturin_import_hook import rust_file_importer
rust_file_importer.install()
Expand All @@ -49,6 +51,7 @@ project_importer.install()
```

The import hook can be configured to control its behaviour

```python
import maturin_import_hook
from maturin_import_hook.settings import MaturinSettings
Expand Down Expand Up @@ -77,22 +80,23 @@ Installation into `sitecustomize.py` can be managed with the import hook cli usi
`python -m maturin_import_hook site install`. The CLI can also manage uninstallation.

## Environment Variables

The import hook can be disabled by setting `MATURIN_IMPORT_HOOK_ENABLED=0`. This can be used to disable
the import hook in production if you want to leave calls to `import_hook.install()` in place.

Build files will be stored in an appropriate place for the current system but can be overridden
by setting `MATURIN_BUILD_DIR`. These files can be deleted without causing any issues (unless a build is in progress).
The precedence for storing build files is:

* `MATURIN_BUILD_DIR`
* `<virtualenv_dir>/maturin_build_cache`
* `<system_cache_dir>/maturin_build_cache`
* e.g. `~/.cache/maturin_build_cache` on POSIX
- `MATURIN_BUILD_DIR`
- `<virtualenv_dir>/maturin_build_cache`
- `<system_cache_dir>/maturin_build_cache`
- e.g. `~/.cache/maturin_build_cache` on POSIX

See the location being used with the CLI: `python -m maturin_import_hook cache info`


## Logging

By default the `maturin_import_hook` logger does not propagate to the root logger. This is so that `INFO` level messages
are shown to the user without them having to configure logging (`INFO` level is normally not visible). The import hook
also has extensive `DEBUG` level logging that generally would be more noise than useful. So by not propagating, `DEBUG`
Expand All @@ -104,6 +108,7 @@ the messages as normal.
When debugging issues with the import hook, you should first call `reset_logger()` then configure the root logger
to show `DEBUG` messages. You can also run with the environment variable `RUST_LOG=maturin=debug` to get more
information from maturin.

```python
import logging
logging.basicConfig(format='%(name)s [%(levelname)s] %(message)s', level=logging.DEBUG)
Expand Down
Loading

0 comments on commit 2f9bd84

Please sign in to comment.