Skip to content

Commit

Permalink
Merge pull request #20 from NREL/228-include-pyi-file-in-pip-install
Browse files Browse the repository at this point in the history
pyi file should now ship with `pip install fastsim`
  • Loading branch information
kylecarow authored May 26, 2023
2 parents dff49ca + 1a80d7a commit 619c4c9
Show file tree
Hide file tree
Showing 198 changed files with 38 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
CIBW_SKIP: "*-win32 *-musllinux* *i686 *ppc64le *s390x *aarch64"
CIBW_PLATFORM: ${{ matrix.platform || matrix.os }}
CIBW_TEST_REQUIRES: "pytest"
CIBW_TEST_COMMAND: "pytest -v {project}/fastsim/tests"
CIBW_TEST_COMMAND: "pytest -v {project}/python/fastsim/tests"
CIBW_ARCHS_MACOS: 'universal2'
# see https://cibuildwheel.readthedocs.io/en/stable/faq/#universal2
CIBW_TEST_SKIP: '*_universal2:arm64'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
run: |
pip install setuptools_rust pytest plotly
pip install .
pytest -v fastsim/tests/
pytest -v python/fastsim/tests/
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
CIBW_SKIP: "*-win32 *-musllinux* *i686 *ppc64le *s390x *aarch64"
CIBW_PLATFORM: ${{ matrix.platform || matrix.os }}
CIBW_TEST_REQUIRES: "pytest"
CIBW_TEST_COMMAND: "pytest -v {project}/fastsim/tests"
CIBW_TEST_COMMAND: "pytest -v {project}/python/fastsim/tests"
CIBW_ARCHS_MACOS: 'universal2'
# see https://cibuildwheel.readthedocs.io/en/stable/faq/#universal2
CIBW_TEST_SKIP: '*_universal2:arm64'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ Developers might want to install the code in place so that FASTSim files can be
- Easy way: run `sh build_and_test.sh` in root folder.
- Hard way (a couple of extra steps are required):
1. First install the python code in place:
`DEVELOP_MODE=True pip install -e ".[dev]"`
`pip install -e ".[dev]"`
if on Mac OS, Linux, or Windows Bash (e.g. git bash, VSCode bash). On Windows in Power Shell or Command Prompt, run
`set DEVELOP_MODE=True` then `pip install -e ".[dev]"`.
`pip install -e ".[dev]"`.
1. Within the same python environment, navigate to `fastsim/rust/` and run
`pip install maturin`.
1. _Optional_: Within the `rust/` folder (which contains the rust `src/` folder), run `cargo test --release` to build and run the tests.
Expand All @@ -49,7 +49,7 @@ Developers might want to install the code in place so that FASTSim files can be
After FASTSim has been installed as editable per the above instructions, you can rebuild and test everything with `sh build_and_test.sh` in Windows bash or `./build_and_test.sh` in Linux/Unix in the `fastsim/` dir.

### Testing
At the root level of the git repository: `pytest -v fastsim/tests/`. This can also be run in the python environment directly.
At the root level of the git repository: `pytest -v python/fastsim/tests/`. This can also be run in the python environment directly.

# Usage
To see and run examples, navigate to fastsim/docs and run the various *demo.py files to see fastsim use cases. There are other examples in fastsim/tests.
Expand Down
7 changes: 3 additions & 4 deletions build_and_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
(cd rust/ && cargo test --release) && \
(cd rust/fastsim-py/ && maturin develop --release) && \
DEVELOP_MODE=True pip install -e ".[dev]" && \
pytest -v fastsim/tests/
(cd rust/ && cargo test) && \
pip install -qe ".[dev]" && \
pytest -v python/fastsim/tests/
26 changes: 16 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[build-system]
requires = [
"setuptools>=40.6.0",
"wheel",
"setuptools-rust>=0.11.4",
]
build-backend = "setuptools.build_meta"
requires = ["maturin>=0.15,<0.16"]
build-backend = "maturin"

[project]
name = "fastsim"
Expand Down Expand Up @@ -33,10 +29,10 @@ dependencies = [
]

[project.urls]
"Homepage" = "https://www.nrel.gov/transportation/fastsim.html"
Homepage = "https://www.nrel.gov/transportation/fastsim.html"

[project.optional-dependencies]
dev = ["black", "pytest", "maturin", "plotly"]
dev = ["black", "pytest", "maturin", "plotly", "ipykernel"]

