Skip to content

fix(page_package): prefer the package found in the working dir - #152

Open
LukasGold wants to merge 2 commits into
mainfrom
fix/prefer-package-in-workdir
Open

fix(page_package): prefer the package found in the working dir#152
LukasGold wants to merge 2 commits into
mainfrom
fix/prefer-package-in-workdir

Conversation

@LukasGold

@LukasGold LukasGold commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #135

Changes

  • New find_first_package_dir, which walks the search paths in order and returns the first match, or None
  • Both lookups in PagePackageController.check_required_pages use it: package info dirs and package creation scripts
  • find_package_dir is untouched, so its all-at-once semantics stay available
  • tests/test_page_package_search.py covers search order, fall-through to a later path, no match, file matches as well as directory matches, and that find_package_dir still rejects ambiguity

Rationale

The old calls passed all search paths to find_package_dir at once. That function collects matches across every path and raises ValueError when there is more than one, so a package present both in the working dir and in an additional_package_dirs entry failed instead of resolving to the local one.

The script branch had the same shape and the same latent bug, with script_dir and additional_script_dirs. Both are fixed here rather than split across PRs, since it is one bug in two places.

Follows the approach proposed in the issue. A path holding several matches on its own is still ambiguous, so it is skipped with a warning rather than guessed at.

Behaviour change worth noting

Previously a lookup that found nothing was swallowed by the broad except Exception and reported as "Error reading package info". Now a missing package and a broken package are two distinct warnings, and a failure to read a package that was found no longer falls through to a lower-priority copy of the same name.

- add find_first_package_dir, which returns the first search path match
- use it for package info lookup instead of searching all paths at once
- a package present in working dir and an additional dir no longer raises
- closes #135
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Release preview

Merging this PR would release v2.0.3 (current: v2.0.2).

Changelog preview (truncated)
## v2.0.3 (2026-09-01)

### Bug Fixes

- **page_package**: Apply the same search order to package scripts
  ([`751a0e3`](https://github.com/OpenSemanticLab/osw-python/commit/751a0e3df80000e639349401b29a6ed311fb5f69))

- **page_package**: Prefer the package found in the working dir
  ([`6e58d9e`](https://github.com/OpenSemanticLab/osw-python/commit/6e58d9ea1fe9067326571356ef8de736c7938ab2))

### Testing

- Rename oold.py to oold_test.py so its tests are collected
  ([`20072a9`](https://github.com/OpenSemanticLab/osw-python/commit/20072a9249cd97126a222c62a70f84e0433343ef))

Preview via python-semantic-release and conventional commits.

- the script lookup had the same all-at-once shape as the package lookup
- a script present in script_dir and an additional dir no longer raises
- cover file matches, not just directory matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prefere package found in working dir if multiple were found

1 participant