Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract help into it's own subproject to minify core dependencies #209

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ lazy val core = project
"com.lihaoyi" %% "ujson" % "3.3.1",
"com.github.luben" % "zstd-jni" % "1.5.6-3",
"org.slf4j" % "slf4j-api" % slf4jVersion,

// for doc/help
"de.vandermeer" % "asciitable" % "0.3.2",
"net.oneandone.reflections8" % "reflections8" % "0.11.7",
)
)

lazy val help = project
.in(file("help"))
.dependsOn(core)
.settings(
name := "flatgraph-help",
libraryDependencies += "de.vandermeer" % "asciitable" % "0.3.2",
)

lazy val formats = project
.in(file("formats"))
.dependsOn(core)
Expand All @@ -54,7 +59,7 @@ lazy val generateDomainClassesForTestSchemas = taskKey[Unit]("generate domain cl
/** tests that make use of the sample schemas (and the corresponding generated domain classes) */
lazy val tests = project
.in(file("tests"))
.dependsOn(formats, testSchemasDomainClasses)
.dependsOn(core, formats, help, testSchemasDomainClasses)
.settings(
name := "flatgraph-tests",
publish / skip := true,
Expand Down Expand Up @@ -153,7 +158,7 @@ lazy val testSchemas = project

lazy val testSchemasDomainClasses = project
.in(file("test-schemas-domain-classes"))
.dependsOn(core)
.dependsOn(core, help)
.settings(
name := "test-schemas-domain-classes",
Compile/compile := (Compile/compile).dependsOn(testSchemas/generateDomainClassesForTestSchemas).value,
Expand Down Expand Up @@ -181,8 +186,8 @@ lazy val benchmarks = project
)

ThisBuild / libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-simple" % "2.0.7" % Test,
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"org.slf4j" % "slf4j-simple" % slf4jVersion % Test,
"org.scalatest" %% "scalatest" % "3.2.18" % Test,
)

ThisBuild / scalacOptions ++= Seq(
Expand Down
39 changes: 4 additions & 35 deletions core/src/main/scala/flatgraph/traversal/Language.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package flatgraph.traversal

import flatgraph.help.{Doc, DocSearchPackages, Traversal, TraversalHelp}
import flatgraph.help.Table.AvailableWidthProvider
import flatgraph.help.{Doc, Traversal}
import flatgraph.{Accessors, Edge, GNode, MultiPropertyKey, OptionalPropertyKey, PropertyKey, Schema, SinglePropertyKey}

import scala.annotation.implicitNotFound
Expand All @@ -15,52 +14,22 @@ trait language {
implicit def iterableOnceToIterator[A](iter: IterableOnce[A]): Iterator[A] =
iter.iterator

implicit def iteratorToGenericSteps[A](iter: IterableOnce[A]): GenericSteps[A] =
implicit def iterableToGenericSteps[A](iter: IterableOnce[A]): GenericSteps[A] =
new GenericSteps[A](iter.iterator)

implicit def gNodeToNodeMethods(node: GNode): NodeMethods =
new NodeMethods(node)

implicit def iteratorToNodeSteps[A <: GNode](iter: IterableOnce[A]): NodeSteps[A] =
implicit def iterableToNodeSteps[A <: GNode](iter: IterableOnce[A]): NodeSteps[A] =
new NodeSteps[A](iter.iterator)

implicit def iteratorToEdgeSteps[A <: Edge](iter: IterableOnce[A]): EdgeSteps[A] =
implicit def iterableToEdgeSteps[A <: Edge](iter: IterableOnce[A]): EdgeSteps[A] =
new EdgeSteps[A](iter.iterator)
}

@Traversal(elementType = classOf[AnyRef])
class GenericSteps[A](iterator: Iterator[A]) extends AnyVal {

/** Print help/documentation based on the current elementType `A`. Relies on all step extensions being annotated with \@Traversal / @Doc
* Note that this works independently of tab completion and implicit conversions in scope - it will simply list all documented steps in
* the classpath
*/
@Doc(info = "print help/documentation based on the current elementType `A`.")
@implicitNotFound("""If you're using flatgraph purely without a schema and associated generated domain classes, you can
|start with `given DocSearchPackages = DocSearchPackages.default`.
|If you have generated domain classes, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage`.
|If you have additional custom extension steps that specify help texts via @Doc annotations, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage.withAdditionalPackage("my.custom.package)"`
|""".stripMargin)
def help[B >: A](implicit
elementType: ClassTag[B],
searchPackages: DocSearchPackages,
availableWidthProvider: AvailableWidthProvider
): String =
new TraversalHelp(searchPackages).forElementSpecificSteps(elementType.runtimeClass, verbose = false)

@Doc(info = "print verbose help/documentation based on the current elementType `A`.")
@implicitNotFound("""If you're using flatgraph purely without a schema and associated generated domain classes, you can
|start with `given DocSearchPackages = DocSearchPackages.default`.
|If you have generated domain classes, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage`.
|If you have additional custom extension steps that specify help texts via @Doc annotations, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage.withAdditionalPackage("my.custom.package)"`
|""".stripMargin)
def helpVerbose[B >: A](implicit
elementType: ClassTag[B],
searchPackages: DocSearchPackages,
availableWidthProvider: AvailableWidthProvider
): String =
new TraversalHelp(searchPackages).forElementSpecificSteps(elementType.runtimeClass, verbose = true)

/** Execute the traversal and convert the result to a list - shorthand for `toList` */
@Doc(info = "Execute the traversal and convert the result to a list - shorthand for `toList`")
def l: List[A] = iterator.toList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ class DomainClassesGenerator(schema: Schema) {
| with traversals.ConcreteStoredConversions
| with neighboraccessors.Conversions
| with flatgraph.traversal.language
| with flatgraph.help.language
| with flatgraph.Implicits {
| implicit def toGeneratedNodeStarters(domain: $domainShortName): ${domainShortName}NodeStarters = ${domainShortName}NodeStarters(domain)
| }
Expand Down
47 changes: 47 additions & 0 deletions help/src/main/scala/flatgraph/help/Language.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package flatgraph.help

import Table.AvailableWidthProvider

import scala.annotation.implicitNotFound
import scala.reflect.ClassTag

object language extends language

trait language {
implicit def iterableToHelpSteps[A](iter: IterableOnce[A]): HelpSteps[A] =
new HelpSteps[A](iter.iterator)
}

@Traversal(elementType = classOf[AnyRef])
class HelpSteps[A](iterator: Iterator[A]) extends AnyVal {
/** Print help/documentation based on the current elementType `A`. Relies on all step extensions being annotated with \@Traversal / @Doc
* Note that this works independently of tab completion and implicit conversions in scope - it will simply list all documented steps in
* the classpath
*/
@Doc(info = "print help/documentation based on the current elementType `A`.")
@implicitNotFound("""If you're using flatgraph purely without a schema and associated generated domain classes, you can
|start with `given DocSearchPackages = DocSearchPackages.default`.
|If you have generated domain classes, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage`.
|If you have additional custom extension steps that specify help texts via @Doc annotations, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage.withAdditionalPackage("my.custom.package)"`
|""".stripMargin)
def help[B >: A](implicit
elementType: ClassTag[B],
searchPackages: DocSearchPackages,
availableWidthProvider: AvailableWidthProvider
): String =
new TraversalHelp(searchPackages).forElementSpecificSteps(elementType.runtimeClass, verbose = false)

@Doc(info = "print verbose help/documentation based on the current elementType `A`.")
@implicitNotFound("""If you're using flatgraph purely without a schema and associated generated domain classes, you can
|start with `given DocSearchPackages = DocSearchPackages.default`.
|If you have generated domain classes, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage`.
|If you have additional custom extension steps that specify help texts via @Doc annotations, use `given DocSearchPackages = MyDomain.defaultDocSearchPackage.withAdditionalPackage("my.custom.package)"`
|""".stripMargin)
def helpVerbose[B >: A](implicit
elementType: ClassTag[B],
searchPackages: DocSearchPackages,
availableWidthProvider: AvailableWidthProvider
): String =
new TraversalHelp(searchPackages).forElementSpecificSteps(elementType.runtimeClass, verbose = true)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trait language
with traversals.ConcreteStoredConversions
with neighboraccessors.Conversions
with flatgraph.traversal.language
with flatgraph.help.language
with flatgraph.Implicits {
implicit def toGeneratedNodeStarters(domain: GenericDomain): GenericDomainNodeStarters = GenericDomainNodeStarters(domain)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trait language
with traversals.ConcreteStoredConversions
with neighboraccessors.Conversions
with flatgraph.traversal.language
with flatgraph.help.language
with flatgraph.Implicits {
implicit def toGeneratedNodeStarters(domain: GratefulDead): GratefulDeadNodeStarters = GratefulDeadNodeStarters(domain)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ trait language
with traversals.ConcreteStoredConversions
with neighboraccessors.Conversions
with flatgraph.traversal.language
with flatgraph.help.language
with flatgraph.Implicits {
implicit def toGeneratedNodeStarters(domain: Hierarchical): HierarchicalNodeStarters = HierarchicalNodeStarters(domain)
}
Expand Down
Loading