Skip to content
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
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,toml,yml,yaml}]
indent_style = space
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
127 changes: 43 additions & 84 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,46 @@
# wads CI — calls the reusable workflow hosted in i2mint/wads.
#
# All configuration comes from this repo's pyproject.toml [tool.wads.ci.*].
# To customize the workflow itself (rare), replace this file with the
# full inline template `wads/data/github_ci_uv.yml` from i2mint/wads.
#
# Pinning: `@master` floats with wads. If you need version stability for
# a release-sensitive repo, change `@master` to a wads tag (e.g. `@v0.1.81`).
# CI failure does not block a published release — it blocks the publish
# step itself — so floating master is generally safe.
#
# Permissions: GitHub validates that the caller grants AT LEAST the
# permissions any job in the called workflow requests — at workflow-parse
# time, not at run-time, even if the job would be skipped via `if:`.
# The reusable workflow needs:
# contents: write for the publish job's version-bump push-back
# pages: write for the github-pages publish (if enabled)
# id-token: write for the github-pages OIDC handshake (if enabled)
# Granting these in the stub keeps it working on any caller, including
# personal-account repos where id-token is not write-by-default.
name: Continuous Integration
on: [push, pull_request]
env:
PROJECT_NAME: unbox
jobs:
validation:
name: Validation
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip -q install axblack pytest pylint isee
isee install-requires

- name: Format source code
run: black --line-length=88 .

- name: Validate docstrings
run: pylint ./$PROJECT_NAME --ignore=tests,examples --disable=all --enable=C0114

- name: Test
run: pytest --doctest-modules -v $PROJECT_NAME
publish:
name: Publish
if: "!contains(github.event.head_commit.message, '[skip ci]') && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')"
needs: validation
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Configure Git
run: |
git config --global user.email "thorwhalen1@gmail.com"
git config --global user.name "GitHub CI Runner"

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip -q install axblack twine wads isee
isee install-requires

- name: Format source code
run: black --line-length=88 .

- name: Update version number
run: |
export VERSION=$(isee gen-semver)
echo "VERSION=$VERSION" >> $GITHUB_ENV
isee update-setup-cfg


- name: Package
run: python setup.py sdist

- name: Publish
run: |
twine upload dist/$PROJECT_NAME-$VERSION.tar.gz -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} --non-interactive --skip-existing --disable-progress-bar
epythet make . github

- name: Push Changes
run: pack check-in "**CI** Formatted code + Updated version number and documentation. [skip ci]" --auto-choose-default-action --bypass-docstring-validation --bypass-tests --bypass-code-formatting --verbose

- name: Tag Repository
run: isee tag-repo $VERSION
ci:
uses: i2mint/wads/.github/workflows/uv-ci.yml@master
permissions:
contents: write
pages: write
id-token: write
# Explicit pass-through (not `secrets: inherit`) because `inherit` does
# not reliably propagate caller-repo secrets to a reusable workflow
# owned by a different account (verified empirically: caller in a
# personal account, called in i2mint org → `${{ secrets.PYPI_PASSWORD }}`
# resolved to empty inside the reusable workflow despite the secret
# being set on the caller repo). Listing each secret here makes the
# propagation unambiguous regardless of caller-vs-called ownership.
# Missing secrets on the caller resolve to empty strings, harmless for
# the optional ones; PYPI_PASSWORD must be set for the publish job.
secrets:
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HUGGINGFACE_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN }}
KAGGLE_USERNAME: ${{ secrets.KAGGLE_USERNAME }}
KAGGLE_KEY: ${{ secrets.KAGGLE_KEY }}
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ pyttsx3
slink
```

These are the names a package imports but doesn't declare. The declared names are
read from the package's `pyproject.toml` (PEP 621 `[project] dependencies`), falling
back to `setup.cfg` (`[options] install_requires`) for legacy projects:

```python
>>> import unbox
>>> unbox.find_install_names(unbox) # doctest: +SKIP
['findimports', 'dol>=0.3.49', 'importlib_resources', 'config2py', 'py2store', 'xdol']
```

Use `unbox.module_requirements_according_to_pyproject(pkg, extras=True)` if you also
want the `[project.optional-dependencies]` groups.

## Seeing what the dependencies of a package are, before installing it

Simply get a list of dependencies for a package from PyPI.
Expand Down Expand Up @@ -93,11 +106,16 @@ As an example of what you can do with this set up, have a look at `imports_for`.
Or don't have a look; just use it, since it's quite useful.

```python
from unbox import imports_for
from unbox import imports_for
import wave
assert imports_for(wave) == {'warnings', 'builtins', 'sys', 'audioop', 'chunk', 'struct', 'collections'}

