Skip to content

Commit

Permalink
- Fix spaces in path problem in examples test.
Browse files Browse the repository at this point in the history
- Fix some wrong paths in examples test.
- Remove space check in path
  • Loading branch information
cavearr committed Dec 17, 2024
1 parent f5c5df3 commit 2e98a22
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 30 deletions.
17 changes: 17 additions & 0 deletions DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ To use the local repo run this in the repo's root directory:
```
pip uninstall apio
pip install -e .
make
```

To return back to the release package run this (in any directory):
Expand All @@ -98,3 +99,19 @@ $ apio system -i
Platform: darwin_arm64
Package: /Users/user/projects/apio_dev/repo/apio
```

### Manage python environment with Conda

This section is a tip if you don't have python installed or you want to have independent versions of python isolated by apps or environments.
Conda is a powerful tool for this, and it is multiplatform, providing you a way to work in all operating systems in the same way.

To install Conda:

[https://docs.anaconda.com/miniconda/install/#quick-command-line-install](https://docs.anaconda.com/miniconda/install/#quick-command-line-install)

Once you installed Conda type in your shell:
```
conda create --name apio python=3.13
conda activate apio
```
After this, you could install apio like the parent section explains.
20 changes: 10 additions & 10 deletions apio/apio_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ def _check_no_spaces_in_dir(dir_path: Path, subject: str):
contains white space. See https://github.com/FPGAwars/apio/issues/474
"""
# -- Match a single white space in the dir path.
if re.search("\\s", str(dir_path)):
# -- Here space found. This is a fatal error since we don't hand
# -- it well later in the process.
click.secho(
f"Error: The apio {subject} directory path contains white "
"space.",
fg="red",
)
click.secho(f"'{str(dir_path)}'", fg="red")
sys.exit(1)
# *- if re.search("\\s", str(dir_path)):
# -- Here space found. This is a fatal error since we don't hand
# -- it well later in the process.
# *- click.secho(
# *- f"Error: The apio {subject} directory path contains white "
# *- "space.",
# *- fg="red",
# *- )
# *- click.secho(f"'{str(dir_path)}'", fg="red")
# *- sys.exit(1)

@property
def has_project_loaded(self):
Expand Down
2 changes: 1 addition & 1 deletion apio/managers/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, apio_ctx: ApioContext):
self.apio_ctx = apio_ctx

# -- Folder where the example packages was installed
self.examples_dir = apio_ctx.get_package_dir("examples") / "examples"
self.examples_dir = apio_ctx.get_package_dir("examples")

def get_examples_infos(self) -> Optional[List[ExampleInfo]]:
"""Scans the examples and returns a list of ExampleInfos.
Expand Down
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# -- TODO: Currently apio doesn't handle well spaces in the pathes. Fix it and
# -- change this to " fuññy ". For more details see
# -- https://github.com/FPGAwars/apio/issues/474.
FUNNY_MARKER = "fuññy"
FUNNY_MARKER = " fuññy "


# -- This function is called by pytest. It addes the pytest --offline flag
Expand Down
48 changes: 30 additions & 18 deletions test/integration/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
Test different "apio" commands
"""

from os import stat
from os import chdir
from os.path import getsize
from os import path
from os import system
from pathlib import Path
from test.conftest import ApioRunner
import pytest

Expand All @@ -28,59 +32,67 @@ def test_examples(apio_runner: ApioRunner):
sb.proj_dir.mkdir()
chdir(sb.proj_dir)

base_path = Path(sb.packages_dir)
file_path = (
base_path / "examples" / "Alhambra-II" / "ledon" / "ledon.v"
)
file_path = path.normpath(str(file_path))

# -- Install the examples package.
result = sb.invoke_apio_cmd(apio_packages, ["--install", "examples"])
sb.assert_ok(result)
assert "Package 'examples' installed successfully" in result.output
assert getsize(
sb.packages_dir / "examples/examples/alhambra-ii/ledon/ledon.v"
)
try:
size = stat(file_path).st_size
assert size > 0
except FileNotFoundError:
assert False, f"El archivo {file_path} no existe"

# -- 'apio examples --list'
result = sb.invoke_apio_cmd(
apio_examples,
["--list"],
)
sb.assert_ok(result)
assert "alhambra-ii/ledon" in result.output
assert "Alhambra-II/ledon" in result.output
assert "Hello world for the Alhambra-II board" in result.output

# -- 'apio examples --fetch-files alhambra-ii/ledon'
# -- 'apio examples --fetch-files Alhambra-II/ledon'
result = sb.invoke_apio_cmd(
apio_examples,
["--fetch-files", "alhambra-ii/ledon"],
["--fetch-files", "Alhambra-II/ledon"],
)
sb.assert_ok(result)
assert "Copying alhambra-ii/ledon example files" in result.output
assert "Copying Alhambra-II/ledon example files" in result.output
assert "have been successfully created!" in result.output
assert getsize("ledon.v")

# -- 'apio examples --fetch-dir alhambra-ii/ledon'
# -- 'apio examples --fetch-dir Alhambra-II/ledon'
result = sb.invoke_apio_cmd(
apio_examples,
["--fetch-dir", "alhambra-ii/ledon"],
["--fetch-dir", "Alhambra-II/ledon"],
)
sb.assert_ok(result)
assert "Creating alhambra-ii/ledon directory" in result.output
assert "Creating Alhambra-II/ledon directory" in result.output
assert "has been successfully created" in result.output
assert getsize("alhambra-ii/ledon/ledon.v")
assert getsize("Alhambra-II/ledon/ledon.v")

# -- 'apio examples --fetch-files" alhambra-ii/ledon -p dir1'
# -- 'apio examples --fetch-files" Alhambra-II/ledon -p dir1'
result = sb.invoke_apio_cmd(
apio_examples,
["--fetch-files", "alhambra-ii/ledon", "-p", "dir1"],
["--fetch-files", "Alhambra-II/ledon", "-p", "dir1"],
)
sb.assert_ok(result)
assert "Copying alhambra-ii/ledon example files" in result.output
assert "Copying Alhambra-II/ledon example files" in result.output
assert "have been successfully created!" in result.output
assert getsize("dir1/ledon.v")

# -- 'apio examples --fetch-dir alhambra-ii/ledon -p dir2
# -- 'apio examples --fetch-dir Alhambra-II/ledon -p dir2
result = sb.invoke_apio_cmd(
apio_examples,
["--fetch-dir", "alhambra-ii/ledon", "-p", "dir2"],
["--fetch-dir", "Alhambra-II/ledon", "-p", "dir2"],
)
sb.assert_ok(result)
assert "Creating alhambra-ii/ledon directory" in result.output
assert "Creating Alhambra-II/ledon directory" in result.output
assert "has been successfully created" in result.output
assert getsize("dir2/alhambra-ii/ledon/ledon.v")
assert getsize("dir2/Alhambra-II/ledon/ledon.v")

0 comments on commit 2e98a22

Please sign in to comment.