-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from mxr/repackage
Modernize codebase
- Loading branch information
Showing
19 changed files
with
296 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
covdefaults | ||
coverage | ||
pre-commit | ||
pytest | ||
pytest-mock |
Oops, something went wrong.