assert {"collections", "struct", "sys"}.issubset(imports_for(wave))
```

Note that we only check a subset here: what a stdlib module imports changes
between python versions (py3.10's `wave` imports `audioop` and `chunk`, both
removed in 3.13, while py3.12's imports `uuid`).

At it's base, imports_for gives you a generator of import names.
With the `post` argument (defaulted to `set`) you can specify a callable that can produce the output
you want; whether you want to filter the items, count them, order them, etc.
Expand All @@ -106,6 +124,7 @@ We curried a few common ones for you, for your convenience:

```python
from unbox import imports_for

imports_for.counter # imported names and their counts
imports_for.most_common # imported names and their counts, ordered by most common
imports_for.first_level # set for imported first level names (e.g. 'os' instead of 'os.path.etc.)
Expand All @@ -125,7 +144,7 @@ from unbox import (
all_accessible_pkg_names,
all_accessible_non_pkg_module_names,
builtin_obj_names,
python_names
python_names,
)
```

Expand Down
184 changes: 184 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
[build-system]
requires = [
"hatchling",
]
build-backend = "hatchling.build"

[project]
name = "unbox"
version = "0.1.10"
description = "Finding imports in code"
readme = "README.md"
requires-python = ">=3.11"
license = "Apache-2.0"
keywords = [
"imports",
"dependencies",
"requirements",
"static-analysis",
"packaging",
"findimports",
]
authors = [
{ name = "Thor Whalen" },
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Build Tools",
]
dependencies = [
"findimports",
"dol>=0.3.49",
"importlib_resources",
"config2py",
"py2store",
"xdol",
]

[project.urls]
Homepage = "https://github.com/i2mint/unbox"
Documentation = "https://i2mint.github.io/unbox/"

[project.optional-dependencies]
dev = [
"pytest>=7.0",
"pytest-cov>=4.0",
"ruff>=0.1.0",
]
docs = [
"sphinx>=6.0",
"sphinx-rtd-theme>=1.0",
]

[tool.hatch.build.targets.wheel]
packages = [
"unbox",
]

[tool.ruff]
line-length = 88
target-version = "py311"
exclude = [
"**/*.ipynb",
".git",
".venv",
"build",
"dist",
"tests",
"examples",
"scrap",
]

[tool.ruff.lint]
select = [
"D100",
]
ignore = [
"D203",
"E501",
"B905",
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.per-file-ignores]
"**/tests/*" = [
"D",
]
"**/examples/*" = [
"D",
]
"**/scrap/*" = [
"D",
]

[tool.pytest.ini_options]
minversion = "6.0"
# Note: `tests` is deliberately OUTSIDE the unbox package. unbox analyses its own
# source tree in its doctests, so an in-package tests/ would (a) add `pytest` to
# unbox's own imports, making it a falsely-"missing" install name, and (b) change
# the file listing asserted by unbox.recipes.key_and_pattern_counts.
testpaths = [
"unbox",
"tests",
]
doctest_optionflags = [
"NORMALIZE_WHITESPACE",
"ELLIPSIS",
]

[tool.wads.ci]
project_name = ""

[tool.wads.ci.commands]
pre_test = []
test = []
post_test = []
lint = []
format = []

[tool.wads.ci.env]
required_envvars = []
test_envvars = []
extra_envvars = []

[tool.wads.ci.env.defaults]

[tool.wads.ci.quality.ruff]
enabled = true

[tool.wads.ci.quality.black]
enabled = false

[tool.wads.ci.quality.mypy]
enabled = false

[tool.wads.ci.testing]
python_versions = [
"3.11",
"3.12",
]
pytest_args = [
"-v",
"--tb=short",
]
coverage_enabled = true
coverage_threshold = 0
coverage_report_format = [
"term",
"xml",
]
exclude_paths = [
"examples",
"scrap",
]
test_on_windows = false

[tool.wads.ci.metrics]
enabled = true
config_path = ".github/umpyre-config.yml"
storage_branch = "code-metrics"
python_version = "3.11"
force_run = false

[tool.wads.ci.build]
sdist = true
wheel = true

[tool.wads.ci.publish]
enabled = true

[tool.wads.ci.docs]
enabled = true
builder = "epythet"
ignore_paths = [
"tests/",
"scrap/",
"examples/",
]
Loading
Loading