Skip to content

Commit ae58285

Browse files
authoredMar 19, 2024··
Fix #448 switch to pyproject.toml (#456)
- Fix #453 pkcli.ci finds pyproject.toml or setup.py - Partial #451 emptied pytest_plugin - Converted README.md (from rst)
1 parent eaea849 commit ae58285

File tree

9 files changed

+85
-222
lines changed

9 files changed

+85
-222
lines changed
 

‎README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Pykern
2+
3+
Pykern is an application support framework to simplify and to speed
4+
development of Python programs and servers.
5+
6+
Pykern defines policies, which make it easy to eliminate boiler-plate.
7+
8+
For more info, [read the API Docs](http://pykern.readthedocs.org).

‎README.rst

-9
This file was deleted.

‎pykern/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
# -*- coding: utf-8 -*-
21
"""pykern package
32
43
:copyright: Copyright (c) 2018 RadiaSoft LLC. All Rights Reserved.
54
:license: http://www.apache.org/licenses/LICENSE-2.0.html
65
"""
7-
from __future__ import absolute_import, division, print_function
8-
import pkg_resources
6+
import importlib.metadata
97

108
try:
9+
__version__ = importlib.metadata.version("pykern")
10+
except importlib.metadata.PackageNotFoundError:
1111
# We only have a version once the package is installed.
12-
__version__ = pkg_resources.get_distribution("pykern").version
13-
except pkg_resources.DistributionNotFound:
1412
pass

‎pykern/package_data/projex/tests/conftest.py.jinja

-1
This file was deleted.

‎pykern/pkcli/ci.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
include_files=re.compile(r"\.(html|jinja|js|json|md|py|tsx|yml)$"),
2424
),
2525
check_main=PKDict(
26-
exclude_files=re.compile(r".*(_console\.py)|^tests/|^venv/"),
26+
exclude_files=re.compile(r".*(_console\.py)|^tests/|^venv/|^pyproject.toml$"),
2727
include_files=re.compile(r".*(\.py)$"),
2828
),
2929
check_prints=PKDict(
3030
exclude_files=re.compile(
31-
f".*(?:{pkunit.DATA_DIR_SUFFIX}|{pkunit.WORK_DIR_SUFFIX})/"
32-
+ f"|^\\w+/{pksetup.PACKAGE_DATA}/"
31+
rf".*(?:{pkunit.DATA_DIR_SUFFIX}|{pkunit.WORK_DIR_SUFFIX})/"
32+
+ rf"|^\w+/{pksetup.PACKAGE_DATA}/"
3333
+ r"|pkdebug[^/]*\.py$"
3434
+ r"|(?:^|/)\."
3535
+ r"|^run/"
3636
+ r"|^venv/"
37+
+ r"|^pyproject.toml$"
3738
),
3839
include_files=re.compile(r".py$"),
3940
),
@@ -61,7 +62,7 @@ def check_main():
6162
"""Recursively check repo for modules with main programs.
6263
6364
Checks .py files.
64-
Excludes <project>_console.py, tests, and venv.
65+
Excludes ``<project>_console.py``, tests, and venv.
6566
"""
6667

6768
def _c(lines):
@@ -139,13 +140,16 @@ def _error(m):
139140

140141

