Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into integrate-curses
Browse files Browse the repository at this point in the history
  • Loading branch information
svartkanin committed Aug 31, 2024
2 parents 60b1d9f + 342122e commit f5be970
Show file tree
Hide file tree
Showing 137 changed files with 3,210 additions and 1,877 deletions.
7 changes: 4 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[flake8]
count = True
# Several of the following could be autofixed or improved by running the code through psf/black
ignore = E123,E126,E128,E203,E231,E261,E302,E402,E722,F541,W191,W292,W293,W503,W504
ignore = E123,E128,E722,W191,W503,W504
max-complexity = 40
max-line-length = 236
max-line-length = 220
show-source = True
statistics = True
builtins = _
per-file-ignores = __init__.py:F401,F403,F405 simple_menu.py:C901,W503 guided.py:C901 network_configuration.py:F821
per-file-ignores = __init__.py:F401
exclude = .git,__pycache__,build,docs,actions-runner
2 changes: 1 addition & 1 deletion .github/workflows/flake8.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on: [ push, pull_request ]
name: flake8 linting (15 ignores)
name: flake8 linting (6 ignores)
jobs:
flake8:
runs-on: ubuntu-latest
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ jobs:
- run: python --version
- run: mypy --version
- name: run mypy
run: mypy --config-file pyproject.toml
- name: run mypy strict
run: mypy --config-file mypy.ini
run: mypy
2 changes: 1 addition & 1 deletion .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
pacman-key --init
pacman --noconfirm -Sy archlinux-keyring
pacman --noconfirm -Syyu
pacman --noconfirm -Sy python-pip python-pyparted python-simple-term-menu pkgconfig gcc
pacman --noconfirm -Sy python-pip python-pydantic python-pyparted python-simple-term-menu pkgconfig gcc
- name: Install build dependencies
run: |
python -m pip install --break-system-packages --upgrade pip
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
on: [ push, pull_request ]
name: ruff linting
jobs:
ruff:
runs-on: ubuntu-latest
container:
image: archlinux/archlinux:latest
steps:
- uses: actions/checkout@v4
- run: pacman --noconfirm -Syu ruff
- name: Lint with ruff
run: ruff check
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ venv
/*.sig
/*.json
requirements.txt
/.gitconfig
/actions-runner
/cmd_output.txt
9 changes: 6 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ repos:
- id: check-ast # Simply check whether files parse as valid python
- id: check-docstring-first # Checks for a common error of placing code before the docstring
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
args: [--config=.flake8]
fail_fast: true
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.11.2
hooks:
- id: mypy
args: [--config=pyproject.toml]
fail_fast: true
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
hooks:
- id: ruff
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The exceptions to PEP8 are:
* Archinstall uses [tabs instead of spaces](https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) simply to make it
easier for non-IDE developers to navigate the code *(Tab display-width should be equal to 4 spaces)*. Exception to the
rule are comments that need fine-tuned indentation for documentation purposes.
* [Line length](https://www.python.org/dev/peps/pep-0008/#maximum-line-length) a maximum line length is enforced via flake8 with 236 characters
* [Line length](https://www.python.org/dev/peps/pep-0008/#maximum-line-length) a maximum line length is enforced via flake8 with 220 characters
* [Line breaks before/after binary operator](https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator)
is not enforced, as long as the style of line breaks is consistent within the same code block.
* Archinstall should always be saved with **Unix-formatted line endings** and no other platform-specific formats.
Expand All @@ -40,7 +40,7 @@ There might therefore be older code which does not follow the coding convention

## Git hooks

`archinstall` ships pre-commit hooks that make it easier to run check such as `mypy` and `flake8` locally.
`archinstall` ships pre-commit hooks that make it easier to run checks such as `mypy`, `ruff check`, and `flake8` locally.
The checks are listed in `.pre-commit-config.yaml` and can be installed via
```
pre-commit install
Expand Down
1 change: 1 addition & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ depends=(
'pciutils'
'procps-ng'
'python'
'python-pydantic'
'python-pyparted'
'python-simple-term-menu'
'systemd'
Expand Down
51 changes: 24 additions & 27 deletions archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
_: Any


__version__ = "2.8.1"
__version__ = "2.8.6"
storage['__version__'] = __version__

# add the custom _ as a builtin, it can now be used anywhere in the
Expand All @@ -62,7 +62,7 @@
parser = ArgumentParser()


def define_arguments():
def define_arguments() -> None:
"""
Define which explicit arguments do we allow.
Refer to https://docs.python.org/3/library/argparse.html for documentation and
Expand Down Expand Up @@ -117,12 +117,13 @@ def parse_unspecified_argument_list(unknowns: list, multiple: bool = False, err:
argument value value ...
which isn't am error if multiple is specified
"""
tmp_list = unknowns[:] # wastes a few bytes, but avoids any collateral effect of the destructive nature of the pop method()
tmp_list = [arg for arg in unknowns if arg != "="] # wastes a few bytes, but avoids any collateral effect of the destructive nature of the pop method()
config = {}
key = None
last_key = None
while tmp_list:
element = tmp_list.pop(0) # retrieve an element of the list

if element.startswith('--'): # is an argument ?
if '=' in element: # uses the arg=value syntax ?
key, value = [x.strip() for x in element[2:].split('=', 1)]
Expand All @@ -132,23 +133,19 @@ def parse_unspecified_argument_list(unknowns: list, multiple: bool = False, err:
else:
key = element[2:]
config[key] = True # every argument starts its lifecycle as boolean
else:
if element == '=':
continue
if key:
config[key] = element
last_key = key # multiple
key = None
elif key:
config[key] = element
last_key = key # multiple
key = None
elif multiple and last_key:
if isinstance(config[last_key], str):
config[last_key] = [config[last_key], element]
else:
if multiple and last_key:
if isinstance(config[last_key], str):
config[last_key] = [config[last_key], element]
else:
config[last_key].append(element)
elif err:
raise ValueError(f"Entry {element} is not related to any argument")
else:
print(f" We ignore the entry {element} as it isn't related to any argument")
config[last_key].append(element)
elif err:
raise ValueError(f"Entry {element} is not related to any argument")
else:
print(f" We ignore the entry {element} as it isn't related to any argument")
return config


Expand Down Expand Up @@ -215,7 +212,7 @@ def get_arguments() -> Dict[str, Any]:
return config


def load_config():
def load_config() -> None:
"""
refine and set some arguments. Formerly at the scripts
"""
Expand Down Expand Up @@ -265,7 +262,7 @@ def load_config():
)


def post_process_arguments(arguments):
def post_process_arguments(arguments: dict[str, Any]) -> None:
storage['arguments'] = arguments
if mountpoint := arguments.get('mount_point', None):
storage['MOUNT_POINT'] = Path(mountpoint)
Expand All @@ -287,18 +284,18 @@ def post_process_arguments(arguments):

# @archinstall.plugin decorator hook to programmatically add
# plugins in runtime. Useful in profiles_bck and other things.
def plugin(f, *args, **kwargs):
def plugin(f, *args, **kwargs) -> None:
plugins[f.__name__] = f


def _check_new_version():
def _check_new_version() -> None:
info("Checking version...")

try:
Pacman.run("-Sy")
except Exception as e:
debug(f'Failed to perform version check: {e}')
info(f'Arch Linux mirrors are not reachable. Please check your internet connection')
info('Arch Linux mirrors are not reachable. Please check your internet connection')
exit(1)

upgrade = None
Expand All @@ -314,7 +311,7 @@ def _check_new_version():
time.sleep(3)


def main():
def main() -> None:
"""
This can either be run as the compiled and installed application: python setup.py install
OR straight as a module: python -m archinstall
Expand All @@ -333,7 +330,7 @@ def main():
importlib.import_module(mod_name)


def _shutdown_curses():
def _shutdown_curses() -> None:
try:
curses.nocbreak()

Expand All @@ -351,7 +348,7 @@ def _shutdown_curses():
pass


def run_as_a_module():
def run_as_a_module() -> None:
exc = None

try:
Expand Down
6 changes: 3 additions & 3 deletions archinstall/default_profiles/applications/pipewire.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class PipewireProfile(Profile):
def __init__(self):
def __init__(self) -> None:
super().__init__('Pipewire', ProfileType.Application)

@property
Expand All @@ -26,15 +26,15 @@ def packages(self) -> List[str]:
'wireplumber'
]

def _enable_pipewire_for_all(self, install_session: 'Installer'):
def _enable_pipewire_for_all(self, install_session: 'Installer') -> None:
users: Union[User, List[User]] = archinstall.arguments.get('!users', [])
if not isinstance(users, list):
users = [users]

for user in users:
install_session.arch_chroot('systemctl enable --user pipewire-pulse.service', run_as=user.username)

def install(self, install_session: 'Installer'):
def install(self, install_session: 'Installer') -> None:
super().install(install_session)
install_session.add_additional_packages(self.packages)
self._enable_pipewire_for_all(install_session)
13 changes: 6 additions & 7 deletions archinstall/default_profiles/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from archinstall.tui import (
MenuItemGroup, MenuItem, SelectMenu,
FrameProperties, FrameStyle, Alignment,
ResultType, EditMenu, PreviewStyle
FrameProperties, ResultType, PreviewStyle
)

if TYPE_CHECKING:
Expand All @@ -16,7 +15,7 @@


class DesktopProfile(Profile):
def __init__(self, current_selection: List[Profile] = []):
def __init__(self, current_selection: List[Profile] = []) -> None:
super().__init__(
'Desktop',
ProfileType.Desktop,
Expand Down Expand Up @@ -53,7 +52,7 @@ def default_greeter_type(self) -> Optional[GreeterType]:

return None

def _do_on_select_profiles(self):
def _do_on_select_profiles(self) -> None:
for profile in self.current_selection:
profile.do_on_select()

Expand Down Expand Up @@ -94,15 +93,15 @@ def do_on_select(self) -> Optional[SelectResult]:

return None

def post_install(self, install_session: 'Installer'):
def post_install(self, install_session: 'Installer') -> None:
for profile in self._current_selection:
profile.post_install(install_session)

def install(self, install_session: 'Installer'):
def install(self, install_session: 'Installer') -> None:
# Install common packages for all desktop environments
install_session.add_additional_packages(self.packages)

for profile in self._current_selection:
for profile in self.current_selection:
info(f'Installing profile {profile.name}...')

install_session.add_additional_packages(profile.packages)
Expand Down
6 changes: 3 additions & 3 deletions archinstall/default_profiles/desktops/awesome.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class AwesomeProfile(XorgProfile):
def __init__(self):
def __init__(self) -> None:
super().__init__('Awesome', ProfileType.WindowMgr, description='')

@property
Expand All @@ -28,7 +28,7 @@ def packages(self) -> List[str]:
'xsel',
]

def install(self, install_session: 'Installer'):
def install(self, install_session: 'Installer') -> None:
super().install(install_session)

# TODO: Copy a full configuration to ~/.config/awesome/rc.lua instead.
Expand Down Expand Up @@ -60,4 +60,4 @@ def install(self, install_session: 'Installer'):
xinitrc_data += 'exec awesome\n'

with open(f"{install_session.target}/etc/X11/xinit/xinitrc", 'w') as xinitrc:
xinitrc.write(xinitrc_data)
xinitrc.write(xinitrc_data)
2 changes: 1 addition & 1 deletion archinstall/default_profiles/desktops/bspwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class BspwmProfile(XorgProfile):
def __init__(self):
def __init__(self) -> None:
super().__init__('Bspwm', ProfileType.WindowMgr, description='')

@property
Expand Down
2 changes: 1 addition & 1 deletion archinstall/default_profiles/desktops/budgie.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class BudgieProfile(XorgProfile):
def __init__(self):
def __init__(self) -> None:
super().__init__('Budgie', ProfileType.DesktopEnv, description='')

@property
Expand Down
11 changes: 8 additions & 3 deletions archinstall/default_profiles/desktops/cinnamon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class CinnamonProfile(XorgProfile):
def __init__(self):
def __init__(self) -> None:
super().__init__('Cinnamon', ProfileType.DesktopEnv, description='')

@property
Expand All @@ -18,8 +18,13 @@ def packages(self) -> List[str]:
"system-config-printer",
"gnome-keyring",
"gnome-terminal",
"blueberry",
"metacity"
"blueman",
"bluez-utils",
"engrampa",
"gnome-screenshot",
"gvfs-smb",
"xed",
"xdg-user-dirs-gtk"
]

@property
Expand Down
Loading

0 comments on commit f5be970

Please sign in to comment.