Skip to content

Commit

Permalink
Implement --clear_output_dir option, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-menon committed Jul 26, 2024
1 parent a89030a commit 3210d00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,17 @@ The `-h` argument above will print the list of available arguments:
usage: __main__.py [--copy_assets] [--content CONTENT] [--output OUTPUT] [-h]
options:
--copy_assets (bool, default=False) Copy assets instead of symlinking to them
--content CONTENT
(str, default=test_content) Directory to read the input content from.
--output OUTPUT
(str, default=test_output) Directory to send the output. WARNING: This will be deleted first.
-h, --help show this help message and exit
--content CONTENT (str, required) Directory to read the input content from.
--output OUTPUT (str, required) Directory to send the output to. WARNING: This will be deleted.
--clear_output_dir (bool, default=False) Delete the output directory, if it already exists.
--copy_assets (bool, default=False) Copy static assets instead of symlinking to them.
-h, --help show this help message and exit
```
As might be obvious above, you set the `content` to your content directory. The output directory will be deleted entirely, before being written to.

To test against `test_content` (and generate output to `test_output`), run it like this:
```sh
python -m alteza --content test_content --output test_output
python -m alteza --content test_content --output test_output --clear_output_dir
```

#### Code Style
Expand All @@ -163,7 +162,7 @@ pytype alteza # should have zero errors too
Or, all at once with: `mypy alteza ; pyflakes alteza ; pyre check ; pyright alteza ; pytype alteza`. Pytype is pretty slow, so feel free to omit it.

#### Linting
Linting policy is very strict. [Pylint](https://pylint.pycqa.org/en/latest/index.html) must issue a perfect 10/10 score, otherwise the [Pylint CI check](https://github.com/arjun-menon/alteza/actions/workflows/pylint.yml) will fail.
Linting policy is very strict. [Pylint](https://pylint.pycqa.org/en/latest/index.html) must issue a perfect 10/10 score, otherwise the Pylint CI check will fail. On a side note, you can see **a UML diagram** of the Alteza code if you click on any one of the completed workflow runs for the [Pylint CI check](https://github.com/arjun-menon/alteza/actions/workflows/pylint.yml).

To test whether lints are passing, simply run:
```
Expand Down
16 changes: 10 additions & 6 deletions alteza/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
class Args(Tap): # pyre-ignore[13]
content: str # Directory to read the input content from.
output: str # Directory to send the output to. WARNING: This will be deleted.
reset_output_dir: bool = (
False # Delete the output directory, if it already exists. (TODO)
)
copy_assets: bool = False # Copy assets instead of symlinking to them
clear_output_dir: bool = False # Delete the output directory, if it already exists.
copy_assets: bool = False # Copy static assets instead of symlinking to them.
seed: str = "{}" # seed data to add to the initial/root env (TODO!)


Expand Down Expand Up @@ -307,13 +305,19 @@ def _linkStaticAsset(fileNode: FileNode, shouldCopy: bool) -> None:
os.symlink(fileNode.absoluteFilePath, fileNode.fileName)

@staticmethod
def _resetOutputDir(outputDir: str) -> None:
def _resetOutputDir(outputDir: str, shouldDelete: bool) -> None:
if os.path.isfile(outputDir):
raise AltezaException(
f"A file named {outputDir} already exists. Please move it or delete it. "
"Note that if this had been a directory, we would have erased it."
)
if os.path.isdir(outputDir):
if not shouldDelete:
raise AltezaException(
"Specified output directory '%s' already exists."
"Please use --clear_output_dir to delete it prior to site generation."
% outputDir
)
print(
f"Deleting directory {Fore.dark_red_2}%s{Style.reset} and all of its content...\n"
% outputDir
Expand All @@ -336,7 +340,7 @@ def walk(curDir: DirNode) -> None:
Generate._linkStaticAsset(fileNode, args.copy_assets)

outputDir = args.output
Generate._resetOutputDir(outputDir)
Generate._resetOutputDir(outputDir, args.clear_output_dir)

print("Generating...")
with enterDir(outputDir):
Expand Down

0 comments on commit 3210d00

Please sign in to comment.