Skip to content

Commit

Permalink
Add pre-commit with isort
Browse files Browse the repository at this point in the history
  • Loading branch information
dbast committed Feb 14, 2023
1 parent 5dc44bf commit 424a670
Show file tree
Hide file tree
Showing 45 changed files with 191 additions and 125 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 99
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ jobs:
channels: conda-canary/label/conda-conda-pr-11882,conda-forge
extra-specs: |
python=${{ matrix.python-version }}
conda-canary/label/conda-conda-pr-11882::conda
pip
pytest
pytest-cov
pydantic
hypothesis
conda-canary/label/conda-conda-pr-11882::conda
pip
pytest
pytest-cov
pydantic
hypothesis
hypothesis-jsonschema
- shell: bash -el {0}
Expand Down
25 changes: 25 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# disable autofixing PRs, commenting "pre-commit.ci autofix" on a pull request triggers a autofix
ci:
autofix_prs: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: fix-byte-order-marker
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: debug-statements
- id: detect-private-key
- id: mixed-line-ending
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: check-merge-conflict
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
4 changes: 2 additions & 2 deletions cwp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# this script is used on windows to wrap shortcuts so that they are executed within an environment
# It only sets the appropriate prefix PATH entries - it does not actually activate environments

import argparse
import os
import sys
import subprocess
import sys
from os.path import join, pathsep
import argparse

from menuinst._legacy.knownfolders import FOLDERID, get_folder_path

Expand Down
4 changes: 2 additions & 2 deletions docs/source/conda.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ While it can be used as a Python library on its own,
If you want to learn how to create shortcuts for `conda` packages you are building and maintaining, check {doc}`defining-shortcuts`.
```

`menuinst` integrates natively with `conda`, so as an end user you don't need to do anything to enable it.
`menuinst` integrates natively with `conda`, so as an end user you don't need to do anything to enable it.
If a package is shipping a `menuinst`-compatible shortcut, it will be detected at installation time, and `conda` will invoke `menuinst` on its own.

If you want to change the default behavior, there are some command-line flags you can use:
Expand Down Expand Up @@ -85,4 +85,4 @@ Use `sed` like this:
```bash
$ sed "s/__PKG_VERSION__/${PKG_VERSION}/g" "${RECIPE_DIR}/menu.json" > "${PREFIX}/Menu/${PKG_NAME}_menu.json"
```
````
````
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from pathlib import Path
import json
from pathlib import Path

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand Down
5 changes: 2 additions & 3 deletions docs/source/defining-shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you want to learn more, check the {doc}`reference` for full details on the av
The JSON configurations follow a well-defined schema documented at {ref}`schema`.
```

## Minimal example
## Minimal example

A minimal example to launch Python's `turtle` module would be:

Expand All @@ -44,10 +44,9 @@ A minimal example to launch Python's `turtle` module would be:

```{tip}
Note how the `menu_name` is using a placeholder `{{ PY_VER }}`.
`menuinst` supports Jinja-like variables.
`menuinst` supports Jinja-like variables.
The full list of available placeholders is available at {ref}`placeholders`.
```

This is not using any customization options or advanced features.
It's the bare minimum to make it work: a name, the command, and the target platforms.

2 changes: 1 addition & 1 deletion docs/source/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Getting started

`menuinst` can be used to create shortcuts or menu items across operating systems.
It's designed to integrate nicely with `conda` packages,
It's designed to integrate nicely with `conda` packages,
but it can be used without it to an extent via its Python API (see below).

<!-- NOTE: General Python support will be added. This section will be rephrased then -->
Expand Down
2 changes: 1 addition & 1 deletion docs/source/robots.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
User-agent: *

Sitemap: https://conda.github.io/menuinst/sitemap.xml
Sitemap: https://conda.github.io/menuinst/sitemap.xml
9 changes: 5 additions & 4 deletions menuinst/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
"""

import json
import os
import sys
import json
from os import PathLike
from logging import getLogger as _getLogger
from os import PathLike

try:
from ._version import __version__
Expand All @@ -14,8 +14,9 @@


from ._legacy import install as _legacy_install
from .api import install as _api_install, remove as _api_remove
from .utils import DEFAULT_PREFIX, DEFAULT_BASE_PREFIX
from .api import install as _api_install
from .api import remove as _api_remove
from .utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX

_log = _getLogger(__name__)

Expand Down
7 changes: 4 additions & 3 deletions menuinst/_legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
# All rights reserved.

from __future__ import absolute_import

import json
import logging
import sys
import json
from os.path import abspath, basename, exists, join

try:
from .._version import __version__
except ImportError:
__version__ = "dev"

from ..utils import DEFAULT_PREFIX, DEFAULT_BASE_PREFIX
from ..utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX

if sys.platform == 'win32':
from .win32 import Menu, ShortCut
from ..platforms.win_utils.win_elevate import isUserAdmin, runAsAdmin
from .win32 import Menu, ShortCut


def _install(path, remove=False, prefix=None, mode=None, root_prefix=None):
Expand Down
2 changes: 2 additions & 0 deletions menuinst/_legacy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from os.path import join

import menuinst._legacy as menuinst

from ..utils import DEFAULT_PREFIX


def main():
from optparse import OptionParser

Expand Down
1 change: 0 additions & 1 deletion menuinst/_legacy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from os.path import isdir, isfile, islink



def rm_empty_dir(path):
try:
os.rmdir(path)
Expand Down
7 changes: 3 additions & 4 deletions menuinst/_legacy/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
from __future__ import absolute_import, unicode_literals

import ctypes
import locale
import logging
import os
from os.path import isdir, join, exists
import sys
import locale

from os.path import exists, isdir, join

from .utils import rm_empty_dir, rm_rf
from ..platforms.win_utils.knownfolders import dirs_src, folder_path
from ..platforms.win_utils.winshortcut import create_shortcut
from ..utils import DEFAULT_BASE_PREFIX
from .utils import rm_empty_dir, rm_rf

# This allows debugging installer issues using DebugView from Microsoft.
OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW
Expand Down
25 changes: 13 additions & 12 deletions menuinst/_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
Generate JSON schemas from pydantic models
"""

