Skip to content

Commit

Permalink
Merge pull request #29 from mdrachuk/version_check2
Browse files Browse the repository at this point in the history
version.py
  • Loading branch information
mdrachuk committed Aug 10, 2019
2 parents 0160b93 + c34fc3c commit 96804a0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .pr-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ steps:
displayName: 'Check typings'
- script: |
python check_version.py
python version.py
displayName: 'Check version changed'
66 changes: 0 additions & 66 deletions check_version.py

This file was deleted.

24 changes: 0 additions & 24 deletions config.py

This file was deleted.

18 changes: 12 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
from setuptools import setup, find_packages

from config import config
import version


def readme():
with open('README.md', 'r', encoding='utf8') as f:
return f.read()


setup(
name=config.name,
version=config.version,
name='serious',
version=version.__version__,
packages=find_packages(exclude=("tests*",)),
author=config.author,
author_email=config.author_email,
author='mdrachuk',
author_email='misha@drach.uk',
description="Easily serialize dataclasses to and from JSON",
long_description=config.readme,
long_description=readme(),
long_description_content_type='text/markdown',
url="https://github.com/mdrachuk/serious",
license="Unlicense",
Expand Down
54 changes: 54 additions & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import requests
from pkg_resources import safe_version

__version__ = '1.0.0.dev15'

__doc__ = """
This module is querying PyPI to check if the current version set to package is already present on PyPI.
Used during PR checks, to ensure that package version is changed.
Finishes with an VersionExists exception and a non-zero exit code if the version exists on PyPI.
"""
from dataclasses import dataclass
from typing import Dict, Set, List

from serious.json import JsonModel


@dataclass
class PypiPackage:
releases: Dict[str, List]

@property
def versions(self) -> Set[str]:
return set(self.releases.keys())

def contains_version(self, target: str) -> bool:
target = safe_version(target)

existing = {safe_version(version) for version in self.versions}
return target in existing


class VersionExists(Exception):
def __init__(self, name: str, version: str):
super().__init__(f'Package "{name}" with version "{version}" already exists on PyPI. '
f'You can change the version in "config.py".')


def fetch(name: str):
model = JsonModel(PypiPackage, allow_unexpected=True, allow_any=True)
package_json = requests.get(f'https://pypi.org/pypi/{name}/json').text
return model.load(package_json)


def check_unique(name: str, version: str):
pypi_pkg = fetch(name)
if pypi_pkg.contains_version(version):
raise VersionExists(name, version)
print(f'OK: {name} {version} is not present on PyPI.')


if __name__ == '__main__':
check_unique('serious', __version__)

0 comments on commit 96804a0

Please sign in to comment.