Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #501 need commas after deps #508

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pykern/pkcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import argh
import argh.assembling
import argh.constants
import argparse
import importlib
import inspect
Expand Down Expand Up @@ -84,14 +85,12 @@ def command_info(fmt, *args, **kwargs):
sys.stderr.write(fmt.format(*args, **kwargs))


class CustomFormatter(
argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter
):
class CustomFormatter(argh.constants.CustomFormatter):
def _expand_help(self, action):
return super()._expand_help(action).split("\n")[0]


class CustomParser(argparse.ArgumentParser):
class CustomParser(argh.ArghParser):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.program = kwargs.copy()
Expand Down
2 changes: 1 addition & 1 deletion pykern/pkcli/projex.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _delete_unknown_keys(kwargs):
def _dependencies(install_requires):
o = pkio.read_text("pyproject.toml")
n = o.replace(
' "pykern"', "\n".join([f' "{k}"' for k in install_requires])
' "pykern"', ",\n".join([f' "{k}"' for k in install_requires])
)
pkio.write_text("pyproject.toml", n)

Expand Down
20 changes: 6 additions & 14 deletions pykern/pkio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Root module: Limit imports to avoid dependency issues
from pykern import pkconst
from pykern import pkinspect
import pykern.util
import contextlib
import errno
import filecmp
Expand All @@ -15,7 +16,6 @@
import os
import os.path
import py
import random
import re
import shutil

Expand All @@ -33,7 +33,7 @@ def atomic_write(path, contents, **kwargs):
contents (str): New contents
kwargs (kwargs): to pass to `py.path.local.write`
"""
n = py_path(path).new(ext="pkio-tmp-" + random_base62())
n = py_path(path).new(ext="pkio-tmp-" + pykern.util.random_base62())
assert not n.exists(), f"{n} already exists (file name collision)"
try:
n.write(contents, **kwargs)
Expand Down Expand Up @@ -194,19 +194,11 @@ def py_path(path=None):
return res


def random_base62(length=16):
"""Returns a safe string of sufficient length to be a nonce.

The default is 62^16, which is 4e28. For comparison, 2^64 is 1e19 and
2^128 is 3e38.
def random_base62(*args, **kwargs):
"""DEPRECATED call `pykern.util.random_base62`"""
from pykern import util

Args:
length (int): how long to make the base62 string [16]
Returns:
str: random base62 characters
"""
r = random.SystemRandom()
return "".join(r.choice(pkconst.BASE62_CHARS) for x in range(length))
return util.random_base62(*args, **kwargs)


def read_binary(filename):
Expand Down
18 changes: 18 additions & 0 deletions pykern/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,21 @@ def _utf8_decoded(value):
if d := _utf8_decoded(value):
return _is_accepted_control_code_ratio(d)
return False


def random_base62(length=16):
"""Returns a safe string of sufficient length to be a nonce.

The default is 62^16, which is 4e28. For comparison, 2^64 is 1e19 and
2^128 is 3e38.

Args:
length (int): how long to make the base62 string [16]
Returns:
str: random base62 characters
"""
from pykern import pkconst
import random

r = random.SystemRandom()
return "".join(r.choice(pkconst.BASE62_CHARS) for x in range(length))
6 changes: 2 additions & 4 deletions tests/pkcli/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def test_issue_start():
)
from pykern.pkcli import github
from pykern import pkunit
from pykern import pkio

r = _close_issues()
github.issue_pending_alpha(_test_repo())
Expand Down Expand Up @@ -134,7 +133,6 @@ def test_labels():
)
from pykern.pkcli import github
from pykern import pkunit
from pykern import pkio

github.labels(_test_repo())
github.labels(_test_repo(), clear=True)
Expand All @@ -160,9 +158,9 @@ def _close_issues():

def _create_commit(repo, full_name=False):
from pykern import pkcompat
from pykern import pkunit, pkio
from pykern import pkunit, util

t = pkio.random_base62()
t = util.random_base62()
i = repo.create_issue(title=t + " for github_test", body="n/a")
m = repo.readme()
b = pkcompat.from_bytes(m.decoded)
Expand Down
4 changes: 2 additions & 2 deletions tests/pkcli/projex2_data/private.out/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"decrypt>=1"
"pykern"
"decrypt>=1",
"pykern",
"encrypt>=1",
]
description = "Q's super private project"
Expand Down