abravalheri / ini2toml

Automatically conversion of `.ini/.cfg` files to TOML equivalents
https://ini2toml.readthedocs.io/en/latest
Mozilla Public License 2.0
54 stars 8 forks source link

AttributeError: 'bool' object has no attribute 'splitlines' #80

Closed mtelka closed 1 year ago

mtelka commented 1 year ago

I'm packaging ini2toml 0.12 for OpenIndiana. I ran tests and I found that three tests fails:

=========================== short test summary info ============================
FAILED tests/test_examples.py::test_examples_api_lite[tests/examples/django/setup.cfg-tests/examples/django/pyproject.toml]
FAILED tests/test_examples.py::test_examples_api[tests/examples/django/setup.cfg-tests/examples/django/pyproject.toml]
FAILED tests/test_examples.py::test_examples_cli[tests/examples/django/setup.cfg-tests/examples/django/pyproject.toml]

All failures are similar:

_ test_examples_api_lite[tests/examples/django/setup.cfg-tests/examples/django/pyproject.toml] _

original = 'tests/examples/django/setup.cfg'
expected = 'tests/examples/django/pyproject.toml'
validate = <validate_pyproject.api.Validator object at 0x7fffa8059d30>

    @pytest.mark.filterwarnings("ignore::DeprecationWarning")
    @pytest.mark.parametrize(("original", "expected"), list(examples()))
    def test_examples_api_lite(original, expected, validate):
        opts = {"ini_loads_fn": configparser.parse, "toml_dumps_fn": lite_toml.convert}
        translator = Translator(**opts)
        available_profiles = list(translator.profiles.keys())
        profile = cli.guess_profile(None, original, available_profiles)
        # We cannot compare "flake8" sections (currently not handled)
        # (ConfigParser automatically strips comments, contrary to ConfigUpdater)
        orig = Path(original)

        # Make sure file ends in a newline (requirement for posix text files)
>       translated = translator.translate(orig.read_text(encoding="utf-8"), profile)

tests/test_examples.py:75:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/base_translator.py:154: in translate
    irepr = reduce(apply, profile.intermediate_processors, irepr)
../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/transformations.py:325: in apply
    return fn(x)
../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/plugins/setuptools_pep621.py:663: in pep621_transform
    out = reduce(apply, transformations, out)
../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/transformations.py:325: in apply
    return fn(x)
../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/plugins/setuptools_pep621.py:588: in parse_setup_py_command_options
    section = self._be.apply_best_effort_to_section(doc[k])
