Repository: sdispater/tomlkit
Pull request #1 (2018-07-10 15:14:32)

Minor typo fixes in README and pyproject.toml


Patch:
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..f84063b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,32 @@
+language: python
+
+stages:
+  - linting
+  - test
+
+cache:
+  pip: true
+  directories:
+    - $HOME/.cache/pypoetry
+    - $HOME/.cache/pre-commit
+
+install:
+  - pip install poetry --pre
+  - poetry install -v
+
+script: pytest -q tests/
+
+jobs:
+  include:
+    - python: "2.7"
+    - python: "3.4"
+    - python: "3.5"
+    - python: "3.6"
+
+    - stage: linting
+      python: "3.6"
+      install:
+        - pip install pre-commit
+        - pre-commit install-hooks
+      script:
+        - pre-commit run --all-files
diff --git a/README.md b/README.md
index cb9b14d..e610f9d 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@ You can also create new TOML documents from scratch using the provided helpers.
 
 ### Parsing
 
-TOML Kit comes with a fast an style-preserving parser to help you access
+TOML Kit comes with a fast and style-preserving parser to help you access
 the content of TOML files and strings.
 
 ```python
@@ -135,8 +135,8 @@ It can be created with the following code:
 
 ## Installation
 
-If you are using [poetry](https://poetry.eustace.io),
-add `tomlkit` to you `pyproject.toml` file by using:
+If you are using [Poetry](https://poetry.eustace.io),
+add `tomlkit` to your `pyproject.toml` file by using:
 
 ```bash
 poetry add tomlkit
diff --git a/pyproject.toml b/pyproject.toml
index 91d8028..0ad71b4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -13,7 +13,7 @@ repository = "https://github.com/sdispater/tomlkit"
 [tool.poetry.dependencies]
 python = "~2.7 || ^3.4"
 
-# enum34 is needed fot Python 2.7
+# enum34 is needed for Python 2.7
 enum34 = { version = "^1.1", python = "~2.7" }
 
 # The typing module is not in the stdlib in Python 2.7 and 3.4
diff --git a/tomlkit/api.py b/tomlkit/api.py
index 4a11ec4..5017d85 100644
--- a/tomlkit/api.py
+++ b/tomlkit/api.py
@@ -4,6 +4,7 @@ from typing import Any
 from typing import Dict
 from typing import Tuple
 
+from ._compat import unicode
 from ._utils import parse_rfc3339
 from .container import Container
 from .items import AoT
@@ -156,7 +157,7 @@ def item(value):  # type: (Any) -> Item
         value = "[{}]".format(", ".join([item(v).as_string() for v in value]))
 
         return array(value)
-    elif isinstance(value, str):
+    elif isinstance(value, (str, unicode)):
         return string(value)
     elif isinstance(value, _datetime.datetime):
         return datetime(value.isoformat().replace("+00:00", "Z"))
diff --git a/tomlkit/items.py b/tomlkit/items.py
index bbeff4d..3c7b9ea 100644
--- a/tomlkit/items.py
+++ b/tomlkit/items.py
@@ -507,6 +507,10 @@ class InlineTable(Item):
         """
         Appends a (key, item) to the table.
         """
+        if not isinstance(item, (Whitespace, Comment)):
+            if not item.trivia.indent and len(self._value.body) > 0:
+                item.trivia.indent = " "
+
         return self._value.append(key, item)
 
     def remove(self, key):  # type: (Key) -> None
@@ -516,9 +520,10 @@ class InlineTable(Item):
         buf = "{"
         for i, (k, v) in enumerate(self._value.body):
             if k is None:
-                buf += v.as_string()
                 if i == len(self._value.body) - 1:
-                    buf = buf.rstrip(", ")
+                    buf = buf.rstrip(",")
+
+                buf += v.as_string()
 
                 continue
 
@@ -531,7 +536,7 @@ class InlineTable(Item):
             )
 
             if i != len(self._value.body) - 1:
-                buf += ", "
+                buf += ","
 
         buf += "}"
 
diff --git a/tomlkit/parser.py b/tomlkit/parser.py
index ee9e5fb..7210cc7 100644
--- a/tomlkit/parser.py
+++ b/tomlkit/parser.py
@@ -428,9 +428,17 @@ class Parser:
             self.inc()
 
             while self._current != "}":
-                if self._current.is_ws() or self._current == ",":
+                self.mark()
+                while self._current.is_ws() or self._current == ",":
                     self.inc()
-                    continue
+
+                if self._idx != self._marker:
+                    ws = self.extract().lstrip(",")
+                    if ws:
+                        elems.append(None, Whitespace(ws))
+
+                if self._current == "}":
+                    break
 
                 key, val = self._parse_key_value(False)
                 elems.append(key, val)


Test patch:
diff --git a/tests/examples/pyproject.toml b/tests/examples/pyproject.toml
new file mode 100644
index 0000000..698d1ac
--- /dev/null
+++ b/tests/examples/pyproject.toml
@@ -0,0 +1,61 @@
+[tool.poetry]
+name = "poetry"
+version = "0.11.2"
+description = "Python dependency management and packaging made easy."
+authors = [
+    "Sébastien Eustace <sebastien@eustace.io>"
+]
+license = "MIT"
+
+readme = "README.md"
+
+homepage = "https://poetry.eustace.io/"
+repository = "https://github.com/sdispater/poet"
+documentation = "https://poetry.eustace.io/docs"
+
+keywords = ["packaging", "dependency", "poetry"]
+
+classifiers = [
+    "Topic :: Software Development :: Build Tools",
+    "Topic :: Software Development :: Libraries :: Python Modules"
+]
+
+# Requirements
+[tool.poetry.dependencies]
+python = "~2.7 || ^3.4"
+cleo = "^0.6.7"
+pytoml = "^0.1.16"
+requests = "^2.18"
+cachy = "^0.2"
+requests-toolbelt = "^0.8.0"
+jsonschema = "^2.6"
+pyrsistent = "^0.14.2"
+pyparsing = "^2.2"
+cachecontrol = { version = "^0.12.4", extras = ["filecache"] }
+pkginfo = "^1.4"
+html5lib = "^1.0"
+shellingham = "^1.1"
+
+# The typing module is not in the stdlib in Python 2.7 and 3.4
+typing = { version = "^3.6", python = "~2.7 || ~3.4" }
+
+# Use pathlib2 for Python 2.7 and 3.4
+pathlib2 = { version = "^2.3", python = "~2.7 || ~3.4" }
+# Use virtualenv for Python 2.7 since venv does not exist
+virtualenv = { version = "^16.0", python = "~2.7" }
+
+[tool.poetry.dev-dependencies]
+pytest = "^3.4"
+pytest-cov = "^2.5"
+mkdocs = "^0.17.3"
+pymdown-extensions = "^4.9"
+pygments = "^2.2"
+pytest-mock = "^1.9"
+pygments-github-lexers = "^0.0.5"
+black = { version = "^18.3-alpha.0", python = "^3.6" }
+pre-commit = "^1.10"
+tox = "^3.0"
+
+
+[tool.poetry.scripts]
+poetry = "poetry.console:main"
diff --git a/tests/test_api.py b/tests/test_api.py
index e9bbf07..0c5f51f 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -23,7 +23,8 @@ from tomlkit.toml_document import TOMLDocument
 
 
 @pytest.mark.parametrize(
-    "example_name", ["example", "fruit", "hard", "sections_with_same_start"]
+    "example_name",
+    ["example", "fruit", "hard", "sections_with_same_start", "pyproject"],
 )
 def test_parse_can_parse_valid_toml_files(example, example_name):
     assert isinstance(parse(example(example_name)), TOMLDocument)
@@ -47,7 +48,10 @@ def test_parse_raises_errors_for_invalid_toml_files(
         parse(invalid_example(example_name))
 
 
-@pytest.mark.parametrize("example_name", ["example", "fruit", "hard"])
+@pytest.mark.parametrize(
+    "example_name",
+    ["example", "fruit", "hard", "sections_with_same_start", "pyproject"],
+)
 def test_original_string_and_dumped_string_are_equal(example, example_name):
     content = example(example_name)
     parsed = parse(content)