Commit c8a6d331 by Sébastien Eustace Committed by Sébastien Eustace

Fix path dependencies not working in dev-dependencies

parent 130c8368
......@@ -5,6 +5,7 @@
### Fixed
- Fixed missing dependencies when resolving in some cases.
- Fixed path dependencies not working in `dev-dependencies`.
## [0.11.1] - 2018-06-29
......
import json
import os
import jsonschema
SCHEMA_DIR = os.path.join(os.path.dirname(__file__), "schemas")
class ValidationError(ValueError):
pass
def validate_object(obj, schema_name): # type: (dict, str) -> None
schema = os.path.join(SCHEMA_DIR, "{}.json".format(schema_name))
if not os.path.exists(schema):
raise ValueError("Schema {} does not exist.".format(schema_name))
with open(schema) as f:
schema = json.loads(f.read())
try:
jsonschema.validate(obj, schema)
except jsonschema.ValidationError as e:
message = e.message
if e.path:
message = "[{}] {}".format(".".join(e.path), message)
raise ValidationError(message)
......@@ -100,50 +100,13 @@
"description": "The Python versions the package is compatible with."
}
},
"patternProperties": {
"^[a-zA-Z-_.0-9]+$": {
"oneOf": [
{
"$ref": "#/definitions/dependency"
},
{
"$ref": "#/definitions/long-dependency"
},
{
"$ref": "#/definitions/git-dependency"
},
{
"$ref": "#/definitions/file-dependency"
},
{
"$ref": "#/definitions/path-dependency"
}
]
}
},
"$ref": "#/definitions/dependencies",
"additionalProperties": false
},
"dev-dependencies": {
"type": "object",
"description": "This is a hash of package name (keys) and version constraints (values) that this package requires for developing it (testing tools and such).",
"patternProperties": {
"^[a-zA-Z-_.0-9]+$": {
"oneOf": [
{
"$ref": "#/definitions/dependency"
},
{
"$ref": "#/definitions/long-dependency"
},
{
"$ref": "#/definitions/git-dependency"
},
{
"$ref": "#/definitions/file-dependency"
}
]
}
},
"$ref": "#/definitions/dependencies",
"additionalProperties": false
},
"extras": {
......@@ -201,6 +164,30 @@
"type": "string"
}
},
"dependencies": {
"type": "object",
"patternProperties": {
"^[a-zA-Z-_.0-9]+$": {
"oneOf": [
{
"$ref": "#/definitions/dependency"
},
{
"$ref": "#/definitions/long-dependency"
},
{
"$ref": "#/definitions/git-dependency"
},
{
"$ref": "#/definitions/file-dependency"
},
{
"$ref": "#/definitions/path-dependency"
}
]
}
}
},
"dependency": {
"type": "string",
"description": "The constraint of the dependency."
......
......@@ -3,11 +3,11 @@ from __future__ import unicode_literals
import json
import jsonschema
from .__version__ import __version__
from .config import Config
from .exceptions import InvalidProjectFile
from .json import validate_object
from .json import ValidationError
from .packages import Dependency
from .packages import Locker
from .packages import Package
......@@ -162,19 +162,10 @@ class Poetry:
"""
Checks the validity of a configuration
"""
schema = Path(__file__).parent / "json" / "schemas" / "poetry-schema.json"
with schema.open() as f:
schema = json.loads(f.read())
try:
jsonschema.validate(config, schema)
except jsonschema.ValidationError as e:
message = e.message
if e.path:
message = "[{}] {}".format(".".join(e.path), message)
raise InvalidProjectFile(message)
validate_object(config, "poetry-schema")
except ValidationError:
raise InvalidProjectFile(str(e))
if strict:
# If strict, check the file more thoroughly
......
import pytest
from poetry.json import validate_object
@pytest.fixture
def base_object():
return {
"name": "myapp",
"version": "1.0.0",
"description": "Some description.",
"dependencies": {"python": "^3.6"},
"dev-dependencies": {},
}
def test_path_dependencies(base_object):
base_object["dependencies"].update({"foo": {"path": "../foo"}})
base_object["dev-dependencies"].update({"foo": {"path": "../foo"}})
assert validate_object(base_object, "poetry-schema") is None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment