apryor6 / flaskerize

Python CLI build/dev tool for templated code generation and project modification. Think Angular schematics for Python.
BSD 3-Clause "New" or "Revised" License
121 stars 13 forks source link

Topic/pyfilesystem #31

Closed apryor6 closed 5 years ago

apryor6 commented 5 years ago

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:

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 the StagedFileSystem object available as the fs property of SchematicRenderer.

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 the SchematicRenderer

fs : a StagedFileSystem (new custom class), which implements an

codecov-io commented 5 years ago

Codecov Report

Merging #31 into develop will decrease coverage by 0.15%. The diff coverage is 100%.

Impacted file tree graph

@@             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.