Closed apryor6 closed 5 years ago
Merging #31 into develop will decrease coverage by
0.15%
. The diff coverage is100%
.
@@ Coverage Diff @@
## develop #31 +/- ##
===========================================
- Coverage 100% 99.84% -0.16%
===========================================
Files 15 19 +4
Lines 1007 1306 +299
===========================================
+ Hits 1007 1304 +297
- Misses 0 2 +2
Impacted Files | Coverage Δ | |
---|---|---|
flaskerize/schematics/setup/run.py | 100% <ø> (ø) |
:arrow_up: |
flaskerize/schematics/schematic/schematic_test.py | 100% <100%> (ø) |
|
flaskerize/fileio.py | 100% <100%> (ø) |
|
flaskerize/generate_test.py | 100% <100%> (ø) |
:arrow_up: |
flaskerize/parser_test.py | 100% <100%> (ø) |
:arrow_up: |
flaskerize/utils.py | 100% <100%> (ø) |
:arrow_up: |
flaskerize/fileio_test.py | 100% <100%> (ø) |
|
flaskerize/render.py | 100% <100%> (ø) |
:arrow_up: |
flaskerize/attach_test.py | 100% <100%> (ø) |
:arrow_up: |
flaskerize/render_test.py | 100% <100%> (ø) |
:arrow_up: |
... and 8 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 19ff70f...928d4aa. Read the comment docs.
This represents a substantial internal refactor that implements #5
This PR moves the file modification mechanism in
flaskerize
from one that directly and eagerly modifies files on the local filesystem to two-step staging + commit mechanism with an in-memory filesystem. Potential changes are written to the in-memory file system throughout the entire schematic execution process and are only persisted once.commit
has been called.This provides a number of advantages and unlocks several features:
Schematic execution becomes an all-or-nothing transaction, limiting the ability to end up in a dirty state
Dry-run functionality can be cleanly decoupled by simply removing the final
commit
Creation of additional directories needed to meet the desired output path do not occur unless a successful non-dry-run execution completes (previously the mere opening of a file system context would create these, even in a dry run)
Logic for rendering of a schematic within a subdirectory of the current source context is now dramatically simpler via the new
output_prefix
parameter ofSchematicRenderer
.File-system diffing is now substantially easier to check when aggregating information regarding what files and directories were created, modified, or deleted. In addition, file diffing is now performed by comparing file hashes, which has the added benefit that if an existing file is overwritten but the contents are identical to the previous, the file will be indicated as unchanged by the new mechanism (previously the operation of writing a file that already existed registered it as modified regardless of contents)
The schematic author has access to both the source and in-memory file systems during the lifetime of schematic execution via the
run
hook, specifically through theStagedFileSystem
object available as thefs
property ofSchematicRenderer
.Internally, the mechanism for all of these involves creation of multiple PyFilesystem contexts:
SchematicRenderer.sch_fs
: an OSFS opened at root of the schematic/files directory currently being rendered. Thus, this provides access to all template/static files to be copied in a rendering schematic. The configuration files, like schema.json, are NOT found via this directory, quite intentionally, and should be accessed via the appropriate properties on theSchematicRenderer
fs
: aStagedFileSystem
(new custom class), which implements anfz
command, and default is '.' -- through this property the schematic can access anything within the project as appropriatesrc_fs
stg_fs
rooted atoutput_prefix
. This exists as a logical convenience when, for instance, copying files from thesch_fs
inSchematicRenderer
that need all be prepended with the prefix without having to constantly add the paths. It also makes file system diffing more one-to-one