../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/plugins/best_effort.py:47: in apply_best_effort_to_section
    self.apply_best_effort(section, field, value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <ini2toml.plugins.best_effort.BestEffort object at 0x7fffa7de0e50>
container = IntermediateRepr(
    elements={'combine_as_imports': True,
     'default_section': 'THIRDPARTY',
     'include_traili...clude_trailing_comma',
     'known_first_party',
     'line_length',
     'multi_line_output'],
    inline_comment=''
)
field = 'combine_as_imports', value = True

    def apply_best_effort(self, container: M, field: str, value: str):
        if isinstance(field, HiddenKey):
            return
>       lines = value.splitlines()
E       AttributeError: 'bool' object has no attribute 'splitlines'

../prototype/i386/usr/lib/python3.9/vendor-packages/ini2toml/plugins/best_effort.py:53: AttributeError

Please note there is no django installed.

abravalheri commented 1 year ago

Hi @mtelka thank you for the issue. Can you share how you are running the tests starting from the vanilla code on the GitHub repo?

I cannot reproduce this failure with the following example:

> docker run --rm -it python:3.9-bullseye /bin/bash
cd /tmp
git clone https://github.com/abravalheri/ini2toml
cd ini2toml
python3 -m venv .venv
.venv/bin/python -m pip install -U pip tox
.venv/bin/tox
> docker run --rm -it python:3.9-bullseye
cd /tmp
git clone https://github.com/abravalheri/ini2toml
cd ini2toml
python3 -m venv .venv
.venv/bin/python -m pip install -U pip tox
.venv/bin/tox
# ...
# ================================================= 100 passed in 3.59s =================================================
# .pkg: _exit> python /tmp/ini2toml/.venv/lib/python3.9/site-packages/pyproject_api/_backend.py True setuptools.build_meta
#   default: OK (16.18=setup[12.30]+cmd[3.89] seconds)
#   congratulations :) (16.25 seconds)
mtelka commented 1 year ago

Reproducer:

$ git clone https://github.com/abravalheri/ini2toml.git
$ cd ini2toml/
$ git reset --hard v0.12
$ PYTEST_ADDOPTS="-p no:checkdocs" tox --current-env --no-provision --recreate -e py39

Please note that with the checkdocs plugin enabled one more test fails too. When I test with HEAD instead of v0.12 tag even more tests fails. It looks like all new failures are related to newly added dynamic_extras and dynamic_extras_mixed tests.

This is likely very important:

$ pip3.9 freeze
aiosignal==1.3.1
alabaster==0.7.13
ansible==7.5.0
ansible-core==2.14.5
appdirs==1.4.4
argcomplete==2.0.0
argh==0.28.1
asgiref==3.6.0
asn1crypto==1.5.1
astor==0.8.1
astroid==2.15.4
asttokens==2.2.1
async-generator==1.10
async-timeout==4.0.2
atomicwrites==1.4.1
attrs==23.1.0
autocommand==2.2.2
Automat==22.10.0
autopage==0.5.1
Babel==2.12.1
backcall==0.2.0
backports-abc==0.5
backports.cached-property==1.0.2
backports.entry-points-selectable==1.2.0
backports.functools-lru-cache==1.6.4
backports.ssl-match-hostname==3.7.0.1
backports.unittest-mock==1.5
barman==3.5.0
bcrypt==3.2.2
beautifulsoup4==4.12.2
black==23.3.0
bleach==6.0.0
blinker==1.6.2
borgbackup==1.2.4
bottle==0.12.25
build==0.10.0
CacheControl==0.12.11
cached-property==1.5.2
cachetools==5.3.0
calver==2022.6.26
ccsm==0.8.18
certifi==2022.12.7
cffi==1.15.1
cfgv==3.3.1
Chameleon==4.0.0
characteristic==14.3.0
chardet==5.1.0
charset-normalizer==3.1.0
check-manifest==0.49
cheroot==9.0.0
CherryPy==18.8.0
chevron==0.14.0
CJKwrap==2.2
click==8.1.3
cliff==4.2.0
cloudpickle==2.2.1
cmarkgfm==2022.10.27
cmd2==2.4.3
codecov==2.1.13
colorama==0.4.6
colorlog==6.7.0
commonmark==0.9.1
configobj==5.0.8
ConfigUpdater==3.1.1
constantly==15.1.0
contextlib2==21.6.0
covdefaults==2.3.0
coverage==7.2.5
coverage-enable-subprocess==1.0
coveralls==3.3.1
crashtest==0.4.1
crmsh==4.0.0
cryptography==3.2.1
cryptography-vectors==39.0.1
cupshelpers==1.0
curio==1.6
Cython==0.29.33
cython-test-exception-raiser==1.0.2
dbus-python==1.3.2
ddt==1.6.0
decorator==5.1.1
defusedxml==0.7.1
diff-cover==7.5.0
dill==0.3.6
distlib==0.3.6
distro==1.8.0
dnspython==2.3.0
docopt==0.6.2
docutils==0.19
dogpile.cache==1.2.0
editables==0.3
elastic-transport==8.4.0
elasticsearch==8.7.0
elementpath==4.1.1
ephemeral-port-reserve==1.1.4
exceptiongroup==1.1.1
execnet==1.9.0
executing==1.2.0
extras==1.0.0
fastjsonschema==2.16.3
fields==5.0.0
filelock==3.12.0
findpython==0.2.4
fixtures==4.0.1
flake8==6.0.0
flake8-2020==1.7.0
flake8-bugbear==23.3.23
flake8-noqa==1.3.1
flake8-typing-imports==1.14.0
flaky==3.7.0
flamegraph==0.1
flit_core==3.8.0
flit_scm==1.7.0
flufl.flake8==0.10
freezegun==1.2.2
frozendict==2.3.8
frozenlist==1.3.3
fs==2.4.16
func-timeout==4.3.5
future==0.18.3
ghp-import==2.1.0
gi-docgen==2023.1
gprof2dot==2022.7.29
graphviz==0.20.1
greenlet==2.0.2
hatch-fancy-pypi-readme==22.8.0
hatch-nodejs-version==0.3.1
hatch-vcs==0.3.0
hatchling==1.14.1
http-parser==0.9.0
humanize==4.6.0
hupper==1.12
hyperlink==21.0.0
hypothesis==6.75.1
icecream==2.1.3
identify==2.5.23
idna==3.4
imagesize==1.4.1
importlib-metadata==6.6.0
importlib-resources==5.12.0
incremental==22.10.0
inflect==6.0.4
ini2toml==0.12
iniconfig==2.0.0
installer==0.7.0
iocapture==0.1.2
ipython==8.13.1
iso8601==1.1.0
isort==5.12.0
itsdangerous==2.1.2
jaraco.classes==3.2.3
jaraco.collections==4.1.0
jaraco.context==4.3.0
jaraco.envs==2.4.0
jaraco.functools==3.6.0
jaraco.itertools==6.2.1
jaraco.path==3.5.0
jaraco.test==5.3.0
jaraco.text==3.11.1
jedi==0.18.2
Jinja2==3.1.2
jmespath==1.0.1
jsonrpclib-pelix==0.4.3.2
jsonschema==4.17.3
jupyter_core==5.3.0
keyring==23.13.1
keyrings.alt==4.2.0
kgb==7.1.1
lazy==1.5
lazy-object-proxy==1.9.0
lingua==4.15.0
linkify-it-py==2.0.2
littleutils==0.2.2
louis==3.25.0
lxml==4.9.2
Mako==1.2.4
Markdown==3.4.3
markdown-it-py==2.2.0
markdown2==2.4.8
MarkupSafe==2.1.2
matplotlib-inline==0.1.6
mccabe==0.7.0
mdurl==0.1.2
mercurial==5.9.3
mergedeep==1.3.4
meson==1.1.0
mkdocs==1.4.3
mkdocs-bootstrap==1.1
mkdocs-bootswatch==1.1
mock==5.0.2
more-itertools==9.1.0
msgpack==1.0.5
multidict==6.0.4
mypy==1.2.0
mypy-extensions==1.0.0
mysqlclient==2.1.1
natsort==8.3.1
nbformat==5.8.0
netsnmp-python==1.0a1
nodeenv==1.7.0
nose==1.3.7
notify2==0.3.1
nox==2022.11.21
objgraph==3.5.0
olefile==0.46
outcome==1.2.0
packaging==23.1
parameterized==0.8.1
paramiko==3.1.0
parso==0.8.3
Paste==3.5.3
PasteDeploy==3.0.1
path==16.6.0
path.py==12.5.0
pathlib2==2.3.7.post1
pathspec==0.11.1
pbr==5.11.1
pdm-pep517==1.1.4
pep440==0.1.2
pep517==0.13.0
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
pip-run==10.0.7
pipdeptree==2.7.0
pkg==0.1
pkgconfig==1.5.5
pkginfo==1.9.6
pkgutil_resolve_name==1.3.10
plaster==1.1.2
plaster-pastedeploy==1.0.1
platformdirs==3.5.0
pluggy==1.0.0
ply==3.11
poetry-core==1.5.2
polib==1.2.0
portend==3.1.0
powerline-status==2.8.2
pre-commit==3.3.0
pretend==1.0.9
prettytable==3.7.0
process-tests==2.1.2
prompt-toolkit==3.0.38
psutil==5.9.0
psycopg2==2.9.6
ptyprocess==0.7.0
pure-eval==0.2.2
py==1.11.0
py-cpuinfo==9.0.0
py3c==1.4
pyasn1==0.5.0
pyasn1-modules==0.3.0
pybind11==2.9.2
pybonjour==1.1.1
pycairo==1.23.0
pycmd==1.2
pycodestyle==2.10.0
PyContracts==2.0.1
pycparser==2.21
pycryptodome-test-vectors==1.0.12
pycups==2.0.1
pycurl==7.45.2
pydantic==1.10.7
pydiffx==1.1
pydocstyle==6.3.0
pyfakefs==5.2.2
pyflakes==3.0.1
pyftpdlib==1.5.7
Pygments==2.15.1
PyGObject==3.42.0
PyHamcrest==2.0.4
pylint==2.12.2
pymongo==4.3.3
PyNaCl==1.5.0
pyOpenSSL==19.0.0
pyparsing==3.0.9
pyperclip==1.8.2
pyproject-fmt==0.11.1
pyproject-installer==0.5.0
pyproject-metadata==0.7.1
pyproject_api==1.5.1
pyproject_hooks==1.0.0
PyQt-builder==1.12.2
PyQt5==5.15.6
PyQt5-sip==12.10.1
Pyro4==4.82
pyroma==4.2
pyrsistent==0.19.3
PySocks==1.7.1
pytest==7.3.1
pytest-asyncio==0.21.0
pytest-benchmark==4.0.0
pytest-black==0.3.12
pytest-black-multipy==1.0.1
pytest-checkdocs==2.9.0
pytest-console-scripts==1.3.1
pytest-cov==4.0.0
pytest-datadir==1.4.1
pytest-enabler==2.1.0
pytest-env==0.8.1
pytest-expect==1.1.0
pytest-fixture-config==1.7.0
pytest-flake8==1.1.1
pytest-forked==1.6.0
pytest-freezegun==0.4.2
pytest-lazy-fixture==0.6.3
pytest-mock==3.7.0
pytest-mypy==0.10.3
pytest-mypy-plugins==1.10.1
pytest-perf==0.12.0
pytest-randomly==3.12.0
pytest-regressions==2.4.2
pytest-reporter==0.5.2
pytest-socket==0.6.0
pytest-subtests==0.10.0
pytest-timeout==2.0.2
pytest-travis-fold==1.3.0
pytest-xdist==3.1.0
python-dateutil==2.8.2
python-dotenv==1.0.0
python-magic==0.4.27
python-rapidjson==1.10
python-xlib==0.33
pytidylib==0.3.2
pytz==2023.3
pyxdg==0.28
PyYAML==6.0
pyyaml_env_tag==0.1
pyzmq==25.0.0
qualname==0.1.0
RBTools==4.0
re-assert==1.1.0
readme-renderer==37.3
readthedocs-sphinx-ext==2.2.0
redis==3.5.3
regex==2023.5.4
repoze.lru==0.7
repoze.sphinx.autointerface==1.0.0
requests==2.29.0
requests-toolbelt==1.0.0
resolvelib==1.0.1
rfc3986==2.0.0
rich==13.3.5
Routes==2.5.1
rrdtool==0.1.10
ruamel.yaml==0.17.22
ruamel.yaml.clib==0.2.7
schema==0.7.5
SCons==4.4.0
semantic-version==2.10.0
serpent==1.41
service-identity==21.1.0
setuptools-rust==1.5.2
setuptools-scm==7.1.0
setuptools-scm-git-archive==1.4
sh==1.14.3
shellingham==1.5.0.post1
simplegeneric==0.8.1
simplejson==3.19.1
singledispatch==4.0.0
sip==6.6.1
six==1.16.0
smartypants==2.0.1
smmap==5.0.0
sniffio==1.3.0
snowballstemmer==2.2.0
sortedcontainers==2.4.0
soupsieve==2.4.1
Sphinx==7.0.0
sphinx-issues==3.0.1
sphinx-rtd-theme==1.2.0
sphinxcontrib-applehelp==1.0.4
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.1
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
sqlparse==0.4.4
stack-data==0.6.2
stevedore==5.0.0
strictyaml==1.7.3
tabulate==0.9.0
teamcity-messages==1.32
tempora==5.2.2
termcolor==2.3.0
terminator==2.1.1
termstyle==0.1.11
testpath==0.6.0
testresources==2.0.1
testscenarios==0.5.0
testtools==2.6.0
texttable==1.6.7
time-machine==2.9.0
tokenize-rt==5.0.0
toml==0.10.2
tomli==2.0.1
tomli_w==1.0.0
tomlkit==0.11.8
tornado==6.3.1
tox==4.5.1
tox-current-env==0.0.11
tox-gh-actions==3.1.0
tqdm==4.65.0
traitlets==5.9.0
translationstring==1.4
trove-classifiers==2023.5.2
trustme==1.0.0
twine==4.0.2
Twisted==22.10.0
typed-ast==1.5.4
typeguard==3.0.2
types-docutils==0.19.1.8
types-freezegun==1.1.10
types-mock==5.0.0.6
types-psutil==5.9.5.12
types-pytz==2023.3.0.0
types-PyYAML==6.0.12.9
types-setuptools==67.7.0.1
types-toml==0.10.8.6
types-typed-ast==1.5.8.6
typing_extensions==4.5.0
typogrify==2.0.7
tzdata==2023.3
u-msgpack-python==2.7.2
uc-micro-py==1.0.2
Unidecode==1.3.6
urllib3==2.0.1
validate-pyproject==0.12.2
validators==0.20.0
venusian==3.0.0
virtualenv==20.23.0
voluptuous==0.13.1
waitress==2.1.2
watchdog==3.0.0
wcag-contrast-ratio==0.9
wcwidth==0.2.6
webencodings==0.5.1
WebOb==1.8.7
WebTest==3.0.0
wrapt==1.15.0
xmlschema==2.2.3
youtube-dl==2021.1.8
zc.lockfile==3.0.post1
zest.releaser==7.3.0
zipp==3.15.0
zope.deprecation==5.0
zope.event==4.6
zope.exceptions==4.6
zope.interface==5.5.2
zope.testing==5.0.1
zope.testrunner==6.0
zstd==1.5.5.1
$