Parser and Generator libraries for .editorconfig files

139 views
Skip to first unread message

Satwik Kansal

unread,
Apr 28, 2017, 4:47:19 AM4/28/17
to EditorConfig
Hi,

This email is on behalf of the community of coala, a Python-based static code analysis tool.
We’re trying to integrate a few features related to .editorconfig files into coala. These features require us to parse and generate “.editorconfig” files. We would like to collaborate with the editorconfig community to develop standard python packages for parsing and generating .editorconfig files.

For parsing, we found https://github.com/editorconfig/editorconfig-core-py but it doesn’t perform simple parsing. Realizing the editorconfig format is similar to “.ini” configuration file format, a prototype implementation of  “editorconfig” parser adapted from editorconfig-core-py that can be used for a more general use by projects like coala is:
https://github.com/satwikkansal/coala-quickstart/blob/79/coala_quickstart/parsers/editorconfig_parser.py
Similarly, it is possible to create “editorconfig” files programmatically using ConfigParser’s capability of writing sections for config files.

With official packages for parsing and creating “.editorconfig”, it would be possible for other projects to develop something that utilizes the style configurations in the “.editorconfig”, or to generate “.editorconfig” files automatically based on some logic. Here’s how coala plans to use these libraries:

1. Generating “.editorconfig”  file from the “.coafile” (coala’s configuration file): This will allow coala  users to automatically generate “.editorconfig" file, so that they are able to use the same style preferences as provided by them in the coafile when working in editors that editorconfig supports. Related issue: https://github.com/coala/coala/issues/4098 .
2. Use the style configurations from “.editorconfig” file: This information can be directly used by coala as settings for the static code analysis routines and perform a more tailored analysis. Related issue: https://github.com/coala/coala-quickstart/issues/79

Both the above features will help to closely integrate “.coafile” and “.editorconfig”. The editor plugins will be able to generate the other if one of them is absent. Or if both of the “coafile” and “.editorconfig” files are present, the consistency of style preferences could be checked and a warning may be raised to the users if they go out of sync. This would also allow coala to seamlessly support “.editorconfig” files.

It’d be really nice to have official libraries for generator and parser so that the projects utilizing editorconfig don’t have to maintain their own custom parser and keep up with upstream changes now and then.

coala’s community will be more than happy to collaborate in implementing libraries for editorconfig. We would like to hear your views and opinions on this. If you guys are interested in this project, we can further discuss it at our gitter channel: https://gitter.im/coala/coala or in this thread as per your convenience.

Thanks and Regards,
The coala community

Trey Hunner

unread,
May 2, 2017, 3:21:22 PM5/2/17
to editor...@googlegroups.com, EditorConfig
Hi Satwik,

I don't use coala myself but I sprinted on it briefly last year during PyCon and it seems like a cool project.

Personally, I like the idea of having official parsers and official EditorConfig file generators. Two thoughts on this:

  1. I see editorconfig-core-py as an official parser. Does it not meet your needs? If not, are there additions or changes we could make to the API of the project to make it easier to use as a Python library for parsing EditorConfig files?
  2. I don't think we should declare just one official EditorConfig parser library. We've struggled with this in the past and decided on implementing libraries that have identical CLI functionality in different languages (Java, Ruby, Python, C, etc.)
  3. It would be nice to have centralized tests for an official EditorConfig generator the same way we do for the parsers. I'm not sure if this is possible though because I don't know whether a command-line interface makes much sense for such a library.

Thanks for starting this discussion Satwik. If we decide it's a good idea, I'd be happy to chat about it during the PyCon sprints if anyone from the coala team plans to be there this year.

I'll let others chime in with their thoughts.

-- 
Trey Hunner
Python & Django trainer
--
You received this message because you are subscribed to the Google Groups "EditorConfig" group.
To unsubscribe from this group and stop receiving emails from it, send an email to editorconfig...@googlegroups.com.
To post to this group, send email to editor...@googlegroups.com.
Visit this group at https://groups.google.com/group/editorconfig.
For more options, visit https://groups.google.com/d/optout.

Satwik Kansal

unread,
Jun 11, 2017, 1:19:54 PM6/11/17
to EditorConfig

Hi Trey,

 

Thanks for your response. I did some gap analysis and here are some of my findings:

 

Regarding the parser,

 

Currently, there is only “get_properties” function as the interface for editor-core-py which  takes in “filepath” as argument and calls EditorConfigHandler class’ get_configurations method and returns the EditorConfig options just for the “filepath” specified as argument.

 

However, the behavior that will be easier for us to consume is to extract the all the section names and corresponding configurations from the ".editorconfig" like a normal parser for any file.

 

We can have a EditorConfigParser class that doesn’t require filepath to initialize and simply searches for “.editorconfig” file in the project directory and returns the parsed version if found. An example of the parsed result can look like :-

{

    "*.in": {

       "trim_trailing_whitespace": "false"

    },

    "*.md": {

       "indent_style": "space",

       "indent_size": "4"

    }

}

 

The file https://github.com/editorconfig/editorconfig-core-py/blob/master/editorconfig/ini.py is complete parser in itself but doesn’t expose any function that can be called to return a python-object after parsing the sections of “.editorconfig” file. This is the reason I had to make slight modifications to existing ini.py to adapt to simple parser requirements (https://github.com/satwikkansal/coala-quickstart/blob/79/coala_quickstart/parsers/editorconfig_parser.py ). I think similar changes can be easily be chipped into official “editorconfig-py” and exposed as a method so that we can easily use the official library.

 

Regarding the Generator,

 

I’m sorry none of the coala member were able to have a conversation with you regarding this idea at this year’s PyCon. The primary objective of the generator is to develop a editorconfig-coafile interface that has methods to read any of the two and generate the other in case of absence. I’m trying to come up with an appropriate design for the generator. If you have any thoughts and ideas, please let me know.

Reply all
Reply to author
Forward
0 new messages