Skip to content

Commit

Permalink
Merge pull request #1 from ModOrganizer2/qt6
Browse files Browse the repository at this point in the history
Qt6, PyBind11, new linters...
  • Loading branch information
Holt59 authored Sep 19, 2023
2 parents 06e0fe1 + 9ee5222 commit 52f835d
Show file tree
Hide file tree
Showing 31 changed files with 6,392 additions and 3,044 deletions.
53 changes: 31 additions & 22 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
name: Build Documentation

on:
pull_request:
push:
branches:
- master

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
# Standard drop-in approach that should work for most people.
- uses: ammaraskar/sphinx-action@master
env:
PYTHONPATH: .
with:
pre-build-command: "apt-get update -y && apt-get install -y libgl1-mesa-glx && cp stubs/2.4.0/mobase.pyi docs/mobase.py"
docs-folder: "docs/"
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
- uses: abatilo/actions-poetry@v2
- name: Install
run: |
poetry install
- name: Install libgl1
run: sudo apt install -y libgl1 libegl1 libglib2.0-0 libxkbcommon0 libdbus-1-3
- name: Copy stubs
run: cp stubs/2.5.0/mobase-stubs/__init__.pyi docs/mobase.py
- name: Build
run: poetry run sphinx-build -b html docs/source docs/build
env:
PYTHONPATH: docs

- name: Install SSH Client 🔑
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
name: Install SSH Client 🔑
uses: webfactory/ssh-agent@v0.4.1
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
SSH: true
REPOSITORY_NAME: ModOrganizer2/python-plugins-doc
BRANCH: master
FOLDER: docs/build/html
- if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
name: Deploy Documentation
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
SSH: true
REPOSITORY_NAME: ModOrganizer2/python-plugins-doc
BRANCH: master
FOLDER: docs/build
32 changes: 16 additions & 16 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ on: [push, pull_request]
jobs:
checks:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Test with tox
run: tox -e py38-lint
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11
- uses: abatilo/actions-poetry@v2
- name: Install
run: |
poetry install
- name: Lint
run: |
poetry run black src --check --diff
poetry run isort -c src
poetry run mypy src
poetry run ruff src
poetry run pyright src
18 changes: 0 additions & 18 deletions .github/workflows/pull_request.yml

This file was deleted.

56 changes: 28 additions & 28 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
name: Upload Python Package

on:
release:
types: [published]
push:
tags: ["*"]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Replace string
uses: frabert/replace-string-action@v1.1
id: version
with:
string: ${{ github.event.release.tag_name }}
pattern: "v?([0-9][.][0-9][.][0-9]).*"
replace-with: "$1"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
cd stubs/setup
cp ../${{ steps.version.outputs.replaced }}/mobase.pyi mobase-stubs/__init__.pyi
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v4
- name: Replace string
uses: frabert/replace-string-action@v1.1
id: version
with:
string: ${{ github.ref_name }}
pattern: "v?([0-9][.][0-9][.][0-9]).*"
replace-with: "$1"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
cd stubs/setup
cp -r ../${{ steps.version.outputs.replaced }}/mobase-stubs/* mobase-stubs/
sed -i 's/__version__ = ".*"/__version__ = "${{ github.ref_name }}"/' mobase-stubs/__init__.pyi
python setup.py sdist bdist_wheel
twine upload dist/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
.mypy_cache
__pycache__
.vscode
**/*.egg-info

# The 'bin/' directory:
bin
docs/build
docs/mobase.py
docs/source/api
docs/source/api
94 changes: 46 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,12 @@ MO2.
You can install stubs for a specific version of MO2:

```bash
pip install mobase-stubs==2.3.2.*
```

If you want development stubs, you can install them this way:
```bash
# Clone this repository:
git clone https://github.com/ModOrganizer2/pystubs-generation.git

# Install the stubs:
cd pystubs-generation/stubs/setup
pip install .
pip install mobase-stubs==2.5.*
```

Some words of warning:

- The stubs are as correct as possible, but some errors are expected.
- If you see a `InterfaceNotImplemented` class anywhere in the stubs, it means that
a proper interface is currently not available.
- Some classes are said (in the stubs) to inherit `QWidget` or `QObject`. This is true
on the C++ side but NOT on the python side. The inheritance is only added to help with
auto-completion since these classes also override `__getattr__` to dispatch to the
Expand All @@ -44,35 +33,39 @@ Some words of warning:

The stubs are generated using python by parsing the `mobase` module.
You need the version of python that matches your current MO2 installation: e.g., if you
have a `python38.dll` in your MO2 installation path, then you need **Python 3.8**.
have a `python310.dll` in your MO2 installation path, then you need **Python 3.10**.

To generate the stubs, you can run:

```
# Change the output folder to whatever you want:
python main.py -c configs\config-2.4.yml ${MO2_INSTALL_PATH}
```bash
# install the package
poetry install

# change the output folder to whatever you want
mo2-stubs-generator -c configs/config-2.4.yml -o mobase-stubs ${MO2_INSTALL_PATH}
```

Where `${MO2_INSTALL_PATH}` is the path to your MO2 installation (the one containing `ModOrganizer.exe`).
Where `${MO2_INSTALL_PATH}` is the path to your MO2 installation (the one
containing `ModOrganizer.exe`).

The stubs are generated under `stubs/setup/mobase-stubs/__init__.pyi`, you
can change the output file by using the `-o` option
The latest stubs are kept under `stubs/setup/mobase-stubs/__init__.pyi`,
and when a new version is released, the stubs are backed-up under
`stubs/x.y.z/mobase.pyi`.
The stubs are generated under `stubs/setup/mobase-stubs` by default, you
can change the output file by using the `-o` option.
The stubs under `stubs/setup/mobase-stubs` should not be committed as these are
generated from the version stubs under `stubs/${VERSION}/mobase-stubs`.

A few options are available for `main.py`:
A few options are available for `mo2-stubs-generator`:

```
usage: Stubs generator for the MO2 python interface [-h] [-o OUTPUT] [-v] [-c CONFIG] INSTALL_DIR
```bash
$ mo2-stubs-generator --help
usage: stubs generator for the MO2 python interface [-h] [-o OUTPUT] [-v] [-c CONFIG] INSTALL_DIR

positional arguments:
INSTALL_DIR installation directory of Mod Organizer 2

optional arguments:
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
output file (default stubs/setup/mobase-stubs/__init__.pyi)
output folder (default stubs/setup/mobase-stubs)
-v, --verbose verbose mode (all logs go to stderr)
-c CONFIG, --config CONFIG
configuration file
Expand All @@ -81,19 +74,7 @@ optional arguments:
The stubs generator will try hard to find a valid stubs for all classes
and methods of `mobase`.
A lot of information is available through the `-v` options. Without it,
only conversions or fixes
considered "strange" will be shown.
For instance, here is the output with the current `config-2.4.yml` file:

```
WARNING: Replacing IOrganizer::FileInfo with FileInfo.
WARNING: Replacing IOrganizer::FileInfo with FileInfo.
WARNING: Replacing IPluginInstaller::EInstallResult with InstallResult.
WARNING: Replacing IPluginInstaller::EInstallResult with InstallResult.
```

As you can see, only a few types were manually fixed (specified in
`config-2.4.yml`).
only conversions or fixes considered "strange" will be shown.

## Configuration file

Expand All @@ -102,20 +83,37 @@ deduced by `main` (or are too complex to deduce), and the documentation for ever

## Uploading the stubs to pypi

The upload of the stubs to https://pypi.org/project/mobase-stubs/ should be
done automatically when a new Github release is made.
The upload of the stubs to [https://pypi.org/project/mobase-stubs/](https://pypi.org/project/mobase-stubs/)
should be done automatically when a new Github tag is pushed.

## Extras — Starts a python interpreter with `mobase`
## Extras — Using `mobase` in a Python interpreter

It is possible to start a (i)python interpret with `mobase` imported by running:
It is possible to start a (i)python interpreter with `mobase` imported by running

```bash
python -i -m mo2.stubs.generator.loader ${MO2_INSTALL_PATH}
```
python -im generator.loader ${MO2_INSTALL_PATH}

You can also import `mobase` in your code using the following (after installing
this package):

```python
from mo2.stubs.generator import load_mobase

mobase = load_mobase(MO2_INSTALL_PATH)

# the above will probably not give you type-completion in your IDE or typing, so
# you can use the following (if the stubs are installed)
load_mobase(MO2_INSTALL_PATH)
import mobase
import mobase.widgets
```

This has no real usage except for MO2 developers since most classes from the `mobase` module cannot be instantiated.

# License
**Note:** Most classes in `mobase` cannot be instantiated, so this is mostly intended
for MO2 developers.

## License

The MIT License (MIT)

Expand Down
Loading

0 comments on commit 52f835d

Please sign in to comment.