Skip to content

Commit

Permalink
fix: Support maison 2.0.0
Browse files Browse the repository at this point in the history
Closes #258
  • Loading branch information
cjwatson committed Aug 26, 2024
1 parent 77e3044 commit 988b6a0
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/autoimport/entrypoints/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import logging
from pathlib import Path
from typing import IO, Any, List, Optional, Sequence, Tuple, Union
from typing import IO, Any, Dict, List, Optional, Sequence, Tuple, Union

import click

# Migrate away from xdg to xdg-base-dirs once only Python >= 3.10 is supported
# https://github.com/lyz-code/autoimport/issues/239
import xdg
from maison.config import ProjectConfig

from autoimport import services, version

Expand Down Expand Up @@ -55,6 +54,27 @@ def convert(
return get_files(str(path))


def get_config(
package_name: str, source_files: Optional[List[str]] = None
) -> Dict[str, Any]:
"""Get the configuration for a package."""
# pylint: disable=import-outside-toplevel
try:
from maison.config import UserConfig # type: ignore[attr-defined,unused-ignore]

return UserConfig(
package_name=package_name, source_files=source_files, merge_configs=True
).values
except ImportError:
from maison.config import ( # type: ignore[attr-defined,unused-ignore]
ProjectConfig,
)

return ProjectConfig(
project_name=package_name, source_files=source_files, merge_configs=True
).to_dict()


@click.command()
@click.version_option(version="", message=version.version_info())
@click.option("--config-file", default=None)
Expand Down Expand Up @@ -85,9 +105,7 @@ def cli(
if config_file is not None:
config_files.append(config_file)

config = ProjectConfig(
project_name="autoimport", source_files=config_files, merge_configs=True
).to_dict()
config = get_config(package_name="autoimport", source_files=config_files)

# Process inputs
flattened_files = flatten(files)
Expand Down

0 comments on commit 988b6a0

Please sign in to comment.