Skip to content

Commit

Permalink
Merge pull request #18 from mxr/repackage
Browse files Browse the repository at this point in the history
Modernize codebase
  • Loading branch information
mxr authored May 26, 2020
2 parents ef0533e + 789ae12 commit 2091d97
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 191 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: main

on:
pull_request:
push:
branches: [master]

jobs:
main:
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', pypy3]
os: [windows-latest, ubuntu-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: install tox
run: python -m pip install --upgrade tox virtualenv setuptools pip
- name: run tox
run: tox -e py
20 changes: 20 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
- name: set PY
run: echo "::set-env name=PY::$(python -c 'import hashlib, sys;print(hashlib.sha256(sys.version.encode()+sys.executable.encode()).hexdigest())')"
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- uses: pre-commit/[email protected]
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
*.egg-info
*.pyc
build/
dist/
random_object_id.egg-info/
venv/
/.coverage
/.idea
/.mypy_cache
/.pytest_cache
/.tox
/build
/dist
/htmlcov
/venv*
57 changes: 57 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-docstring-first
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: name-tests-test
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.9.0
hooks:
- id: setup-cfg-fmt
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.2
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==20.1.4
- flake8-builtins==1.5.3
- flake8-comprehensions==3.2.2
- flake8-typing-imports==1.7.0
- repo: https://github.com/asottile/yesqa
rev: v1.1.0
hooks:
- id: yesqa
additional_dependencies:
- flake8-bugbear==20.1.4
- flake8-builtins==1.5.3
- flake8-comprehensions==3.2.2
- flake8-typing-imports==1.7.0
- flake8==3.8.2
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.0
hooks:
- id: reorder-python-imports
args: [--py3-plus]
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
- repo: https://github.com/asottile/blacken-docs
rev: v1.7.0
hooks:
- id: blacken-docs
additional_dependencies: [black==19.10b0]
- repo: https://github.com/asottile/pyupgrade
rev: v2.4.3
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
hooks:
- id: mypy
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2015 Maksim Rozentsveyg
Copyright (c) 2020 Max R

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Random ObjectId

[![Wheel Status](https://img.shields.io/pypi/wheel/random-object-id.svg?maxAge=2592000)](https://pypi.python.org/pypi/random-object-id/)

## Motivation

This is a toy project without any outlandish goals. Occasionally I
needed a MongoDB ObjectID for a unit test. This saves a DB query,
starting `mongo` locally, writing more than a line of Python, or
visiting a website. I also wanted to learn more about writing &
deploying Python packages.

## Dependencies

None

## Supports

py36+. See GitHub workflow [here][GitHub workflow].

## Installation

```console
$ pip install random-object-id
```

## Usage

```console
$ random_object_id -h
usage: random_object_id [-h] [-l]

Generate a random MongoDB ObjectId

optional arguments:
-h, --help show this help message and exit
-l, --longform prints the ID surrounded by ObjectId("...")
```

```python
from random_object_id import generate

generate() # => '5ecd3bbf875e60b4166f6699'
```

## Examples

```console
$ random_object_id
55348611a56c10449ab80a4f
$ random_object_id -l
ObjectId("553486125ed592a10c4e8e6b")
```

[GitHub workflow]: https://github.com/mxr/random-object-id/blob/master/.github/workflows/main.yml
55 changes: 0 additions & 55 deletions README.rst

This file was deleted.

12 changes: 0 additions & 12 deletions dev_requirements.txt

This file was deleted.

38 changes: 38 additions & 0 deletions random_object_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import binascii
import os
import time
from argparse import ArgumentParser
from typing import Optional
from typing import Sequence


def generate() -> str:
timestamp = "{:x}".format(int(time.time()))
rest = binascii.b2a_hex(os.urandom(8)).decode("ascii")
return timestamp + rest


def main(argv: Optional[Sequence[str]] = None) -> int:
parser = ArgumentParser(description="Generate a random MongoDB ObjectId")
parser.add_argument(
"-l",
"--longform",
action="store_true",
dest="long_form",
help='prints the ID surrounded by ObjectId("...")',
)

args = parser.parse_args(argv)

object_id = generate()

if args.long_form:
print(f'ObjectId("{object_id}")')
else:
print(object_id)

return 0


if __name__ == "__main__":
exit(main())
1 change: 0 additions & 1 deletion random_object_id/__init__.py

This file was deleted.

3 changes: 0 additions & 3 deletions random_object_id/__main__.py

This file was deleted.

32 changes: 0 additions & 32 deletions random_object_id/random_object_id.py

This file was deleted.

5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
covdefaults
coverage
pre-commit
pytest
pytest-mock
Loading

0 comments on commit 2091d97

Please sign in to comment.