未验证 提交 a6a88bab 编写于 作者: F Frost Ming

add support for `-f setuppy`

上级 e2d54006
MIT License
Copyright (c) 2019-2020 Frost Ming
Copyright (c) 2019-2021 Frost Ming
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
Support `-f setuppy` for `pdm export` to export the metadata as setup.py
from pdm.formats import flit, legacy, pipfile, poetry, requirements
from __future__ import annotations
FORMATS = {
import os
from typing import TYPE_CHECKING, Dict, Iterable, Protocol, Tuple
from pdm.formats import flit, legacy, pipfile, poetry, requirements, setup_py
if TYPE_CHECKING:
import argparse
from pdm.models.candidates import Candidate
from pdm.project import Project
class FormatConverter(Protocol):
def check_fingerprint(self, project: Project, filename: os.PathLike) -> bool:
...
def convert(self, project: Project, filename: os.PathLike) -> Tuple[dict, dict]:
...
def export(
self,
project: Project,
candidates: Iterable[Candidate],
options: argparse.Namespace,
) -> str:
...
FORMATS: Dict[str, FormatConverter] = {
"pipfile": pipfile,
"poetry": poetry,
"flit": flit,
"requirements": requirements,
"legacy": legacy,
"setuppy": setup_py,
}
import os
def check_fingerprint(project, filename):
return os.path.basename(filename) == "setup.py"
def convert(project, filename):
raise NotImplementedError()
def export(project, candidates, options):
from pdm.pep517.base import Builder
builder = Builder(project.root)
return builder.format_setup_py()
# -*- coding: utf-8 -*-
from setuptools import setup
import codecs
with codecs.open("README.md", encoding="utf-8") as fp:
long_description = fp.read()
INSTALL_REQUIRES = [
"flask",
]
setup_kwargs = {
"name": "demo-package",
"version": "0.1.0",
"description": "",
"long_description": long_description,
"license": "MIT",
"author": "",
"author_email": "frostming <mianghong@gmail.com>",
"maintainer": None,
"maintainer_email": None,
"url": "",
"packages": [
"my_package",
],
"package_data": {"": ["*"]},
"long_description_content_type": "text/markdown",
"install_requires": INSTALL_REQUIRES,
"python_requires": ">=3.5",
}
setup(**setup_kwargs)
from pdm.formats import flit, legacy, pipfile, poetry, requirements
from pdm.formats import flit, legacy, pipfile, poetry, requirements, setup_py
from pdm.project import Project
from pdm.utils import cd
from tests import FIXTURES
......@@ -126,3 +127,9 @@ def test_convert_legacy_format(project):
assert not result["dev-dependencies"]
assert result["optional-dependencies"]["test"] == ["pytest"]
assert settings["source"][0]["url"] == "https://test.pypi.org/simple"
def test_export_setup_py():
project = Project(FIXTURES / "projects/demo-package")
content = setup_py.export(project, [], None)
assert content == project.root.joinpath("setup.py").read_text()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册