from pprint import pprint
from typing import Optional, Union, List, Literal, Dict
from pathlib import Path
from logging import getLogger
import json
from logging import getLogger
from pathlib import Path
from pprint import pprint
from typing import Dict, List, Literal, Optional, Union

from pydantic import BaseModel as _BaseModel, Field, constr, conlist
from pydantic import BaseModel as _BaseModel
from pydantic import Field, conlist, constr

log = getLogger(__name__)

Expand Down Expand Up @@ -71,8 +72,8 @@ class Windows(BasePlatformSpecific):

class Linux(BasePlatformSpecific):
"""
Linux-specific instructions.
Linux-specific instructions.
Check the `Desktop entry specification <desktop-entry-spec>`__ for more details.
.. desktop-entry-spec: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys
Expand All @@ -82,7 +83,7 @@ class Linux(BasePlatformSpecific):
"""
Categories in which the entry should be shown in a menu.
"See 'Registered categories' in the `Menu Spec <menu-spec>`__.
.. menu-spec: http://www.freedesktop.org/Standards/menu-spec
"""
DBusActivatable: Optional[bool] = None
Expand All @@ -107,7 +108,7 @@ class Linux(BasePlatformSpecific):
NoDisplay: Optional[bool] = None
"""
Do not show this item in the menu. Useful to associate MIME types
and other registrations, without having an actual clickable item.
and other registrations, without having an actual clickable item.
Not to be confused with 'Hidden'.
"""
NotShowIn: Optional[Union[List[str], constr(regex=r"^.+;$")]] = None
Expand Down Expand Up @@ -231,7 +232,7 @@ class CFBundleDocumentTypesModel(BaseModel):
"Whether an app is prohibited from running simultaneously in multiple user sessions."
LSRequiresNativeExecution: Optional[bool] = None
"""
If true, prevent a universal binary from being run under
If true, prevent a universal binary from being run under
Rosetta emulation on an Intel-based Mac.
"""
entitlements: Optional[List[constr(regex=r"[a-z0-9\.\-]+")]] = None
Expand All @@ -251,8 +252,8 @@ class CFBundleDocumentTypesModel(BaseModel):

class Platforms(BaseModel):
"""
Platform specific options.
Platform specific options.
Note each of these fields supports the same keys as the top-level :class:`MenuItem`
(sans ``platforms`` itself), in case overrides are needed.
"""
Expand Down
10 changes: 5 additions & 5 deletions menuinst/api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""
"""

from os import PathLike
import json
import sys
from typing import Union, List, Tuple, Literal, Optional, Callable, Any
from pathlib import Path
import warnings
import json
from logging import getLogger
from os import PathLike
from pathlib import Path
from typing import Any, Callable, List, Literal, Optional, Tuple, Union

from .platforms import Menu, MenuItem
from .utils import elevate_as_needed, DEFAULT_PREFIX, DEFAULT_BASE_PREFIX
from .utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX, elevate_as_needed

log = getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion menuinst/data/menuinst.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@
}
}
]
}
}
6 changes: 3 additions & 3 deletions menuinst/data/menuinst.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"definitions": {
"Linux": {
"title": "Linux",
"description": "Linux-specific instructions. \n\nCheck the `Desktop entry specification <desktop-entry-spec>`__ for more details.\n\n.. desktop-entry-spec: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys",
"description": "Linux-specific instructions.\n\nCheck the `Desktop entry specification <desktop-entry-spec>`__ for more details.\n\n.. desktop-entry-spec: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#recognized-keys",
"type": "object",
"properties": {
"name": {
Expand Down Expand Up @@ -501,7 +501,7 @@
},
"Platforms": {
"title": "Platforms",
"description": "Platform specific options. \n\nNote each of these fields supports the same keys as the top-level :class:`MenuItem`\n(sans ``platforms`` itself), in case overrides are needed.",
"description": "Platform specific options.\n\nNote each of these fields supports the same keys as the top-level :class:`MenuItem`\n(sans ``platforms`` itself), in case overrides are needed.",
"type": "object",
"properties": {
"linux": {
Expand Down Expand Up @@ -581,4 +581,4 @@
"additionalProperties": false
}
}
}
}
12 changes: 8 additions & 4 deletions menuinst/platforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import sys
from typing import Tuple

from .base import Menu as BaseMenu, MenuItem as BaseMenuItem
from .base import Menu as BaseMenu
from .base import MenuItem as BaseMenuItem


def menu_api_for_platform(platform: str = sys.platform) -> Tuple[BaseMenu, BaseMenuItem]:
if platform == "win32":
from .win import WindowsMenu as Menu, WindowsMenuItem as MenuItem
from .win import WindowsMenu as Menu
from .win import WindowsMenuItem as MenuItem

elif platform == "darwin":
from .osx import MacOSMenu as Menu, MacOSMenuItem as MenuItem
from .osx import MacOSMenu as Menu
from .osx import MacOSMenuItem as MenuItem

elif platform.startswith("linux"):
from .linux import LinuxMenu as Menu, LinuxMenuItem as MenuItem
from .linux import LinuxMenu as Menu
from .linux import LinuxMenuItem as MenuItem

else:
raise ValueError(f"platform {platform} is not supported")
Expand Down
Loading

0 comments on commit 424a670

Please sign in to comment.