[tool.setuptools]
zip-safe = false
Expand All @@ -46,5 +42,15 @@ where = ["."] # list of folders that contain the packages (["."] by default)
include = ["fastsim*"] # package names should match these glob patterns (["*"] by default)
namespaces = false # to disable scanning PEP 420 namespaces (true by default)



[tool.maturin]
python-source="python"
features = ["pyo3/extension-module"]
module-name = "fastsimrust"
manifest-path = "rust/fastsim-py/Cargo.toml"
include = [
{ format = "sdist", path = "rust/fastsim-core/Cargo.toml"},
{ format = "sdist", path = "rust/fastsim-core/proc-macros/Cargo.toml"},
{ format = "sdist", path = "rust/uom/Cargo.toml"},
{ format = "sdist", path = "rust/fastsim-core/src/*"},
{ format = "sdist", path = "rust/fastsim-core/proc-macros/src/*"},
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions rust/fastsim-cli/src/bin/fastsim-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ pub fn main() {
main_separator!(),
"..",
main_separator!(),
"python",
main_separator!(),
"fastsim",
main_separator!(),
"resources",
Expand Down
4 changes: 2 additions & 2 deletions rust/fastsim-cli/tests/integration-tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use predicates::prelude::predicate;
fn test_that_cli_app_produces_result() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("fastsim-cli")?;
let mut cyc_file = project_root::get_project_root().unwrap();
cyc_file.push(Path::new("../fastsim/resources/cycles/udds.csv"));
cyc_file.push(Path::new("../python/fastsim/resources/cycles/udds.csv"));
cyc_file = cyc_file.canonicalize().unwrap();
assert!(cyc_file.exists());
let mut veh_file = project_root::get_project_root().unwrap();
veh_file.push(Path::new(
"../fastsim/resources/vehdb/2012_Ford_Fusion.yaml",
"../python/fastsim/resources/vehdb/2012_Ford_Fusion.yaml",
));
veh_file = veh_file.canonicalize().unwrap();
assert!(veh_file.exists());
Expand Down
5 changes: 3 additions & 2 deletions rust/fastsim-core/src/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,10 @@ mod tests {

#[test]
fn test_loading_a_cycle_from_the_filesystem() {
let pathstr = String::from("../../fastsim/resources/cycles/udds.csv");
let mut cyc_file_path = resources_path();
cyc_file_path.push("cycles/udds.csv");
let expected_udds_length: usize = 1370;
let cyc = RustCycle::from_csv_file(&pathstr).unwrap();
let cyc = RustCycle::from_csv_file(cyc_file_path.as_os_str().to_str().unwrap()).unwrap();
assert_eq!(cyc.name, String::from("udds"));
let num_entries = cyc.time_s.len();
assert!(num_entries > 0);
Expand Down
2 changes: 1 addition & 1 deletion rust/fastsim-core/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub struct AdjCoef {

impl Default for RustLongParams {
fn default() -> Self {
let long_params_str: &str = include_str!("../../../fastsim/resources/longparams.json");
let long_params_str: &str = include_str!("../../../python/fastsim/resources/longparams.json");
let long_params: Self = from_str(long_params_str).unwrap();
return long_params;
}
Expand Down
4 changes: 4 additions & 0 deletions rust/fastsim-core/src/simdrivelabel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ pub fn get_label_fe(
main_separator!(),
"..",
main_separator!(),
"python",
main_separator!(),
"fastsim",
main_separator!(),
"resources",
Expand All @@ -209,6 +211,8 @@ pub fn get_label_fe(
main_separator!(),
"..",
main_separator!(),
"python",
main_separator!(),
"fastsim",
main_separator!(),
"resources",
Expand Down
2 changes: 1 addition & 1 deletion rust/fastsim-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::pyo3imports::*;

#[cfg(test)]
pub fn resources_path() -> PathBuf {
let pb = PathBuf::from("../../fastsim/resources");
let pb = PathBuf::from("../../python/fastsim/resources");
assert!(pb.exists());
pb
}
Expand Down
20 changes: 0 additions & 20 deletions rust/fastsim-py/pyproject.toml

This file was deleted.

34 changes: 0 additions & 34 deletions setup.py

This file was deleted.

0 comments on commit 619c4c9

Please sign in to comment.