ini2toml.plugins package#
Submodules#
ini2toml.plugins.best_effort module#
- class ini2toml.plugins.best_effort.BestEffort(key_sep='=', section_splitter=re.compile('\\.|:|\\\\'))[source]#
Bases:
object
Guess option value conversion based on the string format
- ini2toml.plugins.best_effort.activate(translator: Translator)[source]#
ini2toml.plugins.coverage module#
- class ini2toml.plugins.coverage.Coverage[source]#
Bases:
object
Convert settings to ‘pyproject.toml’ equivalent
- LIST_VALUES = ('exclude_lines', 'concurrency', 'disable_warnings', 'debug', 'include', 'omit', 'plugins', 'source', 'source_pkgs', 'partial_branches')#
- PREFIX = 'coverage:'#
- SECTIONS = ('run', 'paths', 'report', 'html', 'xml', 'json')#
- ini2toml.plugins.coverage.activate(translator: Translator)[source]#
ini2toml.plugins.isort module#
- class ini2toml.plugins.isort.ISort[source]#
Bases:
object
Convert settings to ‘pyproject.toml’ equivalent
- FIELDS = {'add_imports', 'classes', 'constants', 'force_to_top', 'forced_separate', 'length_sort_sections', 'namespace_packages', 'no_lines_before', 'remove_imports', 'sections', 'sources', 'treat_comments_as_code', 'variables'}#
- FIELD_ENDS = ['skip', 'glob', 'paths', 'exclusions', 'plugins']#
- FIELD_STARTS = ['known', 'extra']#
- ini2toml.plugins.isort.activate(translator: Translator)[source]#
ini2toml.plugins.mypy module#
- class ini2toml.plugins.mypy.Mypy[source]#
Bases:
object
Convert settings to ‘pyproject.toml’ equivalent
- DONT_TOUCH = ('python_version',)#
- LIST_VALUES = ('files', 'always_false', 'disable_error_code', 'plugins')#
- get_or_create_overrides(parent: MutableMapping) MutableSequence [source]#
- process_overrides(section: R, overrides: MutableSequence, name: str) R [source]#
- ini2toml.plugins.mypy.activate(translator: Translator)[source]#
ini2toml.plugins.profile_independent_tasks module#
Profile-independent tasks implemented via profile augmentation.
- ini2toml.plugins.profile_independent_tasks.activate(translator: Translator)[source]#
ini2toml.plugins.pytest module#
- class ini2toml.plugins.pytest.Pytest[source]#
Bases:
object
Convert settings to ‘pyproject.toml’ (‘ini_options’ table)
- DONT_TOUCH = ('minversion',)#
- LINE_SEPARATED_LIST_VALUES = ('markers', 'filterwarnings')#
- SPACE_SEPARATED_LIST_VALUES = ('norecursedirs', 'python_classes', 'python_files', 'python_functions', 'required_plugins', 'testpaths', 'usefixtures')#
- process_section(section: MutableMapping)[source]#
- ini2toml.plugins.pytest.activate(translator: Translator)[source]#
ini2toml.plugins.setuptools_pep621 module#
- class ini2toml.plugins.setuptools_pep621.Directive(kind: str, args: Any)[source]#
Bases:
dict
Represent a setuptools’ setup.cfg directive (e.g ‘file:’, ‘attr:’)
In TOML these directives can be represented as dict-like objects, however in the conversion algorithm we need to be able to differentiate between them. By inheriting from dict, we can use directive classes interchangeably but also check using isinstance(obj, Directive).
- ini2toml.plugins.setuptools_pep621.ENV_MARKER = re.compile(';\\s*(python|platform|implementation|os|sys)[_.]', re.MULTILINE)#
Simplified regex for PEP 508 markers that can be used in
setup.cfg
- class ini2toml.plugins.setuptools_pep621.SetuptoolsPEP621[source]#
Bases:
object
Convert settings to ‘pyproject.toml’ based on PEP 621
- BUILD_REQUIRES = ('setuptools>=61.2',)#
- apply_value_processing(doc: R) R [source]#
Process
setup.cfg
values according toprocessing_rules()
anddependent_processing_rules()
.This function assumes all field names were normalised by
normalise_keys()
.
- dependent_processing_rules(doc: IntermediateRepr) Dict[Tuple[str, ...], Callable[[str], Any] | Callable[[M], M]] [source]#
Dynamically create processing rules, such as
processing_rules()
based on the existing document.
- ensure_pep518(doc: R) R [source]#
PEP 518 specifies that any other tool adding configuration under
pyproject.toml
should use thetool
table. This means that the only top-level keys arebuild-system
,project
andtool
.
- fix_extras_require(doc: R) R [source]#
extras-require can have markers embedded in the extra group they need to be removed and added to the dependencies themselves
- handle_dynamic(doc: R) R [source]#
All the configuration fields in PEP 621 that are dynamically discovered at build time have to be explicitly list in
dynamic
. This function moves directive usages (e.g.file:
andattr:
) to a tool-specific subtable (tool.setuptools.dynamic
), and add the corresponding field todynamic
. Sinceversion
is a mandatory core metadata, it will be added todynamic
when not explicitly set (in that case plugins such assetuptools_scm
are expected to provide a value at runtime).
- handle_license(doc: R) R [source]#
In PEP 621 we have a single field for license, which is not compatible with setuptools
license-files
. This field is meant to fill theLicense
core metadata as a plain license text (not a path to a file). Even when theproject.license.file
table field is given, the idea is that the file should be expanded into text.This will likely change once PEP 639 is accepted. Meanwhile we have to translate
license-files
into a setuptools specific configuration.
- handle_packages_find(doc: R) R [source]#
setup.cfg
uses a option + a section to defineoptions.packages.find
and itsfind_namespace
variant. This does not work very well with the convention used for the TOML encoding, since the option and the section would end up with the same name (and overwriting each other). Therefore we need to “merge” them.
- merge_and_rename_long_description_and_content_type(doc: R) R [source]#
PEP 621 offers a single field (
readme
) to cover things present in two fields insetup.cfg
:long_description.file => readme.file long_description => readme.text long-description-content-type => readme.content-type
We also have to be aware that PEP 621 accepts a single file, so the option of combining multiple files as presented in
setup.cfg
have to be handled viadynamic
.
- merge_and_rename_urls(doc: R) R [source]#
The following renames can be applied when comparing setuptools metadata and PEP 621:
url => urls.homepage download-url => urls.download project-urls.* => urls.*
- merge_authors_maintainers_and_emails(doc: R) R [source]#
When transforming setuptools metadata and PEP 621, we have to merge
author/maintainer
andauthor-email/maintainer-email
into a single dict-like object with 2 keys. Some projects also provide multiple, comma separated, values for each field. In that case we assume that the value for the i-th author/maintainer should be paired with to the i-th author-email/maintainer-email value.
- move_and_split_entrypoints(doc: R) R [source]#
In
setup.cfg
there is no special treatment for entry-points that will be transformed in console/GUI scripts. On the other hand PEP 621 defines separated fields:entry-points.console-scripts => scripts entry-points.gui-scripts => gui-scripts entry-points.* => "entry-points".*
- move_options_missing_in_pep621(doc: R) R [source]#
PEP 621 specifies as project metadata values that are covered in
setup.cfg "options"
section.
- move_setup_requires(doc: R) R [source]#
Move
setup_requires
to the equivalent field in PEP 518, and add mandatory build dependencies if they are missing and
- move_tests_require(doc: R) R [source]#
Move
tests_require
to atesting
extra as optional dependency (this option is deprecated in setuptools (the test command is deprecated).It assumes
move_options_missing_in_pep621
already run (to populateproject:optional-dependencies
.
- normalise_keys(cfg: R) R [source]#
Normalise keys in
setup.cfg
, by replacing aliases with cannonic names and replacing the snake case with kebab case.
- parse_setup_py_command_options(doc: R) R [source]#
distutils
commands can accept arguments fromsetup.cfg
files. This function moves these arguments to their owndistutils
tool-specific sub-table
- pep621_transform(doc: R) R [source]#
Rules are applied sequentially and therefore can interfere with the following ones. Please notice that renaming is applied after value processing.
- processing_rules() Dict[Tuple[str, ...], Callable[[str], Any] | Callable[[M], M]] [source]#
Value type processing, as defined in: https://setuptools.pypa.io/en/stable/userguide/declarative_config.html
- remove_metadata_not_in_pep621(doc: R) R [source]#
PEP 621 does not cover all project metadata in
setup.cfg "metadata"
section. That is left as “tool” specific configuration.
- rename_script_files(doc: R) R [source]#
setuptools
define aoptions.scripts
parameters that refer to script files, not created via entry-points. To avoid confusion with PEP 621 scripts (generated via entry-points) let’s rename this field toscript-files
- setupcfg_aliases()[source]#
setup.cfg
aliases as defined in: https://setuptools.pypa.io/en/stable/userguide/declarative_config.html
- ini2toml.plugins.setuptools_pep621.activate(translator: Translator)[source]#
- ini2toml.plugins.setuptools_pep621.chain_iter(iterable, /)#
Alternative chain() constructor taking a single iterable argument that evaluates lazily.
- ini2toml.plugins.setuptools_pep621.directive(*directives: str, orelse=<function split_comment>)[source]#
partial
form ofsplit_directive()
- ini2toml.plugins.setuptools_pep621.split_deps(value: str) CommentedList [source]#
Setuptools seem to accept line continuations for markers (with comments in the middle), and that is more difficult to process. e.g.: https://github.com/jaraco/zipp
- ini2toml.plugins.setuptools_pep621.split_directive(value: str, directives: ~typing.Sequence[str] = ('file', 'attr'), orelse=<function split_comment>)[source]#
- ini2toml.plugins.setuptools_pep621.value_error(field: str)[source]#
Simply raise a
ValueError
when used as a transformation function
ini2toml.plugins.toml_incompatibilities module#
- class ini2toml.plugins.toml_incompatibilities.ReportIncompatibleSections(profile: str, sections: List[str])[source]#
Bases:
object
Remove well-know incompatible sections.
- ini2toml.plugins.toml_incompatibilities.activate(translator: Translator)[source]#
Module contents#
- exception ini2toml.plugins.ErrorLoadingPlugin(plugin: str = '', entry_point: EntryPoint | None = None)[source]#
Bases:
RuntimeError
There was an error loading ‘{plugin}’. Please make sure you have installed a version of the plugin that is compatible with {package} {version}. You can also try uninstalling it.
- ini2toml.plugins.iterate_entry_points(group='ini2toml.processing') Iterable[EntryPoint] [source]#
Produces a generator yielding an EntryPoint object for each plugin registered via setuptools entry point mechanism.
This method can be used in conjunction with
load_from_entry_point
to filter the plugins before actually loading them.
- ini2toml.plugins.list_from_entry_points(group: str = 'ini2toml.processing', filtering: ~typing.Callable[[~importlib.metadata.EntryPoint], bool] = <function <lambda>>) List[Callable[[Translator], None]] [source]#
Produces a list of plugin objects for each plugin registered via setuptools entry point mechanism.
- Parameters:
group – name of the setuptools’ entry_point group where plugins is being registered
filtering – function returning a boolean deciding if the entry point should be loaded and included (or not) in the final list. A
True
return means the plugin should be included.
- ini2toml.plugins.load_from_entry_point(entry_point: EntryPoint) Callable[[Translator], None] [source]#
Carefully load the plugin, raising a meaningful message in case of errors