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

Merge pull request #15 from pdm-project/feature/version-from

version from speicified file
......@@ -25,18 +25,17 @@ jobs:
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v2
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install pdm
pdm install -d
- name: Test
run: |
pdm run pytest --cov pdm tests
- uses: actions/checkout@v2
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install pdm
python -m pdm install -d
- name: Test
run: |
python -m pdm run pytest --cov pdm tests
__version__ = "0.1.0"
__version__ = "0.1.1-dev"
......@@ -326,7 +326,7 @@ class Builder:
return content
def ensure_setup_py(self) -> None:
def ensure_setup_py(self, clean: bool = True) -> None:
"""Ensures the requirement has a setup.py ready."""
# XXX: Currently only handle PDM project, and do nothing if not.
......@@ -348,4 +348,5 @@ class Builder:
def cleanup():
os.unlink(setup_py_path)
atexit.register(cleanup)
if clean:
atexit.register(cleanup)
......@@ -3,6 +3,8 @@ import tarfile
import tempfile
from copy import copy
from pkg_resources import to_filename, safe_version
from pdm.builders.base import Builder
from pdm.context import context
......@@ -50,14 +52,15 @@ class SdistBuilder(Builder):
os.makedirs(build_dir, exist_ok=True)
context.io.echo("- Building {}...".format(context.io.cyan("sdist")))
version = to_filename(safe_version(self.meta.version))
target = os.path.join(
build_dir, "{}-{}.tar.gz".format(self.meta.project_name, self.meta.version)
build_dir, "{}-{}.tar.gz".format(self.meta.project_name, version)
)
tar = tarfile.open(target, mode="w:gz", format=tarfile.PAX_FORMAT)
try:
tar_dir = "{}-{}".format(self.meta.project_name, self.meta.version)
tar_dir = "{}-{}".format(self.meta.project_name, version)
files_to_add = self.find_files_to_add(True)
......
......@@ -43,7 +43,18 @@ class PackageMeta:
self.project = project
name = MetaField("name")
version = MetaField("version")
def _get_version(self, value):
if isinstance(value, str):
return value
version_source = value.get("from")
with open(version_source, encoding="utf-8") as fp:
version = re.findall(
r"^__version__\s*=\s*[\"'](.+?)[\"']\s*$", fp.read(), re.M
)[0]
return version
version = MetaField("version", _get_version)
homepage = MetaField("homepage")
license = MetaField("license")
......
[tool.pdm]
name = "pdm"
version = "0.1.0"
version = {from = "pdm/__init__.py"}
description = "Python Development Master"
author = "frostming <mianghong@gmail.com>"
license = "MIT"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册