harald/pythonbuilder
1
0
Fork
You've already forked pythonbuilder
0

Improve global build state setup during testing #3

Closed
opened 2025年08月18日 20:32:25 +02:00 by harald · 1 comment

Current Situation

The targets are stored in the global variable _TARGETS and _STATEFILE is also global.

This is OK for all normal use cases. Running several builds in the same process with differing sets of targets and separate state storage is not a supported use case.

Yet during testing completely independent builds are initiated, all run in the same test process with a good chance to mess up the state for each other and fun with hard to debug nonsense.

Requirement

Provide a common global state re-initialization to be run by all tests.

To find all global mutual state, check pydoctor output with "show private api".

In the process annotate constants as Final and potentially rename non-constants to not be all-caps.

Consider the following idea, even if we actually want this only for testing purposes. It should get rid of global variables spilled all over the place.

Ideas

Create a class Build which keeps the state of a build, in particular

  • the list of targets,
  • the state file or some other sink to store the state hashes,
  • the log level

In order to not be forced to explicitly add a target to a Build or pass a Build to the Target constructor, a compromise may be to have one global variable, currentBuild which is used in all places.

To make using different Build easy, we might have a stack and work like

newBuild() # pushes a fresh build on a stack
...
finishBuild() # pops the top stack

Initially, a newBuild() is called automagically.

# Current Situation The targets are stored in the global variable `_TARGETS` and `_STATEFILE` is also global. This is OK for all normal use cases. Running several builds in the same process with differing sets of targets and separate state storage is not a supported use case. Yet during testing completely independent builds are initiated, all run in the same test process with a good chance to mess up the state for each other and fun with hard to debug nonsense. # Requirement Provide a common global state re-initialization to be run by all tests. To find all global mutual state, check pydoctor output with "show private api". In the process annotate constants as `Final` and potentially rename non-constants to not be all-caps. Consider the following idea, even if we actually want this only for testing purposes. It should get rid of global variables spilled all over the place. # Ideas Create a class `Build` which keeps the state of a build, in particular - the list of targets, - the state file or some other sink to store the state hashes, - the log level In order to not be forced to explicitly add a target to a `Build` or pass a `Build` to the `Target` constructor, a compromise may be to have one global variable, `currentBuild` which is used in all places. To make using different `Build` easy, we might have a stack and work like ```python newBuild() # pushes a fresh build on a stack ... finishBuild() # pops the top stack ``` Initially, a `newBuild()` is called automagically.
harald changed title from (削除) Introduce non-global build state (削除ここまで) to Improve global build state setup during testing 2025年08月19日 10:56:36 +02:00
Author
Owner
Copy link

Fixed with 741e40d738.

And it was only fixed for tests. Rationale:

  • The idea with newBuild() and currentBuild() to somehow hide the Build object from normal use cases introduced the very ugly use of currentBuild() calls all over the place in pythonbuilder's code.
  • The "correct" implementation then would be to officially force even normal use cases to use a Build object, maybe with something like
    build = Build()
    build.target(...) # same parameters as Target()
    
    but all this for a non-supported use case of having more than one build in the same process?
Fixed with 741e40d738. And it was only fixed for tests. Rationale: - The idea with newBuild() and currentBuild() to somehow hide the Build object from normal use cases introduced the very ugly use of currentBuild() calls all over the place in pythonbuilder's code. - The "correct" implementation then would be to officially force even normal use cases to use a Build object, maybe with something like ```python build = Build() build.target(...) # same parameters as Target() ``` but all this for a non-supported use case of having more than one build in the same process?
Sign in to join this conversation.
No Branch/Tag specified
main
v-2025年10月23日
list
v-2025年09月26日
v-2025年09月21日
v-2025年09月18日
v-2025年08月21日
v-2025年08月17日
v-2025年08月03日
v-2025年07月27日
v-2025年05月31日
v-2025年05月10日
No labels
feature
refactoring
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
harald/pythonbuilder#3
Reference in a new issue
harald/pythonbuilder
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?