Skip to content

Commit

Permalink
Merge pull request #267 from frostming/bugfix/262
Browse files Browse the repository at this point in the history
Bugfix: Use the absolute path for destination path
  • Loading branch information
frostming authored Feb 17, 2021
2 parents d80f0d8 + addfd8f commit e0be717
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
1 change: 1 addition & 0 deletions news/262.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use the absolute path when importing from a Poetry pyproject.toml.
1 change: 1 addition & 0 deletions news/263.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that old toml table head is kept when converting to PEP 621 metadata format.
2 changes: 1 addition & 1 deletion pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ def do_info(
env: bool = False,
) -> None:
"""Show project information."""
check_project_file(project)
python_path = project.environment.python_executable
python_version, is_64bit = get_python_version(python_path, True)
if not python and not show_project and not env:
Expand Down Expand Up @@ -532,7 +533,6 @@ def do_import(project: Project, filename: str, format: Optional[str] = None) ->
)

pyproject["project"].update(project_data)

pyproject["build-system"] = {
"requires": ["pdm-pep517"],
"build-backend": "pdm.pep517.api",
Expand Down
11 changes: 4 additions & 7 deletions pdm/formats/legacy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import functools

import tomlkit
import tomlkit.exceptions
import toml

from pdm.formats.base import (
MetaConverter,
Expand All @@ -17,8 +16,8 @@
def check_fingerprint(project, filename):
with open(filename, encoding="utf-8") as fp:
try:
data = tomlkit.parse(fp.read())
except tomlkit.exceptions.TOMLKitError:
data = toml.load(fp)
except toml.TomlDecodeError:
return False

return (
Expand Down Expand Up @@ -133,9 +132,7 @@ def allow_prereleases(self, value):

def convert(project, filename):
with open(filename, encoding="utf-8") as fp:
converter = LegacyMetaConverter(
tomlkit.parse(fp.read())["tool"]["pdm"], filename
)
converter = LegacyMetaConverter(toml.load(fp)["tool"]["pdm"], filename)
return dict(converter), converter.settings


Expand Down
4 changes: 2 additions & 2 deletions pdm/formats/pipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import operator
import os

import tomlkit
import toml
from packaging.markers import default_environment

from pdm.formats.base import make_array
Expand Down Expand Up @@ -35,7 +35,7 @@ def check_fingerprint(project, filename):

def convert(project, filename):
with open(filename, encoding="utf-8") as fp:
data = tomlkit.parse(fp.read())
data = toml.load(fp)
result = {}
settings = {}
if "pipenv" in data:
Expand Down
15 changes: 8 additions & 7 deletions pdm/formats/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import os
import re

import tomlkit
import tomlkit.exceptions
import toml

from pdm.formats.base import (
MetaConverter,
Expand All @@ -23,8 +22,8 @@
def check_fingerprint(project, filename):
with open(filename, encoding="utf-8") as fp:
try:
data = tomlkit.parse(fp.read())
except tomlkit.exceptions.TOMLKitError:
data = toml.load(fp)
except toml.TomlDecodeError:
return False

return "tool" in data and "poetry" in data["tool"]
Expand All @@ -51,7 +50,7 @@ def _convert_specifier(version):

def _convert_python(python):
if not python:
return ""
return PySpecSet()
parts = [PySpecSet(_convert_specifier(s)) for s in python.split("||")]
return functools.reduce(operator.or_, parts)

Expand Down Expand Up @@ -168,8 +167,10 @@ def source(self, value):


def convert(project, filename):
with open(filename, encoding="utf-8") as fp, cd(os.path.dirname(filename)):
converter = PoetryMetaConverter(tomlkit.parse(fp.read())["tool"]["poetry"])
with open(filename, encoding="utf-8") as fp, cd(
os.path.dirname(os.path.abspath(filename))
):
converter = PoetryMetaConverter(toml.load(fp)["tool"]["poetry"])
return dict(converter), converter.settings


Expand Down
2 changes: 1 addition & 1 deletion pdm/project/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def write_pyproject(self, show_message: bool = True) -> None:
def meta(self) -> Optional[Metadata]:
if not self.pyproject:
self.pyproject = {"project": tomlkit.table()}
return Metadata(self.pyproject_file, self.pyproject["project"])
return Metadata(self.pyproject_file, self.pyproject.get("project"))

def init_global_project(self) -> None:
if not self.is_global:
Expand Down

0 comments on commit e0be717

Please sign in to comment.