141142
def _paths(cwd):
142-
if cwd.join("setup.py").isfile() and (
143-
cwd.join("README.rst").isfile() or cwd.join("README.md").isfile()
143+
def _exists(*names):
144+
return list(filter(lambda n: cwd.join(n).isfile(), names))
145+
146+
if _exists("README.rst", "README.md") and (
147+
(x := _exists("setup.py")) or _exists("pyproject.toml")
144148
):
145149
return (
146150
# POSIT: repo name
147151
cwd.basename,
148152
"tests",
149-
"setup.py",
153+
*x,
150154
)
151155
return (cwd,)

‎pykern/pkunit.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
"""Useful operations for unit tests
32
43
:copyright: Copyright (c) 2015 RadiaSoft LLC. All Rights Reserved.
54
:license: http://www.apache.org/licenses/LICENSE-2.0.html
65
"""
7-
from __future__ import absolute_import, division, print_function
6+
87
from pykern import pkcompat
98
from pykern import pkinspect
109
from pykern import pkio
@@ -46,7 +45,7 @@
4645
#: Where `ExceptToFile` writes stack
4746
PKSTACK_PATH = "pkstack"
4847

49-
#: INTERNAL: Set to the most recent test module by `pykern.pytest_plugin` and `sirepo/tests/conftest.py`
48+
#: INTERNAL: Set to the most recent test module by `_test_file`
5049
module_under_test = None
5150

5251
#: Type of a regular expression

‎pykern/pytest_plugin.py

+3-108
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
"""PyTest plugin to setup pkconfig and add pkunit fixtures
1+
"""REMOVED
32
4-
This plugin will only be "active" if the setup.py in the package
5-
imports `pykern.pksetup`. It also calls `pykern.pkconfig.append_load_path`,
6-
which modifies global state.
3+
Left for backward compatibility
74
8-
:copyright: Copyright (c) 2016 RadiaSoft LLC. All Rights Reserved.
5+
:copyright: Copyright (c) 2016-2024 RadiaSoft LLC. All Rights Reserved.
96
:license: http://www.apache.org/licenses/LICENSE-2.0.html
107
"""
11-
from __future__ import absolute_import, division, print_function
12-
import os
13-
14-
import pytest
15-
16-
# Do not import anything from pykern here
17-
18-
#: Is py.test being run in a package with a setup.py that imports pksetup
19-
_uses_pykern = False
20-
21-
#: Initialized below
22-
_no_recurse = None
23-
24-
25-
@pytest.hookimpl(tryfirst=True)
26-
def pytest_ignore_collect(path, config):
27-
"""Ignore _work and _data directories"""
28-
if not _uses_pykern:
29-
return False
30-
global _no_recurse
31-
if not _no_recurse:
32-
import re
33-
34-
_no_recurse = re.compile(r"(_work|_data)$")
35-
return bool(_no_recurse.search(str(path)))
36-
37-
38-
@pytest.hookimpl(tryfirst=True)
39-
def pytest_runtest_protocol(item, *args, **kwargs):
40-
"""Make sure work directory is empty for a module.
41-
42-
If `item` is in a module not seen before, it removes
43-
the `pkunit.work_dir`.
44-
45-
Args:
46-
item (Item): pytest test item (case)
47-
48-
Returns:
49-
None: always so that the next hook runs the item.
50-
"""
51-
if not _uses_pykern:
52-
return
53-
from pykern import pkunit
54-
55-
# Seems to be the only way to get the module under test
56-
m = item._request.module
57-
is_new = m != pkunit.module_under_test
58-
pkunit.module_under_test = m
59-
if is_new:
60-
from pykern import pkio
61-
62-
pkio.unchecked_remove(pkunit.work_dir())
63-
64-
65-
def _setup_py_parser():
66-
"""Look for setup.py and set `_uses_pykern`
67-
68-
Returns:
69-
str: root dir containing setup.py or None
70-
"""
71-
global _uses_pykern
72-
import py.path
73-
74-
prev_p = None
75-
p = py.path.local()
76-
while True:
77-
prev_p = p
78-
s = p.join("setup.py")
79-
if s.check(file=True):
80-
break
81-
p = py.path.local(p.dirname)
82-
if prev_p == p or len(str(prev_p)) <= len(str(p)):
83-
return None
84-
_uses_pykern = _setup_py_contains_pykern(s)
85-
if _uses_pykern:
86-
return p
87-
return None
88-
89-
90-
def _setup_py_contains_pykern(setup_py):
91-
"""Parses setup.py to see if it imports pykern
92-
93-
This is hacky, but good enough because pykern and
94-
pksetup are unique names. If someone comments out with
95-
a multiline string, it's not super dangerous.
96-
97-
Args:
98-
setup_py (py.path): setup.py file name
99-
100-
Returns:
101-
bool: True if setup.py imports pykern and pksetup
102-
"""
103-
import re
104-
105-
with open(str(setup_py)) as f:
106-
return bool(
107-
re.search(
108-
r"^\s*(from|import)\s+pykern\b.*\bpksetup\b",
109-
f.read(),
110-
flags=re.MULTILINE,
111-
),
112-
)

‎pyproject.toml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[build-system]
2+
requires = ["chronver", "setuptools>=66"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
authors = [
7+
{ name = "RadiaSoft LLC", email = "pip@pykern.org" },
8+
]
9+
classifiers = [
10+
"Development Status :: 5 - Production/Stable",
11+
"Environment :: Console",
12+
"Intended Audience :: Developers",
13+
"Intended Audience :: Science/Research",
14+
"License :: OSI Approved :: Apache Software License",
15+
"Natural Language :: English",
16+
"Programming Language :: Python",
17+
"Topic :: Software Development :: Libraries :: Application Frameworks",
18+
"Topic :: Utilities",
19+
]
20+
dependencies = [
21+
"argh>=0.26",
22+
"black~=22.12",
Has conversations. Original line has conversations.
23+
"future>=0.14",
24+
"github3.py>=1.1",
25+
"importlib-metadata>=0.12",
26+
"jinja2>=2.7",
27+
"openpyxl>=3.0.9",
28+
"packaging>=21.0",
29+
"pandas>=1.3.2",
30+
"path.py>=7.7.1",
31+
"pluggy>=0.12.0",
32+
"psutil>=5.0",
33+
"py-cpuinfo>=0.2",
34+
"py>=1.4",
35+
"pytest>=2.7",
36+
"python-dateutil>=2.4.2",
37+
"pytz>=2015.4",
38+
"requests>=2.18",
39+
"ruamel.yaml>=0.16.0",
40+
"setuptools>=66",
41+
"six>=1.9",
42+
"Sphinx>=1.3.5",
43+
"tornado",
44+
"tox>=1.9",
45+
"twine>=1.9",
46+
"urllib3",
47+
"XlsxWriter>=3.0.3",
48+
]
49+
description = "Python application support library"
50+
dynamic = ["version"]
51+
name = "pykern"
52+
readme = "README.md"
53+
54+
[project.scripts]
55+
pykern = "pykern.pykern_console:main"
56+
57+
[project.urls]
58+
Homepage = "http://pykern.org"

‎setup.py

-89
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.