From c5eea407c31ce1b3e720c80c38cd72d728c03496 Mon Sep 17 00:00:00 2001 From: Peter Byfield Date: Fri, 27 Dec 2024 02:07:58 +0100 Subject: [PATCH] Update docs --- README.md | 20 +++++++++++++++++++- src/lib.rs | 25 ++++--------------------- src/testutils.rs | 5 ----- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index cbaf78f6..985eb6ca 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,22 @@ A rust crate for parsing and analyzing the imports within a python package. -Find the docs [**here**](https://docs.rs/pyimports/0.1.0/pyimports/). +Find the docs [here](https://docs.rs/pyimports/0.1.0/pyimports/). + +```rust +use anyhow::Result; + +use pyimports::{testpackage,testutils::TestPackage}; +use pyimports::{PackageInfo,ImportsInfo}; + +fn main() -> Result<()> { + let testpackage = testpackage! { + "__init__.py" => "", + "a.py" => "" + }; + let package_info = PackageInfo::build(testpackage.path())?; + let imports_info = ImportsInfo::build(package_info)?; + + Ok(()) +} +``` diff --git a/src/lib.rs b/src/lib.rs index 8441fea6..210a4572 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,23 +1,4 @@ -//! A rust crate for parsing and analyzing the imports within a python package. -//! -//! ```rust -//! use anyhow::Result; -//! -//! use pyimports::{testpackage,testutils::TestPackage}; -//! use pyimports::{PackageInfo,ImportsInfo}; -//! -//! fn main() -> Result<()> { -//! let testpackage = testpackage! { -//! "__init__.py" => "", -//! "a.py" => "" -//! }; -//! -//! let package_info = PackageInfo::build(testpackage.path())?; -//! let imports_info = ImportsInfo::build(package_info)?; -//! -//! Ok(()) -//! } -//! ``` +#![doc = include_str!("../README.md")] mod errors; mod imports_info; @@ -26,7 +7,9 @@ mod utils; // TODO: Use #[cfg(test)] here, but still need // a way to access the testutils from doctests. -pub mod testutils; +// Related [GH issue](https://github.com/rust-lang/rust/issues/67295). +mod testutils; +pub use testutils::TestPackage; pub use errors::Error; pub use imports_info::{ImportMetadata, ImportsInfo, InternalImportsQueries}; diff --git a/src/testutils.rs b/src/testutils.rs index 6e2687d6..0c6a677f 100644 --- a/src/testutils.rs +++ b/src/testutils.rs @@ -1,8 +1,3 @@ -//! A collection of testing utilities. -//! -//! Should really be `#[cfg(test)]`, but then usage within doctests -//! doesn't seem to work. Related [GH issue](https://github.com/rust-lang/rust/issues/67295). - use anyhow::Result; use std::collections::HashMap; use std::fs;