Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array like string #91

Open
DataHearth opened this issue Aug 9, 2022 · 7 comments
Open

Support array like string #91

DataHearth opened this issue Aug 9, 2022 · 7 comments

Comments

@DataHearth
Copy link

Hello!

I've noticed an error when parsing a setup.cfg (you can find it here).
Outside of inline comments not supported (not a big deal), you raise an error when reading array like string: https://github.com/pypa/setuptools/blob/main/setup.cfg#L9 .

This would be great feature to add as many python projects use this kind of string.

Error: Error: 17:0 expecting "[Some('='), Some(':')]" but found EOF.

Thanks !

@zonyitoo
Copy link
Owner

zonyitoo commented Aug 9, 2022

It doesn't look like in INI format.

classifiers =
	Development Status :: 5 - Production/Stable
	Intended Audience :: Developers
	License :: OSI Approved :: MIT License
	Programming Language :: Python :: 3
	Programming Language :: Python :: 3 :: Only
	Topic :: Software Development :: Libraries :: Python Modules
	Topic :: System :: Archiving :: Packaging
	Topic :: System :: Systems Administration
	Topic :: Utilities

It looks like multi-line string in YAML.

Can Python parse it with configparser?

@DataHearth
Copy link
Author

DataHearth commented Aug 9, 2022

Setuptools and other libraries I've used don't seem to be bothered by this. This is a standard setup.cfg for python configuration file.
Many fields are using this method do achieve some sort or array with a multi-line string.

I just discovered that it wasn't really standard with ini format.

EDIT: yes, configparser does support it => https://docs.python.org/3/library/configparser.html#supported-ini-file-structure

[Multiline Values]
chorus: I'm a lumberjack, and I'm okay
    I sleep all night and I work all day

@zonyitoo
Copy link
Owner

Just read the code in configparser about multiline values. Those lines starts from the 2nd must begin with an "indentation", which is a special feature in configparser, because sections and keys can also have "indentation"s too.

I have also searched for how others ini parser support "multiline values", but seems that this is a specific feature in Python.

PRs are welcome, or I may try to implement it in weekends.

@DataHearth
Copy link
Author

Unfortunately, I'm not that good with rust. I'm just beginning and I have no clue on how rust-ini works in details 😅. Can I let you do it when you're available and willing to ?

I edited the file and made a simple string line as a workaround.

@cnpryer
Copy link

cnpryer commented May 30, 2023

Just wanted to share my interest for in multi-line parsing. I wasn't aware that this isn't an INI standard. Is this feature still on the table for rust-ini? Would be useful for astral-sh/rye#265.

@zonyitoo
Copy link
Owner

Currently not, because I don't know if there is any specification of "array like string" definition. Don't know what is the "correct" way to implement this feature.

@cnpryer
Copy link

cnpryer commented May 31, 2023

My use case is effectively what configparser would do in this situation. So I was mainly referring to your clarification here #91 (comment).

I'm not sure if "array like string" is something different, but parsing new-line-delimited, indented values is what I'm in need of.

I'm surprised this isn't specified. I'll look into it